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 OrgChild4Controller extends Controller {
if (!orgChild4) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ 4");
}
try {
const getOrgChild4 = {
orgChild4Id: orgChild4.id,
orgRootName: orgChild4.orgRoot.orgRootName,
orgName: `${orgChild4.orgChild4Name}/${orgChild4.orgChild3.orgChild3Name}/${orgChild4.orgChild2.orgChild2Name}/${orgChild4.orgChild1.orgChild1Name}/${orgChild4.orgRoot.orgRootName}`,
orgChild4Name: orgChild4.orgChild4Name,
orgChild4ShortName: orgChild4.orgChild4ShortName,
orgChild4Code: orgChild4.orgChild4Code,
orgChild4Rank: orgChild4.orgChild4Rank,
orgChild4Order: orgChild4.orgChild4Order,
orgChild4PhoneEx: orgChild4.orgChild4PhoneEx,
orgChild4PhoneIn: orgChild4.orgChild4PhoneIn,
orgChild4Fax: orgChild4.orgChild4Fax,
orgRevisionId: orgChild4.orgRevisionId,
orgCode: orgChild4.orgRoot.orgRootCode + orgChild4.orgChild4Code,
};
return new HttpSuccess(getOrgChild4);
} catch (error) {
return error;
}
const getOrgChild4 = {
orgChild4Id: orgChild4.id,
orgRootName: orgChild4.orgRoot.orgRootName,
orgName: `${orgChild4.orgChild4Name}/${orgChild4.orgChild3.orgChild3Name}/${orgChild4.orgChild2.orgChild2Name}/${orgChild4.orgChild1.orgChild1Name}/${orgChild4.orgRoot.orgRootName}`,
orgChild4Name: orgChild4.orgChild4Name,
orgChild4ShortName: orgChild4.orgChild4ShortName,
orgChild4Code: orgChild4.orgChild4Code,
orgChild4Rank: orgChild4.orgChild4Rank,
orgChild4Order: orgChild4.orgChild4Order,
orgChild4PhoneEx: orgChild4.orgChild4PhoneEx,
orgChild4PhoneIn: orgChild4.orgChild4PhoneIn,
orgChild4Fax: orgChild4.orgChild4Fax,
orgRevisionId: orgChild4.orgRevisionId,
orgCode: orgChild4.orgRoot.orgRootCode + orgChild4.orgChild4Code,
};
return new HttpSuccess(getOrgChild4);
}
/**
@ -140,26 +136,22 @@ export class OrgChild4Controller extends Controller {
},
order: { orgChild4Order: "DESC" },
});
try {
const child4 = Object.assign(new OrgChild4(), requestBody) as OrgChild4;
child4.orgChild4Name = requestBody.orgChild4Name;
child4.createdUserId = request.user.sub;
child4.createdFullName = request.user.name;
child4.lastUpdateUserId = request.user.sub;
child4.lastUpdateFullName = request.user.name;
child4.orgRootId = String(child3?.orgRootId);
child4.orgChild1Id = String(child3?.orgChild1Id);
child4.orgChild2Id = String(child3?.orgChild2Id);
child4.orgRevisionId = String(child3?.orgRevisionId);
child4.orgChild3Id = String(child3?.id);
child4.orgChild4Order =
order == null || order.orgChild4Order == null ? 1 : order.orgChild4Order + 1;
await this.child4Repository.save(child4);
const child4 = Object.assign(new OrgChild4(), requestBody) as OrgChild4;
child4.orgChild4Name = requestBody.orgChild4Name;
child4.createdUserId = request.user.sub;
child4.createdFullName = request.user.name;
child4.lastUpdateUserId = request.user.sub;
child4.lastUpdateFullName = request.user.name;
child4.orgRootId = String(child3?.orgRootId);
child4.orgChild1Id = String(child3?.orgChild1Id);
child4.orgChild2Id = String(child3?.orgChild2Id);
child4.orgRevisionId = String(child3?.orgRevisionId);
child4.orgChild3Id = String(child3?.id);
child4.orgChild4Order =
order == null || order.orgChild4Order == null ? 1 : order.orgChild4Order + 1;
await this.child4Repository.save(child4);
return new HttpSuccess();
} catch (error) {
return error;
}
return new HttpSuccess();
}
/**
@ -224,21 +216,17 @@ export class OrgChild4Controller extends Controller {
if (!child4) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
try {
child4.lastUpdateUserId = request.user.sub;
child4.lastUpdateFullName = request.user.name;
child4.lastUpdatedAt = new Date();
child4.orgRootId = String(child3IdExits?.orgRootId);
child4.orgChild1Id = String(child3IdExits?.orgChild1Id);
child4.orgChild2Id = String(child3IdExits?.orgChild2Id);
child4.orgRevisionId = String(child3IdExits?.orgRevisionId);
child4.orgChild3Id = String(child3IdExits?.id);
this.child4Repository.merge(child4, requestBody);
await this.child4Repository.save(child4);
return new HttpSuccess();
} catch (error) {
return error;
}
child4.lastUpdateUserId = request.user.sub;
child4.lastUpdateFullName = request.user.name;
child4.lastUpdatedAt = new Date();
child4.orgRootId = String(child3IdExits?.orgRootId);
child4.orgChild1Id = String(child3IdExits?.orgChild1Id);
child4.orgChild2Id = String(child3IdExits?.orgChild2Id);
child4.orgRevisionId = String(child3IdExits?.orgRevisionId);
child4.orgChild3Id = String(child3IdExits?.id);
this.child4Repository.merge(child4, requestBody);
await this.child4Repository.save(child4);
return new HttpSuccess();
}
/**
@ -270,20 +258,16 @@ export class OrgChild4Controller extends Controller {
"not found. orgRevisionIsDraft:true, orgRevisionIsCurrent:false",
);
}
try {
const posMasters = await this.posMasterRepository.find({
where: { orgChild4Id: id },
});
const positions = await this.positionRepository.find({
where: [{ posMasterId: In(posMasters.map((x) => x.id)) }],
});
const posMasters = await this.posMasterRepository.find({
where: { orgChild4Id: 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(id);
return new HttpSuccess();
} catch (error) {
return error;
}
await this.positionRepository.remove(positions);
await this.posMasterRepository.remove(posMasters);
await this.child4Repository.delete(id);
return new HttpSuccess();
}
}