diff --git a/src/controllers/ProfileCertificateController.ts b/src/controllers/ProfileCertificateController.ts index b4e17a21..18ed3f3e 100644 --- a/src/controllers/ProfileCertificateController.ts +++ b/src/controllers/ProfileCertificateController.ts @@ -2,6 +2,7 @@ import { Body, Controller, Delete, + Example, Get, Patch, Path, @@ -22,26 +23,88 @@ 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); @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, }); - return record; + return new HttpSuccess(record); } @Post() @@ -49,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 f5e34158..1cf305b2 100644 --- a/src/controllers/ProfileHonorController.ts +++ b/src/controllers/ProfileHonorController.ts @@ -2,6 +2,7 @@ import { Body, Controller, Delete, + Example, Get, Patch, Path, @@ -18,30 +19,103 @@ 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); @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, }); - return record; + return new HttpSuccess(record); } @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 a24c6730..d05ef9f7 100644 --- a/src/controllers/ProfileInsigniaController.ts +++ b/src/controllers/ProfileInsigniaController.ts @@ -2,6 +2,7 @@ import { Body, Controller, Delete, + Example, Get, Patch, Path, @@ -22,30 +23,126 @@ 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); @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, }); - return record; + return new HttpSuccess(record); } @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(); @@ -63,7 +160,7 @@ export class ProfileInsigniaController extends Controller { history.profileInsigniaId = result.id; - await this.insigniaHistoryRepo.save(data); + await this.insigniaHistoryRepo.save(history); return new HttpSuccess(); } diff --git a/src/controllers/ProfileTrainingController.ts b/src/controllers/ProfileTrainingController.ts index e5a02183..32a1a123 100644 --- a/src/controllers/ProfileTrainingController.ts +++ b/src/controllers/ProfileTrainingController.ts @@ -2,6 +2,7 @@ import { Body, Controller, Delete, + Example, Get, Patch, Path, @@ -22,30 +23,118 @@ 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); @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, }); - return record; + return new HttpSuccess(record); } @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();