change endPoint
This commit is contained in:
parent
5ca15d5433
commit
5812f9e56d
3 changed files with 75 additions and 6 deletions
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue