remove try catch
This commit is contained in:
parent
039b11d1c3
commit
e9ed8ff3f4
8 changed files with 1575 additions and 1744 deletions
|
|
@ -12,7 +12,7 @@ import {
|
|||
SuccessResponse,
|
||||
Response,
|
||||
Get,
|
||||
Example
|
||||
Example,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
|
|
@ -44,7 +44,6 @@ export class PosExecutiveController extends Controller {
|
|||
requestBody: CreatePosExecutive,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
|
||||
const checkName = await this.posExecutiveRepository.findOne({
|
||||
where: { posExecutiveName: requestBody.posExecutiveName },
|
||||
});
|
||||
|
|
@ -53,17 +52,13 @@ export class PosExecutiveController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
try {
|
||||
const posExecutive = Object.assign(new PosExecutive(), requestBody);
|
||||
posExecutive.createdUserId = request.user.sub;
|
||||
posExecutive.createdFullName = request.user.name;
|
||||
posExecutive.lastUpdateUserId = request.user.sub;
|
||||
posExecutive.lastUpdateFullName = request.user.name;
|
||||
await this.posExecutiveRepository.save(posExecutive);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
const posExecutive = Object.assign(new PosExecutive(), requestBody);
|
||||
posExecutive.createdUserId = request.user.sub;
|
||||
posExecutive.createdFullName = request.user.name;
|
||||
posExecutive.lastUpdateUserId = request.user.sub;
|
||||
posExecutive.lastUpdateFullName = request.user.name;
|
||||
await this.posExecutiveRepository.save(posExecutive);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -80,11 +75,11 @@ export class PosExecutiveController extends Controller {
|
|||
requestBody: CreatePosExecutive,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const posExecutive = await this.posExecutiveRepository.findOne({where: {id: id}});
|
||||
const posExecutive = await this.posExecutiveRepository.findOne({ where: { id: id } });
|
||||
if (!posExecutive) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
|
||||
}
|
||||
|
||||
|
||||
const checkName = await this.posExecutiveRepository.findOne({
|
||||
where: { posExecutiveName: requestBody.posExecutiveName },
|
||||
});
|
||||
|
|
@ -93,15 +88,11 @@ export class PosExecutiveController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
try {
|
||||
posExecutive.lastUpdateUserId = request.user.sub;
|
||||
posExecutive.lastUpdateFullName = request.user.name;
|
||||
this.posExecutiveRepository.merge(posExecutive, requestBody);
|
||||
await this.posExecutiveRepository.save(posExecutive);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
posExecutive.lastUpdateUserId = request.user.sub;
|
||||
posExecutive.lastUpdateFullName = request.user.name;
|
||||
this.posExecutiveRepository.merge(posExecutive, requestBody);
|
||||
await this.posExecutiveRepository.save(posExecutive);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -119,44 +110,31 @@ export class PosExecutiveController extends Controller {
|
|||
if (!delPosExecutive) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งตามไอดีนี้ : " + id);
|
||||
}
|
||||
try {
|
||||
await this.positionRepository.delete({ posExecutiveId: id });
|
||||
await this.posExecutiveRepository.delete({ id });
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
await this.positionRepository.delete({ posExecutiveId: id });
|
||||
await this.posExecutiveRepository.delete({ id });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* API รายละเอียดตำแหน่งทางการบริหาร
|
||||
*
|
||||
* @summary ORG_044 - รายละเอียดตำแหน่งทางการบริหาร (ADMIN) #47
|
||||
*
|
||||
*
|
||||
* @param {string} id Id ตำแหน่งทางการบริหาร
|
||||
*/
|
||||
@Get("{id}")
|
||||
async detailPosExecutive(@Path() id: string) {
|
||||
|
||||
@Get("{id}")
|
||||
async detailPosExecutive(@Path() id: string) {
|
||||
const posExecutive = await this.posExecutiveRepository.findOne({
|
||||
where: { id },
|
||||
select:[
|
||||
"id",
|
||||
"posExecutiveName",
|
||||
"posExecutivePriority"
|
||||
]
|
||||
});
|
||||
if (!posExecutive) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
try {
|
||||
return new HttpSuccess(posExecutive);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
select: ["id", "posExecutiveName", "posExecutivePriority"],
|
||||
});
|
||||
if (!posExecutive) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
return new HttpSuccess(posExecutive);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* API รายการตำแหน่งทางการบริหาร
|
||||
*
|
||||
* @summary ORG_026 - รายการตำแหน่งทางการบริหาร (ADMIN) #28
|
||||
|
|
@ -171,16 +149,12 @@ export class PosExecutiveController extends Controller {
|
|||
},
|
||||
])
|
||||
async GetPosExecutive() {
|
||||
try {
|
||||
const posExecutive = await this.posExecutiveRepository.find({
|
||||
select: ["id", "posExecutiveName", "posExecutivePriority"],
|
||||
});
|
||||
if (!posExecutive) {
|
||||
return new HttpSuccess([]);
|
||||
}
|
||||
return new HttpSuccess(posExecutive);
|
||||
} catch (error) {
|
||||
return error;
|
||||
const posExecutive = await this.posExecutiveRepository.find({
|
||||
select: ["id", "posExecutiveName", "posExecutivePriority"],
|
||||
});
|
||||
if (!posExecutive) {
|
||||
return new HttpSuccess([]);
|
||||
}
|
||||
return new HttpSuccess(posExecutive);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue