From 5812f9e56d1c317d4c48c4832669a97128dc444c Mon Sep 17 00:00:00 2001 From: Bright Date: Fri, 21 Jun 2024 17:56:31 +0700 Subject: [PATCH] change endPoint --- src/controllers/ProfileInsigniaController.ts | 35 ++++++++++++++++++++ src/controllers/ProfileLeaveController.ts | 34 +++++++++++++++++++ src/entities/ProfileChildren.ts | 12 +++---- 3 files changed, 75 insertions(+), 6 deletions(-) diff --git a/src/controllers/ProfileInsigniaController.ts b/src/controllers/ProfileInsigniaController.ts index 2f4f06db..7b71e203 100644 --- a/src/controllers/ProfileInsigniaController.ts +++ b/src/controllers/ProfileInsigniaController.ts @@ -243,4 +243,39 @@ export class ProfileInsigniaController extends Controller { return new HttpSuccess(); } + + @Post("dump-db") + public async newInsigniaDumpDB(@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 insignia = await this.insigniaMetaRepo.findOne({ + where: { name: body.insigniaId }, + }); + if (!insignia) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชฯ นี้"); + } + + const data = new ProfileInsignia(); + + const meta = { + createdUserId: req.user.sub, + createdFullName: req.user.name, + lastUpdateUserId: req.user.sub, + lastUpdateFullName: req.user.name, + }; + + Object.assign(data, { ...body, ...meta }); + data.insigniaId = insignia.id + await this.insigniaRepo.save(data); + + return new HttpSuccess(); + } } diff --git a/src/controllers/ProfileLeaveController.ts b/src/controllers/ProfileLeaveController.ts index 67cd4c0b..8ff61a61 100644 --- a/src/controllers/ProfileLeaveController.ts +++ b/src/controllers/ProfileLeaveController.ts @@ -324,4 +324,38 @@ export class ProfileLeaveController extends Controller { return new HttpSuccess(); } + + @Post("dump-db") + public async newLeaveDumpDB(@Request() req: RequestWithUser, @Body() body: CreateProfileLeave) { + 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 leaveType = await this.leaveTypeRepository.findOne({ + where: { name: body.leaveTypeId } + }); + if (!leaveType) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทลานี้"); + } + + const data = new ProfileLeave(); + + const meta = { + createdUserId: req.user.sub, + createdFullName: req.user.name, + lastUpdateUserId: req.user.sub, + lastUpdateFullName: req.user.name, + }; + + Object.assign(data, { ...body, ...meta }); + data.leaveTypeId = leaveType.id; + await this.leaveRepo.save(data); + + return new HttpSuccess(); + } } diff --git a/src/entities/ProfileChildren.ts b/src/entities/ProfileChildren.ts index c277713e..50cb5c8f 100644 --- a/src/entities/ProfileChildren.ts +++ b/src/entities/ProfileChildren.ts @@ -86,12 +86,12 @@ export class ProfileChildren extends EntityBase { export type CreateProfileChildren = { profileId: string; - childrenCareer: string; - childrenFirstName: string; - childrenLastName: string; - childrenPrefix: string; - childrenLive: boolean; - childrenCitizenId: string; + childrenCareer: string | null; + childrenFirstName: string | null; + childrenLastName: string | null; + childrenPrefix: string | null; + childrenLive: boolean | null; + childrenCitizenId: string | null; }; export type CreateProfileChildrenEmployee = {