From eabd1c4ac7f640ba749c3b58f9a346d24e090095 Mon Sep 17 00:00:00 2001 From: kittapath Date: Fri, 27 Sep 2024 10:12:54 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=97=E0=B8=B3=E0=B8=AA=E0=B8=B3=E0=B9=80?= =?UTF-8?q?=E0=B8=99=E0=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 56 +++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 87d5f4e6..1a3a3edb 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -616,12 +616,15 @@ export class CommandController extends Controller { requestBody: { commandNo?: string | null; commandYear?: number | null }, @Request() request: RequestWithUser, ) { - const command = await this.commandRepository.findOne({ where: { id: id } }); + const command = await this.commandRepository.findOne({ + where: { id: id }, + }); if (!command) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้"); } const copy = new Command(); Object.assign(copy, { ...command, ...requestBody, id: undefined }); + copy.status = "NEW"; copy.createdUserId = request.user.sub; copy.createdFullName = request.user.name; copy.createdAt = new Date(); @@ -629,6 +632,57 @@ export class CommandController extends Controller { copy.lastUpdateFullName = request.user.name; copy.lastUpdatedAt = new Date(); await this.commandRepository.save(copy); + + const commandRecives = await this.commandReciveRepository.find({ + where: { commandId: id }, + }); + const commandSends = await this.commandSendRepository.find({ + where: { commandId: id }, + }); + const commandSendCCs = await this.commandSendCCRepository.find({ + where: { commandSendId: In(commandSends.map((x) => x.id)) }, + }); + commandRecives.map((x: any) => { + delete x.id; + return { + ...x, + createdUserId: request.user.sub, + createdFullName: request.user.name, + createdAt: new Date(), + lastUpdateUserId: request.user.sub, + lastUpdateFullName: request.user.name, + lastUpdatedAt: new Date(), + }; + }); + await this.commandRepository.save(commandRecives); + + commandSends.map((x: any) => { + delete x.id; + return { + ...x, + createdUserId: request.user.sub, + createdFullName: request.user.name, + createdAt: new Date(), + lastUpdateUserId: request.user.sub, + lastUpdateFullName: request.user.name, + lastUpdatedAt: new Date(), + }; + }); + await this.commandRepository.save(commandSends); + + commandSendCCs.map((x: any) => { + delete x.id; + return { + ...x, + createdUserId: request.user.sub, + createdFullName: request.user.name, + createdAt: new Date(), + lastUpdateUserId: request.user.sub, + lastUpdateFullName: request.user.name, + lastUpdatedAt: new Date(), + }; + }); + await this.commandRepository.save(commandSendCCs); return new HttpSuccess(copy.id); }