From 75332983c2b6eec549af8b479c864277102e3f7d Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Sun, 20 Dec 2020 19:38:22 +0100 Subject: [PATCH] Code + comment cleanup for the response models ref #39 --- src/models/responses/ResponseAuth.ts | 13 +++++--- src/models/responses/ResponseEmpty.ts | 2 +- src/models/responses/ResponseLogout.ts | 4 +-- src/models/responses/ResponseParticipant.ts | 19 ++++------- src/models/responses/ResponsePermission.ts | 8 +++-- src/models/responses/ResponsePrincipal.ts | 8 +++-- src/models/responses/ResponseRunner.ts | 7 ++-- src/models/responses/ResponseRunnerGroup.ts | 33 +++++-------------- .../responses/ResponseRunnerOrganisation.ts | 12 ++++--- src/models/responses/ResponseRunnerTeam.ts | 14 ++++---- src/models/responses/ResponseTrack.ts | 14 ++++---- src/models/responses/ResponseUser.ts | 18 +++++----- src/models/responses/ResponseUserGroup.ts | 22 +++++-------- 13 files changed, 83 insertions(+), 91 deletions(-) diff --git a/src/models/responses/ResponseAuth.ts b/src/models/responses/ResponseAuth.ts index 39a16ef..5a8aa9e 100644 --- a/src/models/responses/ResponseAuth.ts +++ b/src/models/responses/ResponseAuth.ts @@ -1,26 +1,29 @@ import { IsInt, IsString } from 'class-validator'; /** - * Defines a auth object + * Defines the repsonse auth. */ export class Auth { /** - * access_token - JWT shortterm access token + * The access_token - JWT shortterm access token. */ @IsString() access_token: string; + /** - * refresh_token - longterm refresh token (used for requesting new access tokens) + * The refresh_token - longterm refresh token (used for requesting new access tokens). */ @IsString() refresh_token: string; + /** - * access_token_expires_at - unix timestamp of access token expiry + * The unix timestamp for access the token's expiry. */ @IsInt() access_token_expires_at: number; + /** - * refresh_token_expires_at - unix timestamp of access token expiry + * The unix unix timestamp for the access token's expiry. */ @IsInt() refresh_token_expires_at: number; diff --git a/src/models/responses/ResponseEmpty.ts b/src/models/responses/ResponseEmpty.ts index 7787b2a..57b0543 100644 --- a/src/models/responses/ResponseEmpty.ts +++ b/src/models/responses/ResponseEmpty.ts @@ -1,7 +1,7 @@ import { IsString } from 'class-validator'; /** - * Defines a empty response object + * Defines a empty response object. */ export class ResponseEmpty { @IsString() diff --git a/src/models/responses/ResponseLogout.ts b/src/models/responses/ResponseLogout.ts index f0c109d..fdb8d49 100644 --- a/src/models/responses/ResponseLogout.ts +++ b/src/models/responses/ResponseLogout.ts @@ -1,11 +1,11 @@ import { IsString } from 'class-validator'; /** - * Defines a Logout object + * Defines the logout response. */ export class Logout { /** - * timestamp of logout + * The logout's timestamp. */ @IsString() timestamp: number; diff --git a/src/models/responses/ResponseParticipant.ts b/src/models/responses/ResponseParticipant.ts index 0647efe..148bcff 100644 --- a/src/models/responses/ResponseParticipant.ts +++ b/src/models/responses/ResponseParticipant.ts @@ -1,18 +1,12 @@ -import { - IsInt, - - - - IsString -} from "class-validator"; +import { IsInt, IsString } from "class-validator"; import { Participant } from '../entities/Participant'; /** - * Defines a participant response. + * Defines the participant response. */ export abstract class ResponseParticipant { /** - * Autogenerated unique id (primary key). + * The participant's id. */ @IsInt() id: number; @@ -25,7 +19,6 @@ export abstract class ResponseParticipant { /** * The participant's middle name. - * Optional. */ @IsString() middlename?: string; @@ -38,18 +31,20 @@ export abstract class ResponseParticipant { /** * The participant's phone number. - * Optional. */ @IsString() phone?: string; /** * The participant's e-mail address. - * Optional. */ @IsString() email?: string; + /** + * Creates a ResponseParticipant object from a participant. + * @param participant The participant the response shall be build for. + */ public constructor(participant: Participant) { this.id = participant.id; this.firstname = participant.firstname; diff --git a/src/models/responses/ResponsePermission.ts b/src/models/responses/ResponsePermission.ts index 23a3686..a6b0bc1 100644 --- a/src/models/responses/ResponsePermission.ts +++ b/src/models/responses/ResponsePermission.ts @@ -10,11 +10,11 @@ import { PermissionTarget } from '../enums/PermissionTargets'; import { ResponsePrincipal } from './ResponsePrincipal'; /** - * Defines a track of given length. + * Defines the permission response. */ export class ResponsePermission { /** - * Autogenerated unique id (primary key). + * The permission's id. */ @IsInt() id: number;; @@ -40,6 +40,10 @@ export class ResponsePermission { @IsEnum(PermissionAction) action: PermissionAction; + /** + * Creates a ResponsePermission object from a permission. + * @param permission The permission the response shall be build for. + */ public constructor(permission: Permission) { this.id = permission.id; this.principal = permission.principal.toResponse(); diff --git a/src/models/responses/ResponsePrincipal.ts b/src/models/responses/ResponsePrincipal.ts index 920bac2..afd4dd1 100644 --- a/src/models/responses/ResponsePrincipal.ts +++ b/src/models/responses/ResponsePrincipal.ts @@ -4,16 +4,20 @@ import { import { Principal } from '../entities/Principal'; /** - * Defines Principal's response class. + * Defines the principal response. */ export abstract class ResponsePrincipal { /** - * Autogenerated unique id (primary key). + * The principal's id. */ @IsInt() id: number; + /** + * Creates a ResponsePrincipal object from a principal. + * @param principal The principal the response shall be build for. + */ public constructor(principal: Principal) { this.id = principal.id; } diff --git a/src/models/responses/ResponseRunner.ts b/src/models/responses/ResponseRunner.ts index 01327c2..5fae2ee 100644 --- a/src/models/responses/ResponseRunner.ts +++ b/src/models/responses/ResponseRunner.ts @@ -7,13 +7,12 @@ import { RunnerGroup } from '../entities/RunnerGroup'; import { ResponseParticipant } from './ResponseParticipant'; /** - * Defines RunnerTeam's response class. + * Defines the runner response. */ export class ResponseRunner extends ResponseParticipant { /** * The runner's currently ran distance in meters. - * Optional. */ @IsInt() distance: number; @@ -24,6 +23,10 @@ export class ResponseRunner extends ResponseParticipant { @IsObject() group: RunnerGroup; + /** + * Creates a ResponseRunner object from a runner. + * @param runner The user the response shall be build for. + */ public constructor(runner: Runner) { super(runner); this.distance = runner.scans.filter(scan => { scan.valid === true }).reduce((sum, current) => sum + current.distance, 0); diff --git a/src/models/responses/ResponseRunnerGroup.ts b/src/models/responses/ResponseRunnerGroup.ts index 922f141..7be35a6 100644 --- a/src/models/responses/ResponseRunnerGroup.ts +++ b/src/models/responses/ResponseRunnerGroup.ts @@ -1,38 +1,20 @@ -import { - IsInt, - - - - IsNotEmpty, - - - - IsObject, - - - - IsOptional, - - - - IsString -} from "class-validator"; +import { IsInt, IsNotEmpty, IsObject, IsOptional, IsString } from "class-validator"; import { GroupContact } from '../entities/GroupContact'; import { RunnerGroup } from '../entities/RunnerGroup'; /** - * Defines a track of given length. + * Defines the runnerGroup response. */ export abstract class ResponseRunnerGroup { /** - * Autogenerated unique id (primary key). + * The runnerGroup's id. */ @IsInt() @IsNotEmpty() id: number;; /** - * The groups's name. + * The runnerGroup's name. */ @IsString() @IsNotEmpty() @@ -40,13 +22,16 @@ export abstract class ResponseRunnerGroup { /** - * The group's contact. - * Optional. + * The runnerGroup's contact. */ @IsObject() @IsOptional() contact?: GroupContact; + /** + * Creates a ResponseRunnerGroup object from a runnerGroup. + * @param group The runnerGroup the response shall be build for. + */ public constructor(group: RunnerGroup) { this.id = group.id; this.name = group.name; diff --git a/src/models/responses/ResponseRunnerOrganisation.ts b/src/models/responses/ResponseRunnerOrganisation.ts index e8b7b9a..edc1ff0 100644 --- a/src/models/responses/ResponseRunnerOrganisation.ts +++ b/src/models/responses/ResponseRunnerOrganisation.ts @@ -9,25 +9,27 @@ import { RunnerTeam } from '../entities/RunnerTeam'; import { ResponseRunnerGroup } from './ResponseRunnerGroup'; /** - * Defines RunnerOrgs's response class. + * Defines the runnerOrganisation response. */ export class ResponseRunnerOrganisation extends ResponseRunnerGroup { /** - * The orgs's address. - * Optional. + * The runnerOrganisation's address. */ @IsObject() @IsNotEmpty() address?: Address; /** - * The orgs associated teams. + * The runnerOrganisation associated teams. */ @IsArray() teams: RunnerTeam[]; - + /** + * Creates a ResponseRunnerOrganisation object from a runnerOrganisation. + * @param org The runnerOrganisation the response shall be build for. + */ public constructor(org: RunnerOrganisation) { super(org); this.address = org.address; diff --git a/src/models/responses/ResponseRunnerTeam.ts b/src/models/responses/ResponseRunnerTeam.ts index b26e2c2..0a15302 100644 --- a/src/models/responses/ResponseRunnerTeam.ts +++ b/src/models/responses/ResponseRunnerTeam.ts @@ -1,24 +1,24 @@ -import { - IsNotEmpty, - IsObject -} from "class-validator"; +import { IsNotEmpty, IsObject } from "class-validator"; import { RunnerOrganisation } from '../entities/RunnerOrganisation'; import { RunnerTeam } from '../entities/RunnerTeam'; import { ResponseRunnerGroup } from './ResponseRunnerGroup'; /** - * Defines RunnerTeam's response class. + * Defines the runnerTeam response. */ export class ResponseRunnerTeam extends ResponseRunnerGroup { /** - * The team's parent group (organisation). - * Optional. + * The runnerTeam's parent group (organisation). */ @IsObject() @IsNotEmpty() parentGroup: RunnerOrganisation; + /** + * Creates a ResponseRunnerTeam object from a runnerTeam. + * @param team The team the response shall be build for. + */ public constructor(team: RunnerTeam) { super(team); this.parentGroup = team.parentGroup; diff --git a/src/models/responses/ResponseTrack.ts b/src/models/responses/ResponseTrack.ts index ce1d74d..83da863 100644 --- a/src/models/responses/ResponseTrack.ts +++ b/src/models/responses/ResponseTrack.ts @@ -1,16 +1,12 @@ -import { - IsInt, - - IsString -} from "class-validator"; +import { IsInt, IsString } from "class-validator"; import { Track } from '../entities/Track'; /** - * Defines a track of given length. + * Defines the track response. */ export class ResponseTrack { /** - * Autogenerated unique id (primary key). + * The track's id. */ @IsInt() id: number;; @@ -27,6 +23,10 @@ export class ResponseTrack { @IsInt() distance: number; + /** + * Creates a ResponseTrack object from a track. + * @param track The track the response shall be build for. + */ public constructor(track: Track) { this.id = track.id; this.name = track.name; diff --git a/src/models/responses/ResponseUser.ts b/src/models/responses/ResponseUser.ts index 0927106..67fad20 100644 --- a/src/models/responses/ResponseUser.ts +++ b/src/models/responses/ResponseUser.ts @@ -11,7 +11,7 @@ import { UserGroup } from '../entities/UserGroup'; import { ResponsePrincipal } from './ResponsePrincipal'; /** - * Defines a user response. + * Defines the user response. */ export class ResponseUser extends ResponsePrincipal { /** @@ -22,7 +22,6 @@ export class ResponseUser extends ResponsePrincipal { /** * The user's middle name. - * Optional. */ @IsString() middlename?: string; @@ -35,52 +34,53 @@ export class ResponseUser extends ResponsePrincipal { /** * The user's phone number. - * Optional. */ @IsString() phone?: string; /** * The user's e-mail address. - * Optional. */ @IsString() email?: string; /** * The user's username. - * Optional. */ @IsString() username?: string; /** - * is user enabled? + * Is user enabled? */ @IsBoolean() enabled: boolean = true; /** - * profilepic + * The user's profile pic. */ @IsString() @IsOptional() profilePic?: string; /** - * Groups + * The groups that the user is a part of. */ @IsArray() @IsOptional() groups: UserGroup[]; /** - * permissions + * The user's permissions. */ @IsArray() @IsOptional() permissions: Permission[]; + /** + * Creates a ResponseUser object from a user. + * @param user The user the response shall be build for. + */ public constructor(user: User) { super(user); this.firstname = user.firstname; diff --git a/src/models/responses/ResponseUserGroup.ts b/src/models/responses/ResponseUserGroup.ts index 1317c8f..6dd428d 100644 --- a/src/models/responses/ResponseUserGroup.ts +++ b/src/models/responses/ResponseUserGroup.ts @@ -1,41 +1,37 @@ -import { - IsArray, - - - IsNotEmpty, - - IsOptional, - IsString -} from "class-validator"; +import { IsArray, IsNotEmpty, IsOptional, IsString } from "class-validator"; import { Permission } from '../entities/Permission'; import { UserGroup } from '../entities/UserGroup'; import { ResponsePrincipal } from './ResponsePrincipal'; /** - * Defines a user response. + * Defines the userGroup response. */ export class ResponseUserGroup extends ResponsePrincipal { /** - * The group's name + * The userGroup's name. */ @IsNotEmpty() @IsString() name: string; /** - * The group's description + * The userGroup's description. */ @IsOptional() @IsString() description?: string; /** - * permissions + * The userGroup's permissions. */ @IsArray() @IsOptional() permissions: Permission[]; + /** + * Creates a ResponseUserGroup object from a userGroup. + * @param group The userGroup the response shall be build for. + */ public constructor(group: UserGroup) { super(group); this.name = group.name;