remove try catch
This commit is contained in:
parent
039b11d1c3
commit
e9ed8ff3f4
8 changed files with 1575 additions and 1744 deletions
|
|
@ -58,26 +58,22 @@ export class OrgChild3Controller {
|
|||
if (!orgChild3) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ 3");
|
||||
}
|
||||
try {
|
||||
const getOrgChild3 = {
|
||||
orgChild3Id: orgChild3.id,
|
||||
orgRootName: orgChild3.orgRoot.orgRootName,
|
||||
orgName: `${orgChild3.orgChild3Name}/${orgChild3.orgChild2.orgChild2Name}/${orgChild3.orgChild1.orgChild1Name}/${orgChild3.orgRoot.orgRootName}`,
|
||||
orgChild3Name: orgChild3.orgChild3Name,
|
||||
orgChild3ShortName: orgChild3.orgChild3ShortName,
|
||||
orgChild3Code: orgChild3.orgChild3Code,
|
||||
orgChild3Rank: orgChild3.orgChild3Rank,
|
||||
orgChild3Order: orgChild3.orgChild3Order,
|
||||
orgChild3PhoneEx: orgChild3.orgChild3PhoneEx,
|
||||
orgChild3PhoneIn: orgChild3.orgChild3PhoneIn,
|
||||
orgChild3Fax: orgChild3.orgChild3Fax,
|
||||
orgRevisionId: orgChild3.orgRevisionId,
|
||||
orgCode: orgChild3.orgRoot.orgRootCode + orgChild3.orgChild3Code,
|
||||
};
|
||||
return new HttpSuccess(getOrgChild3);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
const getOrgChild3 = {
|
||||
orgChild3Id: orgChild3.id,
|
||||
orgRootName: orgChild3.orgRoot.orgRootName,
|
||||
orgName: `${orgChild3.orgChild3Name}/${orgChild3.orgChild2.orgChild2Name}/${orgChild3.orgChild1.orgChild1Name}/${orgChild3.orgRoot.orgRootName}`,
|
||||
orgChild3Name: orgChild3.orgChild3Name,
|
||||
orgChild3ShortName: orgChild3.orgChild3ShortName,
|
||||
orgChild3Code: orgChild3.orgChild3Code,
|
||||
orgChild3Rank: orgChild3.orgChild3Rank,
|
||||
orgChild3Order: orgChild3.orgChild3Order,
|
||||
orgChild3PhoneEx: orgChild3.orgChild3PhoneEx,
|
||||
orgChild3PhoneIn: orgChild3.orgChild3PhoneIn,
|
||||
orgChild3Fax: orgChild3.orgChild3Fax,
|
||||
orgRevisionId: orgChild3.orgRevisionId,
|
||||
orgCode: orgChild3.orgRoot.orgRootCode + orgChild3.orgChild3Code,
|
||||
};
|
||||
return new HttpSuccess(getOrgChild3);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -124,24 +120,20 @@ export class OrgChild3Controller {
|
|||
},
|
||||
order: { orgChild3Order: "DESC" },
|
||||
});
|
||||
try {
|
||||
const child3 = Object.assign(new OrgChild3(), requestBody) as OrgChild3;
|
||||
child3.orgChild3Name = requestBody.orgChild3Name;
|
||||
child3.createdUserId = request.user.sub;
|
||||
child3.createdFullName = request.user.name;
|
||||
child3.lastUpdateUserId = request.user.sub;
|
||||
child3.lastUpdateFullName = request.user.name;
|
||||
child3.orgRootId = String(child2?.orgRootId);
|
||||
child3.orgChild1Id = String(child2?.orgChild1Id);
|
||||
child3.orgRevisionId = String(child2?.orgRevisionId);
|
||||
child3.orgChild2Id = String(child2?.id);
|
||||
child3.orgChild3Order =
|
||||
order == null || order.orgChild3Order == null ? 1 : order.orgChild3Order + 1;
|
||||
await this.child3Repository.save(child3);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
const child3 = Object.assign(new OrgChild3(), requestBody) as OrgChild3;
|
||||
child3.orgChild3Name = requestBody.orgChild3Name;
|
||||
child3.createdUserId = request.user.sub;
|
||||
child3.createdFullName = request.user.name;
|
||||
child3.lastUpdateUserId = request.user.sub;
|
||||
child3.lastUpdateFullName = request.user.name;
|
||||
child3.orgRootId = String(child2?.orgRootId);
|
||||
child3.orgChild1Id = String(child2?.orgChild1Id);
|
||||
child3.orgRevisionId = String(child2?.orgRevisionId);
|
||||
child3.orgChild2Id = String(child2?.id);
|
||||
child3.orgChild3Order =
|
||||
order == null || order.orgChild3Order == null ? 1 : order.orgChild3Order + 1;
|
||||
await this.child3Repository.save(child3);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -192,20 +184,16 @@ export class OrgChild3Controller {
|
|||
if (!child3) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
}
|
||||
try {
|
||||
child3.lastUpdateUserId = request.user.sub;
|
||||
child3.lastUpdateFullName = request.user.name;
|
||||
child3.lastUpdatedAt = new Date();
|
||||
child3.orgRootId = String(child2IdExits?.orgRootId);
|
||||
child3.orgChild1Id = String(child2IdExits?.orgChild1Id);
|
||||
child3.orgRevisionId = String(child2IdExits?.orgRevisionId);
|
||||
child3.orgChild2Id = String(child2IdExits?.id);
|
||||
this.child3Repository.merge(child3, requestBody);
|
||||
await this.child3Repository.save(child3);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
child3.lastUpdateUserId = request.user.sub;
|
||||
child3.lastUpdateFullName = request.user.name;
|
||||
child3.lastUpdatedAt = new Date();
|
||||
child3.orgRootId = String(child2IdExits?.orgRootId);
|
||||
child3.orgChild1Id = String(child2IdExits?.orgChild1Id);
|
||||
child3.orgRevisionId = String(child2IdExits?.orgRevisionId);
|
||||
child3.orgChild2Id = String(child2IdExits?.id);
|
||||
this.child3Repository.merge(child3, requestBody);
|
||||
await this.child3Repository.save(child3);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -245,21 +233,17 @@ export class OrgChild3Controller {
|
|||
// "ไม่สามารถลบได้ เนื่องจาก id ผูกกับโครงสร้างระดับ4",
|
||||
// );
|
||||
// }
|
||||
try {
|
||||
const posMasters = await this.posMasterRepository.find({
|
||||
where: { orgChild3Id: id },
|
||||
});
|
||||
const positions = await this.positionRepository.find({
|
||||
where: [{ posMasterId: In(posMasters.map((x) => x.id)) }],
|
||||
});
|
||||
const posMasters = await this.posMasterRepository.find({
|
||||
where: { orgChild3Id: 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({ orgChild3Id: id });
|
||||
await this.child3Repository.delete(id);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
await this.positionRepository.remove(positions);
|
||||
await this.posMasterRepository.remove(posMasters);
|
||||
await this.child4Repository.delete({ orgChild3Id: id });
|
||||
await this.child3Repository.delete(id);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue