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

@ -60,26 +60,22 @@ export class OrgChild1Controller {
if (!orgChild1) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ 1");
}
try {
const getOrgChild1 = {
orgChild1Id: orgChild1.id,
orgRootName: orgChild1.orgRoot.orgRootName,
orgName: `${orgChild1.orgChild1Name}/${orgChild1.orgRoot.orgRootName}`,
orgChild1Name: orgChild1.orgChild1Name,
orgChild1ShortName: orgChild1.orgChild1ShortName,
orgChild1Code: orgChild1.orgChild1Code,
orgChild1Rank: orgChild1.orgChild1Rank,
orgChild1Order: orgChild1.orgChild1Order,
orgChild1PhoneEx: orgChild1.orgChild1PhoneEx,
orgChild1PhoneIn: orgChild1.orgChild1PhoneIn,
orgChild1Fax: orgChild1.orgChild1Fax,
orgRevisionId: orgChild1.orgRevisionId,
orgCode: orgChild1.orgRoot.orgRootCode + orgChild1.orgChild1Code,
};
return new HttpSuccess(getOrgChild1);
} catch (error) {
return error;
}
const getOrgChild1 = {
orgChild1Id: orgChild1.id,
orgRootName: orgChild1.orgRoot.orgRootName,
orgName: `${orgChild1.orgChild1Name}/${orgChild1.orgRoot.orgRootName}`,
orgChild1Name: orgChild1.orgChild1Name,
orgChild1ShortName: orgChild1.orgChild1ShortName,
orgChild1Code: orgChild1.orgChild1Code,
orgChild1Rank: orgChild1.orgChild1Rank,
orgChild1Order: orgChild1.orgChild1Order,
orgChild1PhoneEx: orgChild1.orgChild1PhoneEx,
orgChild1PhoneIn: orgChild1.orgChild1PhoneIn,
orgChild1Fax: orgChild1.orgChild1Fax,
orgRevisionId: orgChild1.orgRevisionId,
orgCode: orgChild1.orgRoot.orgRootCode + orgChild1.orgChild1Code,
};
return new HttpSuccess(getOrgChild1);
}
/**
@ -136,22 +132,18 @@ export class OrgChild1Controller {
},
order: { orgChild1Order: "DESC" },
});
try {
const child1 = Object.assign(new OrgChild1(), requestBody) as OrgChild1;
child1.orgChild1Name = requestBody.orgChild1Name;
child1.createdUserId = request.user.sub;
child1.createdFullName = request.user.name;
child1.lastUpdateUserId = request.user.sub;
child1.lastUpdateFullName = request.user.name;
child1.orgRevisionId = String(rootIdExits?.orgRevisionId);
child1.orgRootId = String(rootIdExits?.id);
child1.orgChild1Order =
order == null || order.orgChild1Order == null ? 1 : order.orgChild1Order + 1;
await this.child1Repository.save(child1);
return new HttpSuccess();
} catch (error) {
return error;
}
const child1 = Object.assign(new OrgChild1(), requestBody) as OrgChild1;
child1.orgChild1Name = requestBody.orgChild1Name;
child1.createdUserId = request.user.sub;
child1.createdFullName = request.user.name;
child1.lastUpdateUserId = request.user.sub;
child1.lastUpdateFullName = request.user.name;
child1.orgRevisionId = String(rootIdExits?.orgRevisionId);
child1.orgRootId = String(rootIdExits?.id);
child1.orgChild1Order =
order == null || order.orgChild1Order == null ? 1 : order.orgChild1Order + 1;
await this.child1Repository.save(child1);
return new HttpSuccess();
}
/**
@ -212,18 +204,14 @@ export class OrgChild1Controller {
if (chkCode != null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
}
try {
child1.lastUpdateUserId = request.user.sub;
child1.lastUpdateFullName = request.user.name;
child1.lastUpdatedAt = new Date();
child1.orgRevisionId = String(rootIdExits?.orgRevisionId);
child1.orgRootId = String(rootIdExits?.id);
this.child1Repository.merge(child1, requestBody);
await this.child1Repository.save(child1);
return new HttpSuccess();
} catch (error) {
return error;
}
child1.lastUpdateUserId = request.user.sub;
child1.lastUpdateFullName = request.user.name;
child1.lastUpdatedAt = new Date();
child1.orgRevisionId = String(rootIdExits?.orgRevisionId);
child1.orgRootId = String(rootIdExits?.id);
this.child1Repository.merge(child1, requestBody);
await this.child1Repository.save(child1);
return new HttpSuccess();
}
/**
@ -261,23 +249,19 @@ export class OrgChild1Controller {
// "ไม่สามารถลบได้ เนื่องจาก id ผูกกับโครงสร้างระดับ2",
// );
// }
try {
const posMasters = await this.posMasterRepository.find({
where: { orgChild1Id: id },
});
const positions = await this.positionRepository.find({
where: [{ posMasterId: In(posMasters.map((x) => x.id)) }],
});
const posMasters = await this.posMasterRepository.find({
where: { orgChild1Id: 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.child4Repository.delete({ orgChild1Id: id });
await this.child3Repository.delete({ orgChild1Id: id });
await this.child2Repository.delete({ orgChild1Id: id });
await this.child1Repository.delete({ id });
return new HttpSuccess();
} catch (error) {
return error;
}
await this.positionRepository.remove(positions);
await this.posMasterRepository.remove(posMasters);
await this.child4Repository.delete({ orgChild1Id: id });
await this.child3Repository.delete({ orgChild1Id: id });
await this.child2Repository.delete({ orgChild1Id: id });
await this.child1Repository.delete({ id });
return new HttpSuccess();
}
}