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()
paidAmount: number;
@IsInt()
@IsPositive()
created_at: number;
@IsInt()
@IsPositive()
updated_at: number;
/**
* Creates a ResponseDonation object from a scan.
* @param donation The donation the response shall be build for.
@ -54,5 +62,7 @@ export class ResponseAnonymousDonation implements IResponse {
else {
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()
paidAmount: number;
@IsInt()
@IsPositive()
created_at: number;
@IsInt()
@IsPositive()
updated_at: number;
/**
* Creates a ResponseDonation object from a scan.
* @param donation The donation the response shall be build for.
@ -64,5 +72,7 @@ export class ResponseDonation implements IResponse {
else {
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 { GroupContact } from '../entities/GroupContact';
import { ResponseObjectType } from '../enums/ResponseObjectType';
@ -64,6 +64,14 @@ export class ResponseGroupContact implements IResponse {
@IsObject()
address?: Address;
@IsInt()
@IsPositive()
created_at: number;
@IsInt()
@IsPositive()
updated_at: number;
/**
* Creates a ResponseGroupContact object from a contact.
* @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.created_at = contact.created_at;
this.updated_at = contact.updated_at;
}
}

View File

@ -2,7 +2,8 @@ import {
IsEnum,
IsInt,
IsNotEmpty,
IsObject
IsObject,
IsPositive
} from "class-validator";
import { Permission } from '../entities/Permission';
import { PermissionAction } from '../enums/PermissionAction';
@ -48,6 +49,14 @@ export class ResponsePermission implements IResponse {
@IsEnum(PermissionAction)
action: PermissionAction;
@IsInt()
@IsPositive()
created_at: number;
@IsInt()
@IsPositive()
updated_at: number;
/**
* Creates a ResponsePermission object from a permission.
* @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.target = permission.target;
this.action = permission.action;
this.created_at = permission.created_at;
this.updated_at = permission.updated_at;
}
}

View File

@ -1,5 +1,6 @@
import {
IsInt
IsInt,
IsPositive
} from "class-validator";
import { Principal } from '../entities/Principal';
import { ResponseObjectType } from '../enums/ResponseObjectType';
@ -22,11 +23,21 @@ export abstract class ResponsePrincipal implements IResponse {
@IsInt()
id: number;
@IsInt()
@IsPositive()
created_at: number;
@IsInt()
@IsPositive()
updated_at: 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;
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 { ResponseObjectType } from '../enums/ResponseObjectType';
import { IResponse } from './IResponse';
@ -42,6 +42,14 @@ export class ResponseRunnerCard implements IResponse {
@IsBoolean()
enabled: boolean = true;
@IsInt()
@IsPositive()
created_at: number;
@IsInt()
@IsPositive()
updated_at: number;
/**
* Creates a ResponseRunnerCard object from a runner card.
* @param card The card the response shall be build for.
@ -57,5 +65,7 @@ export class ResponseRunnerCard implements IResponse {
}
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 { ResponseObjectType } from '../enums/ResponseObjectType';
import { IResponse } from './IResponse';
@ -40,6 +40,14 @@ export abstract class ResponseRunnerGroup implements IResponse {
@IsNumber()
total_distance: number
@IsInt()
@IsPositive()
created_at: number;
@IsInt()
@IsPositive()
updated_at: number;
/**
* Creates a ResponseRunnerGroup object from a runnerGroup.
* @param group The runnerGroup the response shall be build for.
@ -49,5 +57,7 @@ export abstract class ResponseRunnerGroup implements IResponse {
this.name = group.name;
if (group.contact) { this.contact = group.contact.toResponse(); };
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()
distance: number;
@IsInt()
@IsPositive()
created_at: number;
@IsInt()
@IsPositive()
updated_at: number;
/**
* Creates a ResponseScan object from a scan.
* @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(); }
this.distance = scan.distance;
this.valid = scan.valid;
this.created_at = scan.created_at;
this.updated_at = scan.updated_at;
}
}

View File

@ -1,5 +1,4 @@
import {
IsBoolean,
IsInt,
@ -8,6 +7,7 @@ import {
IsObject,
IsOptional,
IsPositive,
IsString
} from "class-validator";
import { ScanStation } from '../entities/ScanStation';
@ -63,6 +63,14 @@ export class ResponseScanStation implements IResponse {
@IsBoolean()
enabled?: boolean = true;
@IsInt()
@IsPositive()
created_at: number;
@IsInt()
@IsPositive()
updated_at: number;
/**
* Creates a ResponseStatsClient object from a statsClient.
* @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.";
if (station.track) { this.track = station.track.toResponse(); }
this.enabled = station.enabled;
this.created_at = station.created_at;
this.updated_at = station.updated_at;
}
}

View File

@ -1,10 +1,10 @@
import {
IsInt,
IsNotEmpty,
IsOptional,
IsPositive,
IsString
} from "class-validator";
import { StatsClient } from '../entities/StatsClient';
@ -49,6 +49,14 @@ export class ResponseStatsClient implements IResponse {
@IsNotEmpty()
prefix: string;
@IsInt()
@IsPositive()
created_at: number;
@IsInt()
@IsPositive()
updated_at: number;
/**
* Creates a ResponseStatsClient object from a statsClient.
* @param client The statsClient the response shall be build for.
@ -58,5 +66,7 @@ export class ResponseStatsClient implements IResponse {
this.description = client.description;
this.prefix = client.prefix;
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 { Track } from '../entities/Track';
import { ResponseObjectType } from '../enums/ResponseObjectType';
@ -40,6 +40,14 @@ export class ResponseTrack implements IResponse {
@IsOptional()
minimumLapTime?: number;
@IsInt()
@IsPositive()
created_at: number;
@IsInt()
@IsPositive()
updated_at: number;
/**
* Creates a ResponseTrack object from a track.
* @param track The track the response shall be build for.
@ -52,5 +60,7 @@ export class ResponseTrack implements IResponse {
if (this.minimumLapTime < 0) {
throw new TrackLapTimeCantBeNegativeError();
}
this.created_at = track.created_at;
this.updated_at = track.updated_at;
}
}