From e374f2e339131deb6e523747bfbae50fb36d2fc3 Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Wed, 20 May 2026 20:40:09 +0700 Subject: [PATCH] fixed service crash --- src/controllers/AuthRoleController.ts | 8 +-- src/controllers/CommandOperatorController.ts | 51 +++++++------------- src/controllers/OrganizationController.ts | 2 + src/services/PositionService.ts | 1 + 4 files changed, 25 insertions(+), 37 deletions(-) diff --git a/src/controllers/AuthRoleController.ts b/src/controllers/AuthRoleController.ts index 7cbc387d..13f5ce04 100644 --- a/src/controllers/AuthRoleController.ts +++ b/src/controllers/AuthRoleController.ts @@ -130,12 +130,12 @@ export class AuthRoleController extends Controller { port: REDIS_PORT, }); - redisClient.del("role_" + posMaster.current_holderId, (err: Error, response: Response) => { - if (err) throw err; + redisClient.del("role_" + posMaster.current_holderId, (err: Error) => { + if (err) console.error("Redis delete role error:", err); }); - redisClient.del("menu_" + posMaster.current_holderId, (err: Error, response: Response) => { - if (err) throw err; + redisClient.del("menu_" + posMaster.current_holderId, (err: Error) => { + if (err) console.error("Redis delete menu error:", err); }); } finally { if (redisClient) { diff --git a/src/controllers/CommandOperatorController.ts b/src/controllers/CommandOperatorController.ts index 1a461ab3..18393f53 100644 --- a/src/controllers/CommandOperatorController.ts +++ b/src/controllers/CommandOperatorController.ts @@ -9,7 +9,7 @@ import { Path, Request, Response, - Get + Get, } from "tsoa"; import { LessThan, MoreThan } from "typeorm"; import { AppDataSource } from "../database/data-source"; @@ -37,9 +37,7 @@ export class CommandOperatorController extends Controller { * @param commandId คีย์คำสั่ง */ @Get("{commandId}") - async getCommandOperatorByCommandId( - @Path() commandId: string - ) { + async getCommandOperatorByCommandId(@Path() commandId: string) { const command = await this.commandRepo.findOne({ where: { id: commandId }, select: { id: true }, @@ -61,10 +59,7 @@ export class CommandOperatorController extends Controller { * @param operatorId คีย์เจ้าหน้าที่ดำเนินการ */ @Get("swap/{direction}/{operatorId}") - async swapCommandOperator( - @Path() direction: string, - @Path() operatorId: string, - ) { + async swapCommandOperator(@Path() direction: string, @Path() operatorId: string) { const source = await this.commandOperatorRepo.findOne({ where: { id: operatorId }, }); @@ -106,10 +101,7 @@ export class CommandOperatorController extends Controller { source.orderNo = dest.orderNo; dest.orderNo = temp; - await Promise.all([ - this.commandOperatorRepo.save(source), - this.commandOperatorRepo.save(dest), - ]); + await Promise.all([this.commandOperatorRepo.save(source), this.commandOperatorRepo.save(dest)]); return new HttpSuccess(); } @@ -141,35 +133,29 @@ export class CommandOperatorController extends Controller { const nextOrderNo = (lastOrderNo?.orderNo ?? 1) + 1; const now = new Date(); - const operator = Object.assign( - new CommandOperator(), - { - ...body, - commandId: command.id, - orderNo: nextOrderNo, - createdUserId: request.user.sub, - createdFullName: request.user.name, - createdAt: now, - lastUpdateUserId: request.user.sub, - lastUpdateFullName: request.user.name, - lastUpdatedAt: now, - } - ); + const operator = Object.assign(new CommandOperator(), { + ...body, + commandId: command.id, + orderNo: nextOrderNo, + createdUserId: request.user.sub, + createdFullName: request.user.name, + createdAt: now, + lastUpdateUserId: request.user.sub, + lastUpdateFullName: request.user.name, + lastUpdatedAt: now, + }); await this.commandOperatorRepo.save(operator); return new HttpSuccess(); } - /** + /** * API ลบเจ้าหน้าที่ดำเนินการที่คำสั่ง * @summary API ลบเจ้าหน้าที่ดำเนินการที่คำสั่ง * @param commandId คีย์คำสั่ง * @param operatorId คีย์เจ้าหน้าที่ดำเนินการ */ @Delete("{commandId}/{operatorId}") - public async deleteCommandOperator( - @Path() commandId: string, - @Path() operatorId: string, - ) { + public async deleteCommandOperator(@Path() commandId: string, @Path() operatorId: string) { const queryRunner = AppDataSource.createQueryRunner(); await queryRunner.connect(); await queryRunner.startTransaction(); @@ -215,10 +201,9 @@ export class CommandOperatorController extends Controller { return new HttpSuccess(true); } catch (error) { await queryRunner.rollbackTransaction(); - throw error; + console.error("Delete command operator error:", error); } finally { await queryRunner.release(); } } - } diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index 960b4815..e107df5c 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -214,6 +214,7 @@ export class OrganizationController extends Controller { await sendToQueueOrgDraft(msg); return new HttpSuccess("Draft is being created... Processing in the background."); } catch (error: any) { + console.error("Error creating draft organization:", error); throw error; } } @@ -2529,6 +2530,7 @@ export class OrganizationController extends Controller { await sendToQueueOrg(msg); return new HttpSuccess(); } catch (error: any) { + console.error("Error publishing draft organization:", error); throw error; } } diff --git a/src/services/PositionService.ts b/src/services/PositionService.ts index 29bb168a..b6514eca 100644 --- a/src/services/PositionService.ts +++ b/src/services/PositionService.ts @@ -188,6 +188,7 @@ export async function CreatePosMasterHistoryOfficer( return true; } catch (err) { if (manager) { + console.error("CreatePosMasterHistoryOfficer error (external transaction):", err); throw err; } console.error("CreatePosMasterHistoryOfficer transaction error:", err);