change endPoint

This commit is contained in:
Bright 2024-06-21 17:56:31 +07:00
parent 5ca15d5433
commit 5812f9e56d
3 changed files with 75 additions and 6 deletions

View file

@ -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();
}
}

View file

@ -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();
}
}

View file

@ -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 = {