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

@ -62,26 +62,22 @@ export class OrgChild2Controller extends Controller {
if (!orgChild2) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ 2");
}
try {
const getOrgChild2 = {
orgChild2Id: orgChild2.id,
orgRootName: orgChild2.orgRoot.orgRootName,
orgName: `${orgChild2.orgChild2Name}/${orgChild2.orgChild1.orgChild1Name}/${orgChild2.orgRoot.orgRootName}`,
orgChild2Name: orgChild2.orgChild2Name,
orgChild2ShortName: orgChild2.orgChild2ShortName,
orgChild2Code: orgChild2.orgChild2Code,
orgChild2Rank: orgChild2.orgChild2Rank,
orgChild2Order: orgChild2.orgChild2Order,
orgChild2PhoneEx: orgChild2.orgChild2PhoneEx,
orgChild2PhoneIn: orgChild2.orgChild2PhoneIn,
orgChild2Fax: orgChild2.orgChild2Fax,
orgRevisionId: orgChild2.orgRevisionId,
orgCode: orgChild2.orgRoot.orgRootCode + orgChild2.orgChild2Code,
};
return new HttpSuccess(getOrgChild2);
} catch (error) {
return error;
}
const getOrgChild2 = {
orgChild2Id: orgChild2.id,
orgRootName: orgChild2.orgRoot.orgRootName,
orgName: `${orgChild2.orgChild2Name}/${orgChild2.orgChild1.orgChild1Name}/${orgChild2.orgRoot.orgRootName}`,
orgChild2Name: orgChild2.orgChild2Name,
orgChild2ShortName: orgChild2.orgChild2ShortName,
orgChild2Code: orgChild2.orgChild2Code,
orgChild2Rank: orgChild2.orgChild2Rank,
orgChild2Order: orgChild2.orgChild2Order,
orgChild2PhoneEx: orgChild2.orgChild2PhoneEx,
orgChild2PhoneIn: orgChild2.orgChild2PhoneIn,
orgChild2Fax: orgChild2.orgChild2Fax,
orgRevisionId: orgChild2.orgRevisionId,
orgCode: orgChild2.orgRoot.orgRootCode + orgChild2.orgChild2Code,
};
return new HttpSuccess(getOrgChild2);
}
/**
@ -142,23 +138,19 @@ export class OrgChild2Controller extends Controller {
},
order: { orgChild2Order: "DESC" },
});
try {
const child2 = Object.assign(new OrgChild2(), requestBody) as OrgChild2;
child2.orgChild2Name = requestBody.orgChild2Name;
child2.createdUserId = request.user.sub;
child2.createdFullName = request.user.name;
child2.lastUpdateUserId = request.user.sub;
child2.lastUpdateFullName = request.user.name;
child2.orgRootId = String(child1?.orgRootId);
child2.orgRevisionId = String(child1?.orgRevisionId);
child2.orgChild1Id = String(child1?.id);
child2.orgChild2Order =
order == null || order.orgChild2Order == null ? 1 : order.orgChild2Order + 1;
await this.child2Repository.save(child2);
return new HttpSuccess();
} catch (error) {
return error;
}
const child2 = Object.assign(new OrgChild2(), requestBody) as OrgChild2;
child2.orgChild2Name = requestBody.orgChild2Name;
child2.createdUserId = request.user.sub;
child2.createdFullName = request.user.name;
child2.lastUpdateUserId = request.user.sub;
child2.lastUpdateFullName = request.user.name;
child2.orgRootId = String(child1?.orgRootId);
child2.orgRevisionId = String(child1?.orgRevisionId);
child2.orgChild1Id = String(child1?.id);
child2.orgChild2Order =
order == null || order.orgChild2Order == null ? 1 : order.orgChild2Order + 1;
await this.child2Repository.save(child2);
return new HttpSuccess();
}
/**
@ -223,19 +215,15 @@ export class OrgChild2Controller extends Controller {
if (!child2) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
try {
child2.lastUpdateUserId = request.user.sub;
child2.lastUpdateFullName = request.user.name;
child2.lastUpdatedAt = new Date();
child2.orgRootId = String(child1IdExits?.orgRootId);
child2.orgRevisionId = String(child1IdExits?.orgRevisionId);
child2.orgChild1Id = String(child1IdExits?.id);
this.child2Repository.merge(child2, requestBody);
await this.child2Repository.save(child2);
return new HttpSuccess();
} catch (error) {
return error;
}
child2.lastUpdateUserId = request.user.sub;
child2.lastUpdateFullName = request.user.name;
child2.lastUpdatedAt = new Date();
child2.orgRootId = String(child1IdExits?.orgRootId);
child2.orgRevisionId = String(child1IdExits?.orgRevisionId);
child2.orgChild1Id = String(child1IdExits?.id);
this.child2Repository.merge(child2, requestBody);
await this.child2Repository.save(child2);
return new HttpSuccess();
}
/**
@ -275,22 +263,18 @@ export class OrgChild2Controller extends Controller {
// "ไม่สามารถลบได้ เนื่องจาก id ผูกกับโครงสร้างระดับ4",
// );
// }
try {
const posMasters = await this.posMasterRepository.find({
where: { orgChild2Id: id },
});
const positions = await this.positionRepository.find({
where: [{ posMasterId: In(posMasters.map((x) => x.id)) }],
});
const posMasters = await this.posMasterRepository.find({
where: { orgChild2Id: 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({ orgChild2Id: id });
await this.child3Repository.delete({ orgChild2Id: id });
await this.child2Repository.delete({ id });
return new HttpSuccess();
} catch (error) {
return error;
}
await this.positionRepository.remove(positions);
await this.posMasterRepository.remove(posMasters);
await this.child4Repository.delete({ orgChild2Id: id });
await this.child3Repository.delete({ orgChild2Id: id });
await this.child2Repository.delete({ id });
return new HttpSuccess();
}
}