From 0fcfcdf790da334e19da251994de4bc57b4ec8cf Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 13 Mar 2024 18:20:16 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=88=E0=B8=B1=E0=B8=94=E0=B8=A5=E0=B8=B3?= =?UTF-8?q?=E0=B8=94=E0=B8=B1=E0=B8=9A=E0=B9=81=E0=B8=AA=E0=B8=94=E0=B8=87?= =?UTF-8?q?=E0=B8=9C=E0=B8=A5=E0=B9=80=E0=B8=84=E0=B8=A3=E0=B8=B7=E0=B9=88?= =?UTF-8?q?=E0=B8=AD=E0=B8=87=E0=B8=A3=E0=B8=B2=E0=B8=8A=E0=B8=AD=E0=B8=B4?= =?UTF-8?q?=E0=B8=AA=E0=B8=A3=E0=B8=B4=E0=B8=A2=E0=B8=B2=E0=B8=A0=E0=B8=A3?= =?UTF-8?q?=E0=B8=93=E0=B9=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/InsigniaController.ts | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/controllers/InsigniaController.ts b/src/controllers/InsigniaController.ts index 8e3a49db..c1355f2d 100644 --- a/src/controllers/InsigniaController.ts +++ b/src/controllers/InsigniaController.ts @@ -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(); + } }