From a1e5bf6f5b999a6e719c33284da35a9d92fcd861 Mon Sep 17 00:00:00 2001 From: Bright Date: Mon, 19 Feb 2024 17:22:05 +0700 Subject: [PATCH] comment try catch --- src/controllers/PosLevelController.ts | 40 ++++++++++----------- src/controllers/PosTypeController.ts | 40 ++++++++++----------- src/controllers/SalaryController.ts | 48 ++++++++++++------------- src/controllers/SalaryRankController.ts | 24 ++++++------- 4 files changed, 76 insertions(+), 76 deletions(-) diff --git a/src/controllers/PosLevelController.ts b/src/controllers/PosLevelController.ts index 145786b..7a80df9 100644 --- a/src/controllers/PosLevelController.ts +++ b/src/controllers/PosLevelController.ts @@ -85,16 +85,16 @@ export class PosLevelController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. posLevelAuthority"); } - try { + // try { posLevel.createdUserId = request.user.sub; posLevel.createdFullName = request.user.name; posLevel.lastUpdateUserId = request.user.sub; posLevel.lastUpdateFullName = request.user.name; await this.posLevelRepository.save(posLevel); return new HttpSuccess(posLevel); - } catch (error) { - return error; - } + // } catch (error) { + // return error; + // } } /** @@ -144,15 +144,15 @@ export class PosLevelController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. posLevelAuthority"); } - try { + // try { posLevel.lastUpdateUserId = request.user.sub; posLevel.lastUpdateFullName = request.user.name; this.posLevelRepository.merge(posLevel, requestBody); await this.posLevelRepository.save(posLevel); return new HttpSuccess(posLevel.id); - } catch (error) { - return error; - } + // } catch (error) { + // return error; + // } } /** @@ -168,12 +168,12 @@ export class PosLevelController extends Controller { if (!delPosLevel) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id); } - try { + // try { await this.posLevelRepository.remove(delPosLevel); return new HttpSuccess(); - } catch (error) { - return error; - } + // } catch (error) { + // return error; + // } } /** @@ -198,7 +198,7 @@ export class PosLevelController extends Controller { }, ) async GetLevelDetail(@Path() id: string) { - try { + // try { const getPosType = await this.posLevelRepository.findOne({ select: ["id", "posLevelName", "posLevelRank", "posLevelAuthority"], relations: ["posType"], @@ -221,9 +221,9 @@ export class PosLevelController extends Controller { } return new HttpSuccess(mapPosLevel); - } catch (error) { - return error; - } + // } catch (error) { + // return error; + // } } /** @@ -247,7 +247,7 @@ export class PosLevelController extends Controller { }, ]) async GetPosLevel() { - try { + // try { const posLevel = await this.posLevelRepository.find({ select: ["id", "posLevelName", "posLevelRank", "posLevelAuthority", "posTypeId"], relations: ["posType"], @@ -267,8 +267,8 @@ export class PosLevelController extends Controller { } })); return new HttpSuccess(mapPosLevel); - } catch (error) { - return error; - } + // } catch (error) { + // return error; + // } } } diff --git a/src/controllers/PosTypeController.ts b/src/controllers/PosTypeController.ts index 7a8fce4..ff63517 100644 --- a/src/controllers/PosTypeController.ts +++ b/src/controllers/PosTypeController.ts @@ -66,16 +66,16 @@ export class PosTypeController extends Controller { if(chkPosTypeName){ throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อประเภทตำแหน่ง: " + requestBody.posTypeName + " มีอยู่ในระบบแล้ว"); } - try { + // try { posType.createdUserId = request.user.sub; posType.createdFullName = request.user.name; posType.lastUpdateUserId = request.user.sub; posType.lastUpdateFullName = request.user.name; await this.posTypeRepository.save(posType); return new HttpSuccess(posType); - } catch (error) { - return error; - } + // } catch (error) { + // return error; + // } } /** @@ -108,15 +108,15 @@ export class PosTypeController extends Controller { if(chkPosTypeName){ throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อประเภทตำแหน่ง: " + requestBody.posTypeName + " มีอยู่ในระบบแล้ว"); } - try { + // try { posType.lastUpdateUserId = request.user.sub; posType.lastUpdateFullName = request.user.name; this.posTypeRepository.merge(posType, requestBody); await this.posTypeRepository.save(posType); return new HttpSuccess(posType.id); - } catch (error) { - return error; - } + // } catch (error) { + // return error; + // } } /** @@ -139,12 +139,12 @@ export class PosTypeController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้ เนื่องจาก id ผูกกับ posLevel",); } - try { + // try { await this.posTypeRepository.remove(delPosType); return new HttpSuccess(); - } catch (error) { - return error; - } + // } catch (error) { + // return error; + // } } /** @@ -171,7 +171,7 @@ export class PosTypeController extends Controller { }, ]) async GetTypeDetail(@Path() id: string) { - try { + // try { const getPosType = await this.posTypeRepository.findOne({ select: ["id", "posTypeName", "posTypeRank"], relations: ["posLevels"], @@ -194,9 +194,9 @@ export class PosTypeController extends Controller { } return new HttpSuccess(mapGetPosType); - } catch (error) { - return error; - } + // } catch (error) { + // return error; + // } } /** @@ -222,7 +222,7 @@ export class PosTypeController extends Controller { }, ]) async GetPosType() { - try { + // try { const posType = await this.posTypeRepository.find({ select: ["id", "posTypeName", "posTypeRank"], relations: ["posLevels"], @@ -242,8 +242,8 @@ export class PosTypeController extends Controller { })), })); return new HttpSuccess(mapPosType); - } catch (error) { - return error; - } + // } catch (error) { + // return error; + // } } } diff --git a/src/controllers/SalaryController.ts b/src/controllers/SalaryController.ts index d17673f..f801cd2 100644 --- a/src/controllers/SalaryController.ts +++ b/src/controllers/SalaryController.ts @@ -56,7 +56,7 @@ export class Salary extends Controller { @Body() requestBody: CreateSalary, @Request() request: { user: Record }, ) { - try { + // try { const salarys = Object.assign(new Salarys(), requestBody); if (!salarys) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); @@ -98,9 +98,9 @@ export class Salary extends Controller { salarys.lastUpdateFullName = request.user.name; await this.salaryRepository.save(salarys); return new HttpSuccess(salarys.id); - } catch (error: any) { - throw new Error(error); - } + // } catch (error: any) { + // throw new Error(error); + // } } /** @@ -126,7 +126,7 @@ export class Salary extends Controller { @Body() requestBody: UpdateSalary, @Request() request: { user: Record }, ) { - try { + // try { const chk_Salary = await this.salaryRepository.findOne({ where: { id: id }, }); @@ -184,9 +184,9 @@ export class Salary extends Controller { this.salaryRepository.merge(chk_Salary, requestBody); await this.salaryRepository.save(chk_Salary); return new HttpSuccess(id); - } catch (error: any) { - throw new Error(error); - } + // } catch (error: any) { + // throw new Error(error); + // } } /** @@ -198,7 +198,7 @@ export class Salary extends Controller { */ @Delete("{id}") async delete_salary(@Path() id: string) { - try { + // try { const chk_Salary = await this.salaryRepository.findOne({ where: { id: id }, }); @@ -218,9 +218,9 @@ export class Salary extends Controller { await this.salaryRankRepository.remove(del_SalaryRank); await this.salaryRepository.remove(chk_Salary); return new HttpSuccess(); - } catch (error: any) { - throw new Error(error); - } + // } catch (error: any) { + // throw new Error(error); + // } } /** @@ -242,7 +242,7 @@ export class Salary extends Controller { detail: "string", //คำอธิบาย }) async GetSalaryById(@Path() id: string) { - try { + // try { const salary = await this.salaryRepository.findOne({ where: { id: id }, select: [ @@ -260,9 +260,9 @@ export class Salary extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี: " + id); } return new HttpSuccess(salary); - } catch (error: any) { - throw new Error(error); - } + // } catch (error: any) { + // throw new Error(error); + // } } /** @@ -277,7 +277,7 @@ export class Salary extends Controller { @Query("pageSize") pageSize: number = 10, @Query("keyword") keyword?: string, ) { - try { + // try { const [salary, total] = await this.salaryRepository.findAndCount({ relations: ["posLevel_", "posType_"], order: { @@ -334,9 +334,9 @@ export class Salary extends Controller { details: item.details, })); return new HttpSuccess({ data: formattedData, total }); - } catch (error: any) { - throw new Error(error); - } + // } catch (error: any) { + // throw new Error(error); + // } } /** @@ -350,7 +350,7 @@ export class Salary extends Controller { @Body() body: { id: string }, @Request() request: { user: Record }, ) { - try { + // try { const salary = await this.salaryRepository.findOne({ relations: ["posLevel_", "posType_", "salaryRanks_"], where: { id: body.id }, @@ -379,8 +379,8 @@ export class Salary extends Controller { ); return new HttpSuccess({ id: newSalary.id }); - } catch (error: any) { - throw new Error(error); - } + // } catch (error: any) { + // throw new Error(error); + // } } } diff --git a/src/controllers/SalaryRankController.ts b/src/controllers/SalaryRankController.ts index 5fa9512..7d6668e 100644 --- a/src/controllers/SalaryRankController.ts +++ b/src/controllers/SalaryRankController.ts @@ -81,7 +81,7 @@ export class SalaryRanksController extends Controller { requestBody: UpdateSalaryRank, @Request() request: { user: Record }, ) { - try { + // try { const salaryRank = await this.salaryRankRepository.findOne({ where: { id: id } }); if (!salaryRank) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id); @@ -91,9 +91,9 @@ export class SalaryRanksController extends Controller { this.salaryRankRepository.merge(salaryRank, requestBody); await this.salaryRankRepository.save(salaryRank); return new HttpSuccess(); - } catch (error: any) { - throw new Error(error); - } + // } catch (error: any) { + // throw new Error(error); + // } } /** @@ -105,7 +105,7 @@ export class SalaryRanksController extends Controller { */ @Delete("{id}") async deleteSalaryRanks(@Path() id: string) { - try { + // try { const delSalaryRanks = await this.salaryRankRepository.findOne({ where: { id }, }); @@ -114,9 +114,9 @@ export class SalaryRanksController extends Controller { } await this.salaryRankRepository.delete({ id: id }); return new HttpSuccess(); - } catch (error: any) { - throw new Error(error); - } + // } catch (error: any) { + // throw new Error(error); + // } } // /** @@ -156,7 +156,7 @@ export class SalaryRanksController extends Controller { @Query("pageSize") pageSize: number = 10, @Query("keyword") keyword?: string, ) { - try { + // try { const [salaryRank, total] = await this.salaryRankRepository.findAndCount({ where: { salaryId: id, @@ -197,8 +197,8 @@ export class SalaryRanksController extends Controller { return new HttpSuccess([]); } return new HttpSuccess({ data: salaryRank, total }); - } catch (error: any) { - throw new Error(error); - } + // } catch (error: any) { + // throw new Error(error); + // } } }