จัดลำดับแสดงผลเครื่องราชอิสริยาภรณ์

This commit is contained in:
Bright 2024-03-13 18:20:16 +07:00
parent 806fb21c61
commit 0fcfcdf790

View file

@ -197,4 +197,37 @@ export class InsigniaController extends Controller {
}));
return new HttpSuccess(mapInsigniaAll);
}
/**
* API
*
* @summary ORG_038 - (ADMIN) #
*
*/
@Post("sort")
async Sort(@Body() requestBody: { insigniaTypeId: string; sortId: string[] }) {
const insigniaType = await this.insigniaTypeRepository.findOne({
where: { id: requestBody.insigniaTypeId }
});
if (!insigniaType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลลำดับเครื่องราชอิสริยาภรณ์นี้");
}
const insignia = await this.insigniaRepository.find({
select: ["id", "level"],
where: { insigniaTypeId: requestBody.insigniaTypeId }
});
if (!insignia) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชอิสริยาภรณ์นี้");
}
const sortLevel = insignia.map((data) => ({
id: data.id,
level: requestBody.sortId.indexOf(data.id) + 1,
}));
await this.insigniaRepository.save(sortLevel);
return new HttpSuccess();
}
}