feat(responses): Added created_at/updated_at

This commit is contained in:
Nicolai Ort 2025-05-06 19:38:20 +02:00
parent 728f8a14e9
commit f225cc4954
Signed by: niggl
GPG Key ID: 13AFA55AF62F269F
11 changed files with 120 additions and 8 deletions

View File

@ -40,6 +40,14 @@ export class ResponseAnonymousDonation implements IResponse {
@IsInt() @IsInt()
paidAmount: number; paidAmount: number;
@IsInt()
@IsPositive()
created_at: number;
@IsInt()
@IsPositive()
updated_at: number;
/** /**
* Creates a ResponseDonation object from a scan. * Creates a ResponseDonation object from a scan.
* @param donation The donation the response shall be build for. * @param donation The donation the response shall be build for.
@ -54,5 +62,7 @@ export class ResponseAnonymousDonation implements IResponse {
else { else {
this.status = DonationStatus.PAID; this.status = DonationStatus.PAID;
} }
this.created_at = donation.created_at;
this.updated_at = donation.updated_at;
} }
} }

View File

@ -47,6 +47,14 @@ export class ResponseDonation implements IResponse {
@IsInt() @IsInt()
paidAmount: number; paidAmount: number;
@IsInt()
@IsPositive()
created_at: number;
@IsInt()
@IsPositive()
updated_at: number;
/** /**
* Creates a ResponseDonation object from a scan. * Creates a ResponseDonation object from a scan.
* @param donation The donation the response shall be build for. * @param donation The donation the response shall be build for.
@ -64,5 +72,7 @@ export class ResponseDonation implements IResponse {
else { else {
this.status = DonationStatus.PAID; this.status = DonationStatus.PAID;
} }
this.created_at = donation.created_at;
this.updated_at = donation.updated_at;
} }
} }

View File

@ -1,4 +1,4 @@
import { IsInt, IsObject, IsString } from "class-validator"; import { IsInt, IsObject, IsPositive, IsString } from "class-validator";
import { Address } from '../entities/Address'; import { Address } from '../entities/Address';
import { GroupContact } from '../entities/GroupContact'; import { GroupContact } from '../entities/GroupContact';
import { ResponseObjectType } from '../enums/ResponseObjectType'; import { ResponseObjectType } from '../enums/ResponseObjectType';
@ -64,6 +64,14 @@ export class ResponseGroupContact implements IResponse {
@IsObject() @IsObject()
address?: Address; address?: Address;
@IsInt()
@IsPositive()
created_at: number;
@IsInt()
@IsPositive()
updated_at: number;
/** /**
* Creates a ResponseGroupContact object from a contact. * Creates a ResponseGroupContact object from a contact.
* @param contact The contact the response shall be build for. * @param contact The contact the response shall be build for.
@ -82,5 +90,7 @@ export class ResponseGroupContact implements IResponse {
this.groups.push(group.toResponse()); this.groups.push(group.toResponse());
} }
} }
this.created_at = contact.created_at;
this.updated_at = contact.updated_at;
} }
} }

View File

@ -2,7 +2,8 @@ import {
IsEnum, IsEnum,
IsInt, IsInt,
IsNotEmpty, IsNotEmpty,
IsObject IsObject,
IsPositive
} from "class-validator"; } from "class-validator";
import { Permission } from '../entities/Permission'; import { Permission } from '../entities/Permission';
import { PermissionAction } from '../enums/PermissionAction'; import { PermissionAction } from '../enums/PermissionAction';
@ -48,6 +49,14 @@ export class ResponsePermission implements IResponse {
@IsEnum(PermissionAction) @IsEnum(PermissionAction)
action: PermissionAction; action: PermissionAction;
@IsInt()
@IsPositive()
created_at: number;
@IsInt()
@IsPositive()
updated_at: number;
/** /**
* Creates a ResponsePermission object from a permission. * Creates a ResponsePermission object from a permission.
* @param permission The permission the response shall be build for. * @param permission The permission the response shall be build for.
@ -57,5 +66,7 @@ export class ResponsePermission implements IResponse {
this.principal = permission.principal.toResponse(); this.principal = permission.principal.toResponse();
this.target = permission.target; this.target = permission.target;
this.action = permission.action; this.action = permission.action;
this.created_at = permission.created_at;
this.updated_at = permission.updated_at;
} }
} }

View File

@ -1,5 +1,6 @@
import { import {
IsInt IsInt,
IsPositive
} from "class-validator"; } from "class-validator";
import { Principal } from '../entities/Principal'; import { Principal } from '../entities/Principal';
import { ResponseObjectType } from '../enums/ResponseObjectType'; import { ResponseObjectType } from '../enums/ResponseObjectType';
@ -22,11 +23,21 @@ export abstract class ResponsePrincipal implements IResponse {
@IsInt() @IsInt()
id: number; id: number;
@IsInt()
@IsPositive()
created_at: number;
@IsInt()
@IsPositive()
updated_at: number;
/** /**
* Creates a ResponsePrincipal object from a principal. * Creates a ResponsePrincipal object from a principal.
* @param principal The principal the response shall be build for. * @param principal The principal the response shall be build for.
*/ */
public constructor(principal: Principal) { public constructor(principal: Principal) {
this.id = principal.id; this.id = principal.id;
this.created_at = principal.created_at;
this.updated_at = principal.updated_at;
} }
} }

View File

@ -1,4 +1,4 @@
import { IsBoolean, IsEAN, IsInt, IsNotEmpty, IsObject, IsString } from "class-validator"; import { IsBoolean, IsEAN, IsInt, IsNotEmpty, IsObject, IsPositive, IsString } from "class-validator";
import { RunnerCard } from '../entities/RunnerCard'; import { RunnerCard } from '../entities/RunnerCard';
import { ResponseObjectType } from '../enums/ResponseObjectType'; import { ResponseObjectType } from '../enums/ResponseObjectType';
import { IResponse } from './IResponse'; import { IResponse } from './IResponse';
@ -42,6 +42,14 @@ export class ResponseRunnerCard implements IResponse {
@IsBoolean() @IsBoolean()
enabled: boolean = true; enabled: boolean = true;
@IsInt()
@IsPositive()
created_at: number;
@IsInt()
@IsPositive()
updated_at: number;
/** /**
* Creates a ResponseRunnerCard object from a runner card. * Creates a ResponseRunnerCard object from a runner card.
* @param card The card the response shall be build for. * @param card The card the response shall be build for.
@ -57,5 +65,7 @@ export class ResponseRunnerCard implements IResponse {
} }
this.enabled = card.enabled; this.enabled = card.enabled;
this.created_at = card.created_at;
this.updated_at = card.updated_at;
} }
} }

View File

@ -1,4 +1,4 @@
import { IsInt, IsNotEmpty, IsNumber, IsObject, IsOptional, IsString } from "class-validator"; import { IsInt, IsNotEmpty, IsNumber, IsObject, IsOptional, IsPositive, IsString } from "class-validator";
import { RunnerGroup } from '../entities/RunnerGroup'; import { RunnerGroup } from '../entities/RunnerGroup';
import { ResponseObjectType } from '../enums/ResponseObjectType'; import { ResponseObjectType } from '../enums/ResponseObjectType';
import { IResponse } from './IResponse'; import { IResponse } from './IResponse';
@ -40,6 +40,14 @@ export abstract class ResponseRunnerGroup implements IResponse {
@IsNumber() @IsNumber()
total_distance: number total_distance: number
@IsInt()
@IsPositive()
created_at: number;
@IsInt()
@IsPositive()
updated_at: number;
/** /**
* Creates a ResponseRunnerGroup object from a runnerGroup. * Creates a ResponseRunnerGroup object from a runnerGroup.
* @param group The runnerGroup the response shall be build for. * @param group The runnerGroup the response shall be build for.
@ -49,5 +57,7 @@ export abstract class ResponseRunnerGroup implements IResponse {
this.name = group.name; this.name = group.name;
if (group.contact) { this.contact = group.contact.toResponse(); }; if (group.contact) { this.contact = group.contact.toResponse(); };
if (group.runners) { this.total_distance = group.runners.reduce((p, c) => p + c.distance, 0) } if (group.runners) { this.total_distance = group.runners.reduce((p, c) => p + c.distance, 0) }
this.created_at = group.created_at;
this.updated_at = group.updated_at;
} }
} }

View File

@ -41,6 +41,14 @@ export class ResponseScan implements IResponse {
@IsPositive() @IsPositive()
distance: number; distance: number;
@IsInt()
@IsPositive()
created_at: number;
@IsInt()
@IsPositive()
updated_at: number;
/** /**
* Creates a ResponseScan object from a scan. * Creates a ResponseScan object from a scan.
* @param scan The scan the response shall be build for. * @param scan The scan the response shall be build for.
@ -50,5 +58,7 @@ export class ResponseScan implements IResponse {
if (scan.runner) { this.runner = scan.runner.toResponse(); } if (scan.runner) { this.runner = scan.runner.toResponse(); }
this.distance = scan.distance; this.distance = scan.distance;
this.valid = scan.valid; this.valid = scan.valid;
this.created_at = scan.created_at;
this.updated_at = scan.updated_at;
} }
} }

View File

@ -1,5 +1,4 @@
import { import {
IsBoolean, IsBoolean,
IsInt, IsInt,
@ -8,6 +7,7 @@ import {
IsObject, IsObject,
IsOptional, IsOptional,
IsPositive,
IsString IsString
} from "class-validator"; } from "class-validator";
import { ScanStation } from '../entities/ScanStation'; import { ScanStation } from '../entities/ScanStation';
@ -63,6 +63,14 @@ export class ResponseScanStation implements IResponse {
@IsBoolean() @IsBoolean()
enabled?: boolean = true; enabled?: boolean = true;
@IsInt()
@IsPositive()
created_at: number;
@IsInt()
@IsPositive()
updated_at: number;
/** /**
* Creates a ResponseStatsClient object from a statsClient. * Creates a ResponseStatsClient object from a statsClient.
* @param client The statsClient the response shall be build for. * @param client The statsClient the response shall be build for.
@ -74,5 +82,7 @@ export class ResponseScanStation implements IResponse {
this.key = "Only visible on creation."; this.key = "Only visible on creation.";
if (station.track) { this.track = station.track.toResponse(); } if (station.track) { this.track = station.track.toResponse(); }
this.enabled = station.enabled; this.enabled = station.enabled;
this.created_at = station.created_at;
this.updated_at = station.updated_at;
} }
} }

View File

@ -1,10 +1,10 @@
import { import {
IsInt, IsInt,
IsNotEmpty, IsNotEmpty,
IsOptional, IsOptional,
IsPositive,
IsString IsString
} from "class-validator"; } from "class-validator";
import { StatsClient } from '../entities/StatsClient'; import { StatsClient } from '../entities/StatsClient';
@ -49,6 +49,14 @@ export class ResponseStatsClient implements IResponse {
@IsNotEmpty() @IsNotEmpty()
prefix: string; prefix: string;
@IsInt()
@IsPositive()
created_at: number;
@IsInt()
@IsPositive()
updated_at: number;
/** /**
* Creates a ResponseStatsClient object from a statsClient. * Creates a ResponseStatsClient object from a statsClient.
* @param client The statsClient the response shall be build for. * @param client The statsClient the response shall be build for.
@ -58,5 +66,7 @@ export class ResponseStatsClient implements IResponse {
this.description = client.description; this.description = client.description;
this.prefix = client.prefix; this.prefix = client.prefix;
this.key = "Only visible on creation."; this.key = "Only visible on creation.";
this.created_at = client.created_at;
this.updated_at = client.updated_at;
} }
} }

View File

@ -1,4 +1,4 @@
import { IsInt, IsOptional, IsString } from "class-validator"; import { IsInt, IsOptional, IsPositive, IsString } from "class-validator";
import { TrackLapTimeCantBeNegativeError } from '../../errors/TrackErrors'; import { TrackLapTimeCantBeNegativeError } from '../../errors/TrackErrors';
import { Track } from '../entities/Track'; import { Track } from '../entities/Track';
import { ResponseObjectType } from '../enums/ResponseObjectType'; import { ResponseObjectType } from '../enums/ResponseObjectType';
@ -40,6 +40,14 @@ export class ResponseTrack implements IResponse {
@IsOptional() @IsOptional()
minimumLapTime?: number; minimumLapTime?: number;
@IsInt()
@IsPositive()
created_at: number;
@IsInt()
@IsPositive()
updated_at: number;
/** /**
* Creates a ResponseTrack object from a track. * Creates a ResponseTrack object from a track.
* @param track The track the response shall be build for. * @param track The track the response shall be build for.
@ -52,5 +60,7 @@ export class ResponseTrack implements IResponse {
if (this.minimumLapTime < 0) { if (this.minimumLapTime < 0) {
throw new TrackLapTimeCantBeNegativeError(); throw new TrackLapTimeCantBeNegativeError();
} }
this.created_at = track.created_at;
this.updated_at = track.updated_at;
} }
} }