Second part of the action comment refactoring
Some checks failed
continuous-integration/drone/pr Build is failing

ref #39
This commit is contained in:
Nicolai Ort 2020-12-21 16:21:12 +01:00
parent 1d0d79f3da
commit 48bef8db60
12 changed files with 79 additions and 49 deletions

View File

@ -1,16 +1,19 @@
import { IsNotEmpty, IsOptional, IsPostalCode, IsString } from 'class-validator'; import { IsNotEmpty, IsOptional, IsPostalCode, IsString } from 'class-validator';
import { Address } from '../entities/Address'; import { Address } from '../entities/Address';
/**
* This classed is used to create a new Address entity from a json body (post request).
*/
export class CreateAddress { export class CreateAddress {
/** /**
* The address's description. * The newaddress's description.
*/ */
@IsString() @IsString()
@IsOptional() @IsOptional()
description?: string; description?: string;
/** /**
* The address's first line. * The new address's first line.
* Containing the street and house number. * Containing the street and house number.
*/ */
@IsString() @IsString()
@ -18,7 +21,7 @@ export class CreateAddress {
address1: string; address1: string;
/** /**
* The address's second line. * The new address's second line.
* Containing optional information. * Containing optional information.
*/ */
@IsString() @IsString()
@ -26,7 +29,9 @@ export class CreateAddress {
address2?: string; address2?: string;
/** /**
* The address's postal code. * The new address's postal code.
* This will get checked against the postal code syntax for the configured country.
* TODO: Implement the config option.
*/ */
@IsString() @IsString()
@IsNotEmpty() @IsNotEmpty()
@ -34,21 +39,21 @@ export class CreateAddress {
postalcode: string; postalcode: string;
/** /**
* The address's city. * The new address's city.
*/ */
@IsString() @IsString()
@IsNotEmpty() @IsNotEmpty()
city: string; city: string;
/** /**
* The address's country. * The new address's country.
*/ */
@IsString() @IsString()
@IsNotEmpty() @IsNotEmpty()
country: string; country: string;
/** /**
* Creates a Address object based on this. * Creates a new Address entity from this.
*/ */
public toAddress(): Address { public toAddress(): Address {
let newAddress: Address = new Address(); let newAddress: Address = new Address();

View File

@ -8,7 +8,7 @@ import { User } from '../entities/User';
import { Auth } from '../responses/ResponseAuth'; import { Auth } from '../responses/ResponseAuth';
/** /**
* This class is used to create auth credentials. * This class is used to create auth credentials based on user credentials provided in a json body (post request).
* To be a little bit more exact: Is takes in a username/email + password and creates a new access and refresh token for the user. * To be a little bit more exact: Is takes in a username/email + password and creates a new access and refresh token for the user.
* It of course checks for user existance, password validity and so on. * It of course checks for user existance, password validity and so on.
*/ */

View File

@ -5,32 +5,34 @@ import { AddressNotFoundError, AddressWrongTypeError } from '../../errors/Addres
import { Address } from '../entities/Address'; import { Address } from '../entities/Address';
import { GroupContact } from '../entities/GroupContact'; import { GroupContact } from '../entities/GroupContact';
/**
* This classed is used to create a new Group entity from a json body (post request).
*/
export class CreateGroupContact { export class CreateGroupContact {
/** /**
* The contact's first name. * The new contact's first name.
*/ */
@IsNotEmpty() @IsNotEmpty()
@IsString() @IsString()
firstname: string; firstname: string;
/** /**
* The contact's middle name. * The new contact's middle name.
* Optional
*/ */
@IsOptional() @IsOptional()
@IsString() @IsString()
middlename?: string; middlename?: string;
/** /**
* The contact's last name. * The new contact's last name.
*/ */
@IsNotEmpty() @IsNotEmpty()
@IsString() @IsString()
lastname: string; lastname: string;
/** /**
* The contact's address. * The new contact's address.
* Optional * Must be the address's id.
*/ */
@IsInt() @IsInt()
@IsOptional() @IsOptional()
@ -38,7 +40,7 @@ export class CreateGroupContact {
/** /**
* The contact's phone number. * The contact's phone number.
* Optional * This will be validated against the configured country phone numer syntax (default: international).
*/ */
@IsOptional() @IsOptional()
@IsPhoneNumber(config.phone_validation_countrycode) @IsPhoneNumber(config.phone_validation_countrycode)
@ -46,14 +48,13 @@ export class CreateGroupContact {
/** /**
* The contact's email address. * The contact's email address.
* Optional
*/ */
@IsOptional() @IsOptional()
@IsEmail() @IsEmail()
email?: string; email?: string;
/** /**
* Get's this participant's address from this.address. * Gets the new contact's address by it's id.
*/ */
public async getAddress(): Promise<Address> { public async getAddress(): Promise<Address> {
if (this.address === undefined || this.address === null) { if (this.address === undefined || this.address === null) {
@ -69,7 +70,7 @@ export class CreateGroupContact {
} }
/** /**
* Creates a Address object based on this. * Creates a new Address entity from this.
*/ */
public async toGroupContact(): Promise<GroupContact> { public async toGroupContact(): Promise<GroupContact> {
let contact: GroupContact = new GroupContact(); let contact: GroupContact = new GroupContact();

View File

@ -4,6 +4,9 @@ import { config } from '../../config';
import { AddressNotFoundError, AddressWrongTypeError } from '../../errors/AddressErrors'; import { AddressNotFoundError, AddressWrongTypeError } from '../../errors/AddressErrors';
import { Address } from '../entities/Address'; import { Address } from '../entities/Address';
/**
* This classed is used to create a new Participant entity from a json body (post request).
*/
export abstract class CreateParticipant { export abstract class CreateParticipant {
/** /**
* The new participant's first name. * The new participant's first name.
@ -14,7 +17,6 @@ export abstract class CreateParticipant {
/** /**
* The new participant's middle name. * The new participant's middle name.
* Optional.
*/ */
@IsString() @IsString()
@IsOptional() @IsOptional()
@ -29,7 +31,7 @@ export abstract class CreateParticipant {
/** /**
* The new participant's phone number. * The new participant's phone number.
* Optional. * This will be validated against the configured country phone numer syntax (default: international).
*/ */
@IsString() @IsString()
@IsOptional() @IsOptional()
@ -38,7 +40,6 @@ export abstract class CreateParticipant {
/** /**
* The new participant's e-mail address. * The new participant's e-mail address.
* Optional.
*/ */
@IsString() @IsString()
@IsOptional() @IsOptional()
@ -48,14 +49,13 @@ export abstract class CreateParticipant {
/** /**
* The new participant's address. * The new participant's address.
* Must be of type number (address id). * Must be of type number (address id).
* Optional.
*/ */
@IsInt() @IsInt()
@IsOptional() @IsOptional()
address?: number; address?: number;
/** /**
* Get's this participant's address from this.address. * Gets the new participant's address by it's address.
*/ */
public async getAddress(): Promise<Address> { public async getAddress(): Promise<Address> {
if (this.address === undefined || this.address === null) { if (this.address === undefined || this.address === null) {

View File

@ -11,33 +11,33 @@ import { PermissionAction } from '../enums/PermissionAction';
import { PermissionTarget } from '../enums/PermissionTargets'; import { PermissionTarget } from '../enums/PermissionTargets';
/** /**
* Defines a track of given length. * This classed is used to create a new Permission entity from a json body (post request).
*/ */
export class CreatePermission { export class CreatePermission {
/** /**
* The permissions's principal's id. * The new permissions's principal's id.
*/ */
@IsInt() @IsInt()
@IsNotEmpty() @IsNotEmpty()
principal: number; principal: number;
/** /**
* The permissions's target. * The new permissions's target.
*/ */
@IsNotEmpty() @IsNotEmpty()
@IsEnum(PermissionTarget) @IsEnum(PermissionTarget)
target: PermissionTarget; target: PermissionTarget;
/** /**
* The permissions's action. * The new permissions's action.
*/ */
@IsNotEmpty() @IsNotEmpty()
@IsEnum(PermissionAction) @IsEnum(PermissionAction)
action: PermissionAction; action: PermissionAction;
/** /**
* Converts a Permission object based on this. * Creates a new Permission entity from this.
*/ */
public async toPermission(): Promise<Permission> { public async toPermission(): Promise<Permission> {
let newPermission: Permission = new Permission(); let newPermission: Permission = new Permission();
@ -49,6 +49,9 @@ export class CreatePermission {
return newPermission; return newPermission;
} }
/**
* Gets the new permission's principal by it's id.
*/
public async getPrincipal(): Promise<Principal> { public async getPrincipal(): Promise<Principal> {
let principal = await getConnectionManager().get().getRepository(Principal).findOne({ id: this.principal }) let principal = await getConnectionManager().get().getRepository(Principal).findOne({ id: this.principal })
if (!principal) { throw new PrincipalNotFoundError(); } if (!principal) { throw new PrincipalNotFoundError(); }

View File

@ -7,6 +7,9 @@ import { Runner } from '../entities/Runner';
import { RunnerGroup } from '../entities/RunnerGroup'; import { RunnerGroup } from '../entities/RunnerGroup';
import { CreateParticipant } from './CreateParticipant'; import { CreateParticipant } from './CreateParticipant';
/**
* This classed is used to create a new Runner entity from a json body (post request).
*/
export class CreateRunner extends CreateParticipant { export class CreateRunner extends CreateParticipant {
/** /**
@ -16,7 +19,7 @@ export class CreateRunner extends CreateParticipant {
group: number; group: number;
/** /**
* Creates a Runner entity from this. * Creates a new Runner entity from this.
*/ */
public async toRunner(): Promise<Runner> { public async toRunner(): Promise<Runner> {
let newRunner: Runner = new Runner(); let newRunner: Runner = new Runner();
@ -33,7 +36,7 @@ export class CreateRunner extends CreateParticipant {
} }
/** /**
* Manages all the different ways a group can be provided. * Gets the new runner's group by it's id.
*/ */
public async getGroup(): Promise<RunnerGroup> { public async getGroup(): Promise<RunnerGroup> {
if (this.group === undefined || this.group === null) { if (this.group === undefined || this.group === null) {

View File

@ -3,16 +3,19 @@ import { getConnectionManager } from 'typeorm';
import { GroupContactNotFoundError, GroupContactWrongTypeError } from '../../errors/GroupContactErrors'; import { GroupContactNotFoundError, GroupContactWrongTypeError } from '../../errors/GroupContactErrors';
import { GroupContact } from '../entities/GroupContact'; import { GroupContact } from '../entities/GroupContact';
/**
* This classed is used to create a new RunnerGroup entity from a json body (post request).
*/
export abstract class CreateRunnerGroup { export abstract class CreateRunnerGroup {
/** /**
* The group's name. * The new group's name.
*/ */
@IsNotEmpty() @IsNotEmpty()
@IsString() @IsString()
name: string; name: string;
/** /**
* The group's contact. * The new group's contact.
* Optional * Optional
*/ */
@IsInt() @IsInt()
@ -20,7 +23,7 @@ export abstract class CreateRunnerGroup {
contact?: number; contact?: number;
/** /**
* Get's this group's contact from this.address. * Gets the new group's contact by it's id.
*/ */
public async getContact(): Promise<GroupContact> { public async getContact(): Promise<GroupContact> {
if (this.contact === undefined || this.contact === null) { if (this.contact === undefined || this.contact === null) {

View File

@ -5,18 +5,20 @@ import { Address } from '../entities/Address';
import { RunnerOrganisation } from '../entities/RunnerOrganisation'; import { RunnerOrganisation } from '../entities/RunnerOrganisation';
import { CreateRunnerGroup } from './CreateRunnerGroup'; import { CreateRunnerGroup } from './CreateRunnerGroup';
/**
* This classed is used to create a new RunnerOrganisation entity from a json body (post request).
*/
export class CreateRunnerOrganisation extends CreateRunnerGroup { export class CreateRunnerOrganisation extends CreateRunnerGroup {
/** /**
* The new organisation's address. * The new organisation's address.
* Must be of type number (address id). * Must be of type number (address id).
* Optional.
*/ */
@IsInt() @IsInt()
@IsOptional() @IsOptional()
address?: number; address?: number;
/** /**
* Get's this org's address from this.address. * Gets the org's address by it's id.
*/ */
public async getAddress(): Promise<Address> { public async getAddress(): Promise<Address> {
if (this.address === undefined || this.address === null) { if (this.address === undefined || this.address === null) {
@ -32,7 +34,7 @@ export class CreateRunnerOrganisation extends CreateRunnerGroup {
} }
/** /**
* Creates a RunnerOrganisation entity from this. * Creates a new RunnerOrganisation entity from this.
*/ */
public async toRunnerOrganisation(): Promise<RunnerOrganisation> { public async toRunnerOrganisation(): Promise<RunnerOrganisation> {
let newRunnerOrganisation: RunnerOrganisation = new RunnerOrganisation(); let newRunnerOrganisation: RunnerOrganisation = new RunnerOrganisation();

View File

@ -6,15 +6,21 @@ import { RunnerOrganisation } from '../entities/RunnerOrganisation';
import { RunnerTeam } from '../entities/RunnerTeam'; import { RunnerTeam } from '../entities/RunnerTeam';
import { CreateRunnerGroup } from './CreateRunnerGroup'; import { CreateRunnerGroup } from './CreateRunnerGroup';
/**
* This classed is used to create a new RunnerTeam entity from a json body (post request).
*/
export class CreateRunnerTeam extends CreateRunnerGroup { export class CreateRunnerTeam extends CreateRunnerGroup {
/** /**
* The team's parent group (organisation). * The new team's parent group (organisation).
*/ */
@IsInt() @IsInt()
@IsNotEmpty() @IsNotEmpty()
parentGroup: number; parentGroup: number;
/**
* Gets the new team's parent org based on it's id.
*/
public async getParent(): Promise<RunnerOrganisation> { public async getParent(): Promise<RunnerOrganisation> {
if (this.parentGroup === undefined || this.parentGroup === null) { if (this.parentGroup === undefined || this.parentGroup === null) {
throw new RunnerTeamNeedsParentError(); throw new RunnerTeamNeedsParentError();
@ -29,7 +35,7 @@ export class CreateRunnerTeam extends CreateRunnerGroup {
} }
/** /**
* Creates a RunnerTeam entity from this. * Creates a new RunnerTeam entity from this.
*/ */
public async toRunnerTeam(): Promise<RunnerTeam> { public async toRunnerTeam(): Promise<RunnerTeam> {
let newRunnerTeam: RunnerTeam = new RunnerTeam(); let newRunnerTeam: RunnerTeam = new RunnerTeam();

View File

@ -1,23 +1,26 @@
import { IsInt, IsNotEmpty, IsPositive, IsString } from 'class-validator'; import { IsInt, IsNotEmpty, IsPositive, IsString } from 'class-validator';
import { Track } from '../entities/Track'; import { Track } from '../entities/Track';
/**
* This classed is used to create a new Track entity from a json body (post request).
*/
export class CreateTrack { export class CreateTrack {
/** /**
* The track's name. * The new track's name.
*/ */
@IsString() @IsString()
@IsNotEmpty() @IsNotEmpty()
name: string; name: string;
/** /**
* The track's distance in meters (must be greater than 0). * The new track's distance in meters (must be greater than 0).
*/ */
@IsInt() @IsInt()
@IsPositive() @IsPositive()
distance: number; distance: number;
/** /**
* Converts a Track object based on this. * Creates a new Track entity from this.
*/ */
public toTrack(): Track { public toTrack(): Track {
let newTrack: Track = new Track(); let newTrack: Track = new Track();

View File

@ -8,6 +8,9 @@ import { UserGroupNotFoundError } from '../../errors/UserGroupErrors';
import { User } from '../entities/User'; import { User } from '../entities/User';
import { UserGroup } from '../entities/UserGroup'; import { UserGroup } from '../entities/UserGroup';
/**
* This classed is used to create a new User entity from a json body (post request).
*/
export class CreateUser { export class CreateUser {
/** /**
* The new user's first name. * The new user's first name.
@ -17,7 +20,6 @@ export class CreateUser {
/** /**
* The new user's middle name. * The new user's middle name.
* Optinal.
*/ */
@IsString() @IsString()
@IsOptional() @IsOptional()
@ -48,7 +50,7 @@ export class CreateUser {
/** /**
* The new user's phone number. * The new user's phone number.
* Optional * This will be validated against the configured country phone numer syntax (default: international).
*/ */
@IsPhoneNumber(config.phone_validation_countrycode) @IsPhoneNumber(config.phone_validation_countrycode)
@IsOptional() @IsOptional()
@ -64,7 +66,6 @@ export class CreateUser {
/** /**
* The new user's groups' id(s). * The new user's groups' id(s).
* You can provide either one groupId or an array of groupIDs. * You can provide either one groupId or an array of groupIDs.
* Optional.
*/ */
@IsOptional() @IsOptional()
groups?: number[] | number groups?: number[] | number
@ -72,7 +73,7 @@ export class CreateUser {
//TODO: ProfilePics //TODO: ProfilePics
/** /**
* Converts this to a User Entity. * Converts this to a User entity.
*/ */
public async toUser(): Promise<User> { public async toUser(): Promise<User> {
let newUser: User = new User(); let newUser: User = new User();

View File

@ -1,6 +1,9 @@
import { IsOptional, IsString } from 'class-validator'; import { IsOptional, IsString } from 'class-validator';
import { UserGroup } from '../entities/UserGroup'; import { UserGroup } from '../entities/UserGroup';
/**
* This classed is used to create a new UserGroup entity from a json body (post request).
*/
export class CreateUserGroup { export class CreateUserGroup {
/** /**
* The new group's name. * The new group's name.
@ -17,7 +20,7 @@ export class CreateUserGroup {
description?: string; description?: string;
/** /**
* Converts this to a UserGroup entity. * Creates a new UserGroup entity from this.
*/ */
public async toUserGroup(): Promise<UserGroup> { public async toUserGroup(): Promise<UserGroup> {
let newUserGroup: UserGroup = new UserGroup(); let newUserGroup: UserGroup = new UserGroup();