แก้ SLR_018 , ลบ return id

This commit is contained in:
Bright 2024-02-27 17:14:22 +07:00
parent 1be7261ba0
commit 5f222498cb
6 changed files with 21 additions and 16 deletions

View file

@ -122,7 +122,7 @@ export class PosLevelController extends Controller {
) { ) {
const posLevel = await this.posLevelRepository.findOne({ where: { id } }); const posLevel = await this.posLevelRepository.findOne({ where: { id } });
if (!posLevel) { if (!posLevel) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้");
} }
const chkPosTypeId = await this.posTypeRepository.findOne({ const chkPosTypeId = await this.posTypeRepository.findOne({
@ -180,7 +180,7 @@ export class PosLevelController extends Controller {
async deleteLevel(@Path() id: string) { async deleteLevel(@Path() id: string) {
const delPosLevel = await this.posLevelRepository.findOne({ where: { id } }); const delPosLevel = await this.posLevelRepository.findOne({ where: { id } });
if (!delPosLevel) { if (!delPosLevel) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้");
} }
// try { // try {
await this.posLevelRepository.remove(delPosLevel); await this.posLevelRepository.remove(delPosLevel);
@ -217,7 +217,7 @@ export class PosLevelController extends Controller {
where: { id: id }, where: { id: id },
}); });
if (!getPosType) { if (!getPosType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้");
} }
const mapPosLevel = { const mapPosLevel = {

View file

@ -98,7 +98,7 @@ export class PosTypeController extends Controller {
) { ) {
const posType = await this.posTypeRepository.findOne({ where: { id } }); const posType = await this.posTypeRepository.findOne({ where: { id } });
if (!posType) { if (!posType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้");
} }
const chkPosTypeName = await this.posTypeRepository.findOne({ const chkPosTypeName = await this.posTypeRepository.findOne({
where: { where: {
@ -134,7 +134,7 @@ export class PosTypeController extends Controller {
async deleteType(@Path() id: string) { async deleteType(@Path() id: string) {
const delPosType = await this.posTypeRepository.findOne({ where: { id } }); const delPosType = await this.posTypeRepository.findOne({ where: { id } });
if (!delPosType) { if (!delPosType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้");
} }
const IdExitsInLevel = await this.posLevelRepository.find({ const IdExitsInLevel = await this.posLevelRepository.find({
where: { posTypeId: id }, where: { posTypeId: id },
@ -182,7 +182,7 @@ export class PosTypeController extends Controller {
where: { id: id }, where: { id: id },
}); });
if (!getPosType) { if (!getPosType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้");
} }
const mapGetPosType = { const mapGetPosType = {

View file

@ -53,7 +53,7 @@ export class ReportController extends Controller {
where: { id: id } where: { id: id }
}); });
if (!salarys) { if (!salarys) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี: " + id); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี");
} }
const posType = await this.poTypeRepository.findOne({ const posType = await this.poTypeRepository.findOne({
where: { id: salarys.posTypeId }, where: { id: salarys.posTypeId },

View file

@ -132,7 +132,7 @@ export class Salary extends Controller {
where: { id: id }, where: { id: id },
}); });
if (!chk_Salary) { if (!chk_Salary) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี: " + id); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี");
} }
if (chk_Salary.isActive && !requestBody.isActive) { if (chk_Salary.isActive && !requestBody.isActive) {
@ -205,12 +205,11 @@ export class Salary extends Controller {
where: { id: id }, where: { id: id },
}); });
if (!chk_Salary) { if (!chk_Salary) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี: " + id); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี");
} }
if (chk_Salary.isActive) { if (chk_Salary.isActive) {
throw new HttpError( throw new HttpError(
HttpStatusCode.NOT_FOUND, HttpStatusCode.NOT_FOUND,
// "ไม่สามารถลบไอดี: " + id + " ได้ เนื่องสถานะการใช้งานที่เป็น Default",
"ไม่สามารถลบข้อมูลนี้ได้ เนื่องจากเปิดใช้งานอยู่", "ไม่สามารถลบข้อมูลนี้ได้ เนื่องจากเปิดใช้งานอยู่",
); );
} }
@ -260,7 +259,7 @@ export class Salary extends Controller {
], ],
}); });
if (!salary) { if (!salary) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี: " + id); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี");
} }
return new HttpSuccess(salary); return new HttpSuccess(salary);
// } catch (error: any) { // } catch (error: any) {

View file

@ -516,7 +516,7 @@ export class SalaryPeriodController extends Controller {
where: { id: id }, where: { id: id },
}); });
if (!chk_SalaryPeriod) { if (!chk_SalaryPeriod) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี: " + id); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี");
} }
const chk_toUpper = ["SPECIAL", "APR", "OCT"]; const chk_toUpper = ["SPECIAL", "APR", "OCT"];
@ -560,7 +560,13 @@ export class SalaryPeriodController extends Controller {
where: { id: id }, where: { id: id },
}); });
if (!SalaryPeriod) { if (!SalaryPeriod) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี: " + id); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี");
}
const SalaryOrg = await this.salaryOrgRepository.findOne({
where: { salaryPeriodId: SalaryPeriod.id }
})
if(SalaryOrg){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้");
} }
await this.salaryPeriodRepository.remove(SalaryPeriod); await this.salaryPeriodRepository.remove(SalaryPeriod);
return new HttpSuccess(); return new HttpSuccess();
@ -580,7 +586,7 @@ export class SalaryPeriodController extends Controller {
select: ["id", "period", "isActive", "effectiveDate", "isActive", "status", "year"], select: ["id", "period", "isActive", "effectiveDate", "isActive", "status", "year"],
}); });
if (!salaryPeriod) { if (!salaryPeriod) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี: " + id); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี");
} }
return new HttpSuccess(salaryPeriod); return new HttpSuccess(salaryPeriod);
} }

View file

@ -84,7 +84,7 @@ export class SalaryRanksController extends Controller {
// try { // try {
const salaryRank = await this.salaryRankRepository.findOne({ where: { id: id } }); const salaryRank = await this.salaryRankRepository.findOne({ where: { id: id } });
if (!salaryRank) { if (!salaryRank) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้");
} }
salaryRank.lastUpdateUserId = request.user.sub; salaryRank.lastUpdateUserId = request.user.sub;
salaryRank.lastUpdateFullName = request.user.name; salaryRank.lastUpdateFullName = request.user.name;
@ -110,7 +110,7 @@ export class SalaryRanksController extends Controller {
where: { id }, where: { id },
}); });
if (!delSalaryRanks) { if (!delSalaryRanks) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งตามไอดีนี้ : " + id); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งตามไอดีนี้");
} }
await this.salaryRankRepository.delete({ id: id }); await this.salaryRankRepository.delete({ id: id });
return new HttpSuccess(); return new HttpSuccess();