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