remove try catch

This commit is contained in:
AdisakKanthawilang 2024-02-28 11:31:01 +07:00
parent 039b11d1c3
commit e9ed8ff3f4
8 changed files with 1575 additions and 1744 deletions

View file

@ -53,25 +53,21 @@ export class OrgRootController extends Controller {
if (!orgRoot) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ Root");
}
try {
const getOrgRoot = {
orgRootId: orgRoot.id,
orgRootName: orgRoot.orgRootName,
orgName: "-",
orgRootShortName: orgRoot.orgRootShortName,
orgRootCode: orgRoot.orgRootCode,
orgRootRank: orgRoot.orgRootRank,
orgRootOrder: orgRoot.orgRootOrder,
orgRootPhoneEx: orgRoot.orgRootPhoneEx,
orgRootPhoneIn: orgRoot.orgRootPhoneIn,
orgRootFax: orgRoot.orgRootFax,
orgRevisionId: orgRoot.orgRevisionId,
orgCode: orgRoot.orgRootCode + "00",
};
return new HttpSuccess(getOrgRoot);
} catch (error) {
return error;
}
const getOrgRoot = {
orgRootId: orgRoot.id,
orgRootName: orgRoot.orgRootName,
orgName: "-",
orgRootShortName: orgRoot.orgRootShortName,
orgRootCode: orgRoot.orgRootCode,
orgRootRank: orgRoot.orgRootRank,
orgRootOrder: orgRoot.orgRootOrder,
orgRootPhoneEx: orgRoot.orgRootPhoneEx,
orgRootPhoneIn: orgRoot.orgRootPhoneIn,
orgRootFax: orgRoot.orgRootFax,
orgRevisionId: orgRoot.orgRevisionId,
orgCode: orgRoot.orgRootCode + "00",
};
return new HttpSuccess(getOrgRoot);
}
/**
@ -134,19 +130,14 @@ export class OrgRootController extends Controller {
},
order: { orgRootOrder: "DESC" },
});
try {
orgRoot.createdUserId = request.user.sub;
orgRoot.createdFullName = request.user.name;
orgRoot.lastUpdateUserId = request.user.sub;
orgRoot.lastUpdateFullName = request.user.name;
orgRoot.orgRootOrder =
order == null || order.orgRootOrder == null ? 1 : order.orgRootOrder + 1;
await this.orgRootRepository.save(orgRoot);
orgRoot.createdUserId = request.user.sub;
orgRoot.createdFullName = request.user.name;
orgRoot.lastUpdateUserId = request.user.sub;
orgRoot.lastUpdateFullName = request.user.name;
orgRoot.orgRootOrder = order == null || order.orgRootOrder == null ? 1 : order.orgRootOrder + 1;
await this.orgRootRepository.save(orgRoot);
return new HttpSuccess();
} catch (error) {
return error;
}
return new HttpSuccess();
}
/**
@ -209,17 +200,13 @@ export class OrgRootController extends Controller {
"ไม่พบข้อมูลโครงสร้างระดับ Root ตามไอดีนี้ :" + id,
);
}
try {
orgRoot.lastUpdateUserId = request.user.sub;
orgRoot.lastUpdateFullName = request.user.name;
orgRoot.lastUpdatedAt = new Date();
this.orgRootRepository.merge(orgRoot, requestBody);
await this.orgRootRepository.save(orgRoot);
orgRoot.lastUpdateUserId = request.user.sub;
orgRoot.lastUpdateFullName = request.user.name;
orgRoot.lastUpdatedAt = new Date();
this.orgRootRepository.merge(orgRoot, requestBody);
await this.orgRootRepository.save(orgRoot);
return new HttpSuccess();
} catch (error) {
return error;
}
return new HttpSuccess();
}
/**
@ -262,25 +249,21 @@ export class OrgRootController extends Controller {
"not found. orgRevisionIsDraft:true, orgRevisionIsCurrent:false",
);
}
try {
const posMasters = await this.posMasterRepository.find({
where: { orgRootId: id },
});
const positions = await this.positionRepository.find({
where: [{ posMasterId: In(posMasters.map((x) => x.id)) }],
});
const posMasters = await this.posMasterRepository.find({
where: { orgRootId: id },
});
const positions = await this.positionRepository.find({
where: [{ posMasterId: In(posMasters.map((x) => x.id)) }],
});
await this.positionRepository.remove(positions);
await this.posMasterRepository.remove(posMasters);
await this.orgChild4Repository.delete({ orgRootId: id });
await this.orgChild3Repository.delete({ orgRootId: id });
await this.orgChild2Repository.delete({ orgRootId: id });
await this.orgChild1Repository.delete({ orgRootId: id });
await this.orgRootRepository.delete({ id });
await this.positionRepository.remove(positions);
await this.posMasterRepository.remove(posMasters);
await this.orgChild4Repository.delete({ orgRootId: id });
await this.orgChild3Repository.delete({ orgRootId: id });
await this.orgChild2Repository.delete({ orgRootId: id });
await this.orgChild1Repository.delete({ orgRootId: id });
await this.orgRootRepository.delete({ id });
return new HttpSuccess();
} catch (error) {
return error;
}
return new HttpSuccess();
}
}