From 03ce83b89896b0f28bad194f595dee6dc440e40b Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Tue, 12 Mar 2024 17:01:02 +0700 Subject: [PATCH 1/4] fix: history response --- src/controllers/ProfileCertificateController.ts | 2 +- src/controllers/ProfileHonorController.ts | 2 +- src/controllers/ProfileInsigniaController.ts | 2 +- src/controllers/ProfileTrainingController.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/controllers/ProfileCertificateController.ts b/src/controllers/ProfileCertificateController.ts index b4e17a21..b7cc239a 100644 --- a/src/controllers/ProfileCertificateController.ts +++ b/src/controllers/ProfileCertificateController.ts @@ -41,7 +41,7 @@ export class ProfileCertificateController extends Controller { const record = await this.certificateHistoryRepo.findBy({ profileCertificateId: certificateId, }); - return record; + return new HttpSuccess(record); } @Post() diff --git a/src/controllers/ProfileHonorController.ts b/src/controllers/ProfileHonorController.ts index f5e34158..818383e2 100644 --- a/src/controllers/ProfileHonorController.ts +++ b/src/controllers/ProfileHonorController.ts @@ -37,7 +37,7 @@ export class ProfileHonorController extends Controller { const record = await this.honorHistoryRepo.findBy({ profileHonorId: honorId, }); - return record; + return new HttpSuccess(record); } @Post() diff --git a/src/controllers/ProfileInsigniaController.ts b/src/controllers/ProfileInsigniaController.ts index a24c6730..b3316fb9 100644 --- a/src/controllers/ProfileInsigniaController.ts +++ b/src/controllers/ProfileInsigniaController.ts @@ -41,7 +41,7 @@ export class ProfileInsigniaController extends Controller { const record = await this.insigniaHistoryRepo.findBy({ profileInsigniaId: InsigniaId, }); - return record; + return new HttpSuccess(record); } @Post() diff --git a/src/controllers/ProfileTrainingController.ts b/src/controllers/ProfileTrainingController.ts index e5a02183..f3b53608 100644 --- a/src/controllers/ProfileTrainingController.ts +++ b/src/controllers/ProfileTrainingController.ts @@ -41,7 +41,7 @@ export class ProfileTrainingController extends Controller { const record = await this.trainingHistoryRepo.findBy({ profileTrainingId: trainingId, }); - return record; + return new HttpSuccess(record); } @Post() From 9c79a1104769e9e16d814b535fce4139613bc761 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Tue, 12 Mar 2024 17:07:54 +0700 Subject: [PATCH 2/4] fix: wrong database save --- src/controllers/ProfileInsigniaController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/ProfileInsigniaController.ts b/src/controllers/ProfileInsigniaController.ts index b3316fb9..864e26d0 100644 --- a/src/controllers/ProfileInsigniaController.ts +++ b/src/controllers/ProfileInsigniaController.ts @@ -63,7 +63,7 @@ export class ProfileInsigniaController extends Controller { history.profileInsigniaId = result.id; - await this.insigniaHistoryRepo.save(data); + await this.insigniaHistoryRepo.save(history); return new HttpSuccess(); } From 96b53a4ca550fbee19a049bdf0d5a1c7ef6daa47 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Tue, 12 Mar 2024 17:11:42 +0700 Subject: [PATCH 3/4] chore: add response example --- .../ProfileCertificateController.ts | 61 +++++++++++++ src/controllers/ProfileHonorController.ts | 62 ++++++++++++++ src/controllers/ProfileInsigniaController.ts | 85 +++++++++++++++++++ src/controllers/ProfileTrainingController.ts | 77 +++++++++++++++++ 4 files changed, 285 insertions(+) diff --git a/src/controllers/ProfileCertificateController.ts b/src/controllers/ProfileCertificateController.ts index b7cc239a..d859491c 100644 --- a/src/controllers/ProfileCertificateController.ts +++ b/src/controllers/ProfileCertificateController.ts @@ -2,6 +2,7 @@ import { Body, Controller, Delete, + Example, Get, Patch, Path, @@ -31,12 +32,72 @@ export class ProfileCertificateController extends Controller { private certificateHistoryRepo = AppDataSource.getRepository(ProfileCertificateHistory); @Get("{profileId}") + @Example({ + status: 200, + message: "สำเร็จ", + result: [ + { + id: "e1ef9c3d-079a-40d8-8332-664c3e9a5a70", + createdAt: "2024-03-12T03:02:27.532Z", + createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0", + lastUpdatedAt: "2024-03-12T03:02:27.532Z", + lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0", + createdFullName: "สาวิตรี ศรีสมัย", + lastUpdateFullName: "สาวิตรี ศรีสมัย", + profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", + expireDate: "2024-03-12T10:01:48.000Z", + isActive: true, + issueDate: "2024-03-12T10:01:48.000Z", + certificateNo: "string", + certificateType: "string", + issuer: "string", + }, + ], + }) public async getCertificate(@Path() profileId: string) { const record = await this.certificateRepo.findBy({ profileId }); return new HttpSuccess(record); } @Get("history/{certificateId}") + @Example({ + status: 200, + message: "สำเร็จ", + result: [ + { + id: "c0ecf986-b290-44ca-b45e-f4448cdd34dd", + createdAt: "2024-03-12T03:03:30.169Z", + createdUserId: "00000000-0000-0000-0000-000000000000", + lastUpdatedAt: "2024-03-12T03:03:30.169Z", + lastUpdateUserId: "00000000-0000-0000-0000-000000000000", + createdFullName: "string", + lastUpdateFullName: "สาวิตรี ศรีสมัย", + expireDate: "2024-03-12T10:03:05.000Z", + isActive: true, + issueDate: "2024-03-12T10:03:05.000Z", + certificateNo: "no", + certificateType: "type", + issuer: "issuer", + profileCertificateId: "e1ef9c3d-079a-40d8-8332-664c3e9a5a70", + }, + { + id: "dc4c2800-5fc5-4ec3-b19a-c4a27beac35f", + createdAt: "2024-03-12T03:02:27.583Z", + createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0", + lastUpdatedAt: "2024-03-12T03:02:27.583Z", + lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0", + createdFullName: "สาวิตรี ศรีสมัย", + lastUpdateFullName: "สาวิตรี ศรีสมัย", + expireDate: "2024-03-12T10:01:48.000Z", + isActive: true, + issueDate: "2024-03-12T10:01:48.000Z", + certificateNo: "string", + certificateType: "string", + issuer: "string", + profileCertificateId: "e1ef9c3d-079a-40d8-8332-664c3e9a5a70", + }, + ], + }) public async certificateHistory(@Path() certificateId: string) { const record = await this.certificateHistoryRepo.findBy({ profileCertificateId: certificateId, diff --git a/src/controllers/ProfileHonorController.ts b/src/controllers/ProfileHonorController.ts index 818383e2..b0cf23a6 100644 --- a/src/controllers/ProfileHonorController.ts +++ b/src/controllers/ProfileHonorController.ts @@ -2,6 +2,7 @@ import { Body, Controller, Delete, + Example, Get, Patch, Path, @@ -27,12 +28,73 @@ export class ProfileHonorController extends Controller { private honorHistoryRepo = AppDataSource.getRepository(ProfileHonorHistory); @Get("{profileId}") + @Example({ + status: 200, + message: "สำเร็จ", + result: [ + { + id: "debfa8a7-83fb-4801-a940-8ae74e7638d3", + createdAt: "2024-03-12T03:10:05.594Z", + createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0", + lastUpdatedAt: "2024-03-12T03:10:05.594Z", + lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0", + createdFullName: "สาวิตรี ศรีสมัย", + lastUpdateFullName: "สาวิตรี ศรีสมัย", + profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", + isActive: true, + detail: "string", + issueDate: "2024-03-12T10:09:47.000Z", + issuer: "string", + refCommandDate: "2024-03-12T10:09:47.000Z", + refCommandNo: "string", + isDate: true, + }, + ], + }) public async getHonor(@Path() profileId: string) { const record = await this.honorRepo.findBy({ profileId }); return new HttpSuccess(record); } @Get("history/{honorId}") + @Example({ + status: 200, + message: "สำเร็จ", + result: [ + { + id: "3bedb365-4a41-4df5-8f47-b6e143221d2c", + createdAt: "2024-03-12T03:11:01.395Z", + createdUserId: "00000000-0000-0000-0000-000000000000", + lastUpdatedAt: "2024-03-12T03:11:01.395Z", + lastUpdateUserId: "00000000-0000-0000-0000-000000000000", + createdFullName: "string", + lastUpdateFullName: "สาวิตรี ศรีสมัย", + isActive: true, + detail: "detail", + issueDate: "2024-03-12T10:10:31.000Z", + issuer: "issuer", + refCommandDate: "2024-03-12T10:10:31.000Z", + refCommandNo: "refCommandNo", + profileHonorId: "debfa8a7-83fb-4801-a940-8ae74e7638d3", + }, + { + id: "ba0e2f82-014e-46c6-8b82-a7c28eb5325f", + createdAt: "2024-03-12T03:10:05.657Z", + createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0", + lastUpdatedAt: "2024-03-12T03:10:05.657Z", + lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0", + createdFullName: "สาวิตรี ศรีสมัย", + lastUpdateFullName: "สาวิตรี ศรีสมัย", + isActive: true, + detail: "string", + issueDate: "2024-03-12T10:09:47.000Z", + issuer: "string", + refCommandDate: "2024-03-12T10:09:47.000Z", + refCommandNo: "string", + profileHonorId: "debfa8a7-83fb-4801-a940-8ae74e7638d3", + }, + ], + }) public async honorHistory(@Path() honorId: string) { const record = await this.honorHistoryRepo.findBy({ profileHonorId: honorId, diff --git a/src/controllers/ProfileInsigniaController.ts b/src/controllers/ProfileInsigniaController.ts index 864e26d0..5e659265 100644 --- a/src/controllers/ProfileInsigniaController.ts +++ b/src/controllers/ProfileInsigniaController.ts @@ -2,6 +2,7 @@ import { Body, Controller, Delete, + Example, Get, Patch, Path, @@ -31,12 +32,96 @@ export class ProfileInsigniaController extends Controller { private insigniaHistoryRepo = AppDataSource.getRepository(ProfileInsigniaHistory); @Get("{profileId}") + @Example({ + status: 200, + message: "สำเร็จ", + result: [ + { + id: "c9d4dd52-25f5-491a-852d-28bfe00d66cb", + createdAt: "2024-03-12T03:05:09.393Z", + createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0", + lastUpdatedAt: "2024-03-12T03:05:09.393Z", + lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0", + createdFullName: "สาวิตรี ศรีสมัย", + lastUpdateFullName: "สาวิตรี ศรีสมัย", + profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", + isActive: true, + year: 0, + no: "string", + volume: "string", + section: "string", + page: "string", + receiveDate: "2024-03-12T10:05:02.000Z", + insigniaId: "string", + insigniaType: "string", + dateAnnounce: "2024-03-12T10:05:02.000Z", + issue: "string", + volumeNo: "string", + refCommandDate: "2024-03-12T10:05:02.000Z", + refCommandNo: "string", + }, + ], + }) public async getInsignia(@Path() profileId: string) { const record = await this.insigniaRepo.findBy({ profileId }); return new HttpSuccess(record); } @Get("history/{InsigniaId}") + @Example({ + status: 200, + message: "สำเร็จ", + result: [ + { + id: "c363d13c-88bd-4954-adf5-70d3f5ca9c30", + createdAt: "2024-03-12T03:06:31.062Z", + createdUserId: "00000000-0000-0000-0000-000000000000", + lastUpdatedAt: "2024-03-12T03:06:31.062Z", + lastUpdateUserId: "00000000-0000-0000-0000-000000000000", + createdFullName: "string", + lastUpdateFullName: "สาวิตรี ศรีสมัย", + isActive: true, + year: 0, + no: "no", + volume: "volume", + section: "section", + page: "page", + receiveDate: "2024-03-12T10:05:44.000Z", + insigniaId: "insigniaId", + insigniaType: "insigniaType", + dateAnnounce: "2024-03-12T10:05:44.000Z", + issue: "string", + volumeNo: "volumeNo", + refCommandDate: "2024-03-12T10:05:44.000Z", + refCommandNo: "refCommandNo", + profileInsigniaId: "c9d4dd52-25f5-491a-852d-28bfe00d66cb", + }, + { + id: "c9d4dd52-25f5-491a-852d-28bfe00d66cb", + createdAt: "2024-03-12T03:05:09.393Z", + createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0", + lastUpdatedAt: "2024-03-12T03:09:04.905Z", + lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0", + createdFullName: "สาวิตรี ศรีสมัย", + lastUpdateFullName: "สาวิตรี ศรีสมัย", + isActive: true, + year: 0, + no: "string", + volume: "string", + section: "string", + page: "string", + receiveDate: "2024-03-12T10:05:02.000Z", + insigniaId: "string", + insigniaType: "string", + dateAnnounce: "2024-03-12T10:05:02.000Z", + issue: "string", + volumeNo: "string", + refCommandDate: "2024-03-12T10:05:02.000Z", + refCommandNo: "string", + profileInsigniaId: "c9d4dd52-25f5-491a-852d-28bfe00d66cb", + }, + ], + }) public async getInsigniaHistory(@Path() InsigniaId: string) { const record = await this.insigniaHistoryRepo.findBy({ profileInsigniaId: InsigniaId, diff --git a/src/controllers/ProfileTrainingController.ts b/src/controllers/ProfileTrainingController.ts index f3b53608..a2c6f457 100644 --- a/src/controllers/ProfileTrainingController.ts +++ b/src/controllers/ProfileTrainingController.ts @@ -2,6 +2,7 @@ import { Body, Controller, Delete, + Example, Get, Patch, Path, @@ -31,12 +32,88 @@ export class ProfileTrainingController extends Controller { private trainingHistoryRepo = AppDataSource.getRepository(ProfileTrainingHistory); @Get("{profileId}") + @Example({ + status: 200, + message: "สำเร็จ", + result: [ + { + id: "3cf02fb7-2f0c-471b-b641-51d557375c0a", + createdAt: "2024-03-12T02:55:56.915Z", + createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0", + lastUpdatedAt: "2024-03-12T02:55:56.915Z", + lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0", + createdFullName: "สาวิตรี ศรีสมัย", + lastUpdateFullName: "สาวิตรี ศรีสมัย", + profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", + isActive: true, + startDate: "2024-03-12T09:55:23.000Z", + endDate: "2024-03-12T09:55:23.000Z", + numberOrder: "string", + topic: "string", + place: "string", + dateOrder: "2024-03-12T09:55:23.000Z", + department: "string", + duration: "string", + name: "string", + yearly: 0, + isDate: true, + }, + ], + }) public async getTraining(@Path() profileId: string) { const record = await this.trainingRepo.findBy({ profileId }); return new HttpSuccess(record); } @Get("history/{trainingId}") + @Example({ + status: 200, + message: "สำเร็จ", + result: [ + { + id: "6d4e9dbe-8697-4546-9651-0a1c3ea0a82d", + createdAt: "2024-03-12T02:55:56.971Z", + createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0", + lastUpdatedAt: "2024-03-12T02:55:56.971Z", + lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0", + createdFullName: "สาวิตรี ศรีสมัย", + lastUpdateFullName: "สาวิตรี ศรีสมัย", + isActive: true, + startDate: "2024-03-12T09:55:23.000Z", + endDate: "2024-03-12T09:55:23.000Z", + numberOrder: "string", + topic: "string", + place: "string", + dateOrder: "2024-03-12T09:55:23.000Z", + department: "string", + duration: "string", + name: "string", + yearly: 0, + profileTrainingId: "3cf02fb7-2f0c-471b-b641-51d557375c0a", + }, + { + id: "a251c176-3dac-4d09-9813-38c8db1127e3", + createdAt: "2024-03-12T02:58:17.917Z", + createdUserId: "00000000-0000-0000-0000-000000000000", + lastUpdatedAt: "2024-03-12T02:58:17.917Z", + lastUpdateUserId: "00000000-0000-0000-0000-000000000000", + createdFullName: "string", + lastUpdateFullName: "สาวิตรี ศรีสมัย", + isActive: true, + startDate: "2024-03-12T09:57:44.000Z", + endDate: "2024-03-12T09:57:44.000Z", + numberOrder: "string", + topic: "topic", + place: "place", + dateOrder: "2024-03-12T09:57:44.000Z", + department: "department", + duration: "string", + name: "name", + yearly: 0, + profileTrainingId: "3cf02fb7-2f0c-471b-b641-51d557375c0a", + }, + ], + }) public async trainingHistory(@Path() trainingId: string) { const record = await this.trainingHistoryRepo.findBy({ profileTrainingId: trainingId, From 6e7086c0857dfec98e24ed274a8ed346a18f01d3 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Tue, 12 Mar 2024 17:17:16 +0700 Subject: [PATCH 4/4] feat: check if profile exists --- src/controllers/ProfileCertificateController.ts | 12 ++++++++++++ src/controllers/ProfileHonorController.ts | 12 ++++++++++++ src/controllers/ProfileInsigniaController.ts | 12 ++++++++++++ src/controllers/ProfileTrainingController.ts | 12 ++++++++++++ 4 files changed, 48 insertions(+) diff --git a/src/controllers/ProfileCertificateController.ts b/src/controllers/ProfileCertificateController.ts index d859491c..18ed3f3e 100644 --- a/src/controllers/ProfileCertificateController.ts +++ b/src/controllers/ProfileCertificateController.ts @@ -23,11 +23,13 @@ import HttpStatus from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; import { ProfileCertificateHistory } from "../entities/ProfileCertificateHistory"; import { RequestWithUser } from "../middlewares/user"; +import { Profile } from "../entities/Profile"; @Route("api/v1/org/profile/certificate") @Tags("ProfileCertificate") @Security("bearerAuth") export class ProfileCertificateController extends Controller { + private profileRepo = AppDataSource.getRepository(Profile); private certificateRepo = AppDataSource.getRepository(ProfileCertificate); private certificateHistoryRepo = AppDataSource.getRepository(ProfileCertificateHistory); @@ -110,6 +112,16 @@ export class ProfileCertificateController extends Controller { @Request() req: RequestWithUser, @Body() body: CreateProfileCertificate, ) { + if (!body.profileId) { + throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); + } + + const profile = await this.profileRepo.findOneBy({ id: body.profileId }); + + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const data = new ProfileCertificate(); const history = new ProfileCertificateHistory(); diff --git a/src/controllers/ProfileHonorController.ts b/src/controllers/ProfileHonorController.ts index b0cf23a6..1cf305b2 100644 --- a/src/controllers/ProfileHonorController.ts +++ b/src/controllers/ProfileHonorController.ts @@ -19,11 +19,13 @@ import HttpStatus from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; import { ProfileHonorHistory } from "../entities/ProfileHonorHistory"; import { RequestWithUser } from "../middlewares/user"; +import { Profile } from "../entities/Profile"; @Route("api/v1/org/profile/honor") @Tags("ProfileHonor") @Security("bearerAuth") export class ProfileHonorController extends Controller { + private profileRepo = AppDataSource.getRepository(Profile); private honorRepo = AppDataSource.getRepository(ProfileHonor); private honorHistoryRepo = AppDataSource.getRepository(ProfileHonorHistory); @@ -104,6 +106,16 @@ export class ProfileHonorController extends Controller { @Post() public async newHonor(@Request() req: RequestWithUser, @Body() body: CreateProfileHonor) { + if (!body.profileId) { + throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); + } + + const profile = await this.profileRepo.findOneBy({ id: body.profileId }); + + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const data = new ProfileHonor(); const history = new ProfileHonorHistory(); diff --git a/src/controllers/ProfileInsigniaController.ts b/src/controllers/ProfileInsigniaController.ts index 5e659265..d05ef9f7 100644 --- a/src/controllers/ProfileInsigniaController.ts +++ b/src/controllers/ProfileInsigniaController.ts @@ -23,11 +23,13 @@ import HttpStatus from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; import { ProfileInsigniaHistory } from "../entities/ProfileInsigniaHistory"; import { RequestWithUser } from "../middlewares/user"; +import { Profile } from "../entities/Profile"; @Route("api/v1/org/profile/insignia") @Tags("ProfileInsignia") @Security("bearerAuth") export class ProfileInsigniaController extends Controller { + private profileRepo = AppDataSource.getRepository(Profile); private insigniaRepo = AppDataSource.getRepository(ProfileInsignia); private insigniaHistoryRepo = AppDataSource.getRepository(ProfileInsigniaHistory); @@ -131,6 +133,16 @@ export class ProfileInsigniaController extends Controller { @Post() public async newInsignia(@Request() req: RequestWithUser, @Body() body: CreateProfileInsignia) { + if (!body.profileId) { + throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); + } + + const profile = await this.profileRepo.findOneBy({ id: body.profileId }); + + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const data = new ProfileInsignia(); const history = new ProfileInsigniaHistory(); diff --git a/src/controllers/ProfileTrainingController.ts b/src/controllers/ProfileTrainingController.ts index a2c6f457..32a1a123 100644 --- a/src/controllers/ProfileTrainingController.ts +++ b/src/controllers/ProfileTrainingController.ts @@ -23,11 +23,13 @@ import HttpStatus from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; import { ProfileTrainingHistory } from "../entities/ProfileTrainingHistory"; import { RequestWithUser } from "../middlewares/user"; +import { Profile } from "../entities/Profile"; @Route("api/v1/org/profile/training") @Tags("ProfileTraining") @Security("bearerAuth") export class ProfileTrainingController extends Controller { + private profileRepo = AppDataSource.getRepository(Profile); private trainingRepo = AppDataSource.getRepository(ProfileTraining); private trainingHistoryRepo = AppDataSource.getRepository(ProfileTrainingHistory); @@ -123,6 +125,16 @@ export class ProfileTrainingController extends Controller { @Post() public async newTraining(@Request() req: RequestWithUser, @Body() body: CreateProfileTraining) { + if (!body.profileId) { + throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); + } + + const profile = await this.profileRepo.findOneBy({ id: body.profileId }); + + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const data = new ProfileTraining(); const history = new ProfileTrainingHistory();