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();
}
}

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();
}
}

View file

@ -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();
}
}

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();
}
}

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();
}
}

View file

@ -12,7 +12,7 @@ import {
SuccessResponse,
Response,
Get,
Example
Example,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
@ -44,7 +44,6 @@ export class PosExecutiveController extends Controller {
requestBody: CreatePosExecutive,
@Request() request: { user: Record<string, any> },
) {
const checkName = await this.posExecutiveRepository.findOne({
where: { posExecutiveName: requestBody.posExecutiveName },
});
@ -53,17 +52,13 @@ export class PosExecutiveController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
}
try {
const posExecutive = Object.assign(new PosExecutive(), requestBody);
posExecutive.createdUserId = request.user.sub;
posExecutive.createdFullName = request.user.name;
posExecutive.lastUpdateUserId = request.user.sub;
posExecutive.lastUpdateFullName = request.user.name;
await this.posExecutiveRepository.save(posExecutive);
return new HttpSuccess();
} catch (error) {
return error;
}
const posExecutive = Object.assign(new PosExecutive(), requestBody);
posExecutive.createdUserId = request.user.sub;
posExecutive.createdFullName = request.user.name;
posExecutive.lastUpdateUserId = request.user.sub;
posExecutive.lastUpdateFullName = request.user.name;
await this.posExecutiveRepository.save(posExecutive);
return new HttpSuccess();
}
/**
@ -80,11 +75,11 @@ export class PosExecutiveController extends Controller {
requestBody: CreatePosExecutive,
@Request() request: { user: Record<string, any> },
) {
const posExecutive = await this.posExecutiveRepository.findOne({where: {id: id}});
const posExecutive = await this.posExecutiveRepository.findOne({ where: { id: id } });
if (!posExecutive) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
}
const checkName = await this.posExecutiveRepository.findOne({
where: { posExecutiveName: requestBody.posExecutiveName },
});
@ -93,15 +88,11 @@ export class PosExecutiveController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
}
try {
posExecutive.lastUpdateUserId = request.user.sub;
posExecutive.lastUpdateFullName = request.user.name;
this.posExecutiveRepository.merge(posExecutive, requestBody);
await this.posExecutiveRepository.save(posExecutive);
return new HttpSuccess();
} catch (error) {
return error;
}
posExecutive.lastUpdateUserId = request.user.sub;
posExecutive.lastUpdateFullName = request.user.name;
this.posExecutiveRepository.merge(posExecutive, requestBody);
await this.posExecutiveRepository.save(posExecutive);
return new HttpSuccess();
}
/**
@ -119,44 +110,31 @@ export class PosExecutiveController extends Controller {
if (!delPosExecutive) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งตามไอดีนี้ : " + id);
}
try {
await this.positionRepository.delete({ posExecutiveId: id });
await this.posExecutiveRepository.delete({ id });
return new HttpSuccess();
} catch (error) {
return error;
}
await this.positionRepository.delete({ posExecutiveId: id });
await this.posExecutiveRepository.delete({ id });
return new HttpSuccess();
}
/**
/**
* API
*
* @summary ORG_044 - (ADMIN) #47
*
*
* @param {string} id Id
*/
@Get("{id}")
async detailPosExecutive(@Path() id: string) {
@Get("{id}")
async detailPosExecutive(@Path() id: string) {
const posExecutive = await this.posExecutiveRepository.findOne({
where: { id },
select:[
"id",
"posExecutiveName",
"posExecutivePriority"
]
});
if (!posExecutive) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
try {
return new HttpSuccess(posExecutive);
} catch (error) {
return error;
}
}
select: ["id", "posExecutiveName", "posExecutivePriority"],
});
if (!posExecutive) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(posExecutive);
}
/**
/**
* API
*
* @summary ORG_026 - (ADMIN) #28
@ -171,16 +149,12 @@ export class PosExecutiveController extends Controller {
},
])
async GetPosExecutive() {
try {
const posExecutive = await this.posExecutiveRepository.find({
select: ["id", "posExecutiveName", "posExecutivePriority"],
});
if (!posExecutive) {
return new HttpSuccess([]);
}
return new HttpSuccess(posExecutive);
} catch (error) {
return error;
const posExecutive = await this.posExecutiveRepository.find({
select: ["id", "posExecutiveName", "posExecutivePriority"],
});
if (!posExecutive) {
return new HttpSuccess([]);
}
return new HttpSuccess(posExecutive);
}
}

View file

@ -32,9 +32,7 @@ import { Not } from "typeorm";
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class PosLevelController extends Controller {
private posTypeRepository = AppDataSource.getRepository(PosType);
private posLevelRepository = AppDataSource.getRepository(PosLevel);
@ -45,14 +43,12 @@ export class PosLevelController extends Controller {
*
*/
@Post()
@Example(
{
posLevelName: "นักบริหาร",
posLevelRank: 1,
posLevelAuthority: "HEAD",
posTypeId: "08db9e81-fc46-4e95-8b33-be4ca0016abf"
},
)
@Example({
posLevelName: "นักบริหาร",
posLevelRank: 1,
posLevelAuthority: "HEAD",
posTypeId: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
})
async createLevel(
@Body()
requestBody: CreatePosLevel,
@ -62,19 +58,29 @@ export class PosLevelController extends Controller {
if (!posLevel) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
const chkPosTypeId = await this.posTypeRepository.findOne({ where: {
id: requestBody.posTypeId }
})
if(!chkPosTypeId){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล posTypeId ไอดีนี้ : " + requestBody.posTypeId);
const chkPosTypeId = await this.posTypeRepository.findOne({
where: {
id: requestBody.posTypeId,
},
});
if (!chkPosTypeId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูล posTypeId ไอดีนี้ : " + requestBody.posTypeId,
);
}
const chkPosLevelName = await this.posLevelRepository.findOne({ where: {
posTypeId: requestBody.posTypeId, //ระดับประเภทเดียวกัน ชื่อระดับตำแหน่ง ห้ามซ้ำ
posLevelName: requestBody.posLevelName }
})
if(chkPosLevelName){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อระดับตำแหน่ง: " + requestBody.posLevelName + " มีอยู่ในระบบแล้ว");
const chkPosLevelName = await this.posLevelRepository.findOne({
where: {
posTypeId: requestBody.posTypeId, //ระดับประเภทเดียวกัน ชื่อระดับตำแหน่ง ห้ามซ้ำ
posLevelName: requestBody.posLevelName,
},
});
if (chkPosLevelName) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ชื่อระดับตำแหน่ง: " + requestBody.posLevelName + " มีอยู่ในระบบแล้ว",
);
}
const validPosLevelAuthority = ["HEAD", "DEPUTY", "GOVERNOR"];
@ -85,16 +91,12 @@ export class PosLevelController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. posLevelAuthority");
}
try {
posLevel.createdUserId = request.user.sub;
posLevel.createdFullName = request.user.name;
posLevel.lastUpdateUserId = request.user.sub;
posLevel.lastUpdateFullName = request.user.name;
await this.posLevelRepository.save(posLevel);
return new HttpSuccess(posLevel);
} catch (error) {
return error;
}
posLevel.createdUserId = request.user.sub;
posLevel.createdFullName = request.user.name;
posLevel.lastUpdateUserId = request.user.sub;
posLevel.lastUpdateFullName = request.user.name;
await this.posLevelRepository.save(posLevel);
return new HttpSuccess(posLevel);
}
/**
@ -105,12 +107,10 @@ export class PosLevelController extends Controller {
* @param {string} id Id
*/
@Put("{id}")
@Example(
{
positionName: "นักบริหาร",
posTypeRank: 1,
},
)
@Example({
positionName: "นักบริหาร",
posTypeRank: 1,
})
async editLevel(
@Path() id: string,
@Body() requestBody: UpdatePosLevel,
@ -121,20 +121,30 @@ export class PosLevelController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
}
const chkPosTypeId = await this.posTypeRepository.findOne({ where: {
id: requestBody.posTypeId }
})
if(!chkPosTypeId){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล posTypeId ไอดีนี้ : " + requestBody.posTypeId);
const chkPosTypeId = await this.posTypeRepository.findOne({
where: {
id: requestBody.posTypeId,
},
});
if (!chkPosTypeId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูล posTypeId ไอดีนี้ : " + requestBody.posTypeId,
);
}
const chkPosLevelName = await this.posLevelRepository.findOne({ where: {
id: Not(id),
posTypeId: requestBody.posTypeId,
posLevelName: requestBody.posLevelName }
})
if(chkPosLevelName){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อระดับตำแหน่ง: " + requestBody.posLevelName + " มีอยู่ในระบบแล้ว");
const chkPosLevelName = await this.posLevelRepository.findOne({
where: {
id: Not(id),
posTypeId: requestBody.posTypeId,
posLevelName: requestBody.posLevelName,
},
});
if (chkPosLevelName) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ชื่อระดับตำแหน่ง: " + requestBody.posLevelName + " มีอยู่ในระบบแล้ว",
);
}
const validPosLevelAuthority = ["HEAD", "DEPUTY", "GOVERNOR"];
if (
@ -144,15 +154,11 @@ export class PosLevelController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. posLevelAuthority");
}
try {
posLevel.lastUpdateUserId = request.user.sub;
posLevel.lastUpdateFullName = request.user.name;
this.posLevelRepository.merge(posLevel, requestBody);
await this.posLevelRepository.save(posLevel);
return new HttpSuccess(posLevel.id);
} catch (error) {
return error;
}
posLevel.lastUpdateUserId = request.user.sub;
posLevel.lastUpdateFullName = request.user.name;
this.posLevelRepository.merge(posLevel, requestBody);
await this.posLevelRepository.save(posLevel);
return new HttpSuccess(posLevel.id);
}
/**
@ -168,12 +174,8 @@ export class PosLevelController extends Controller {
if (!delPosLevel) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
}
try {
await this.posLevelRepository.remove(delPosLevel);
return new HttpSuccess();
} catch (error) {
return error;
}
await this.posLevelRepository.remove(delPosLevel);
return new HttpSuccess();
}
/**
@ -184,46 +186,40 @@ export class PosLevelController extends Controller {
* @param {string} id Id
*/
@Get("{id}")
@Example(
{
@Example({
id: "00000000-0000-0000-0000-000000000000",
posLevelName: "นักบริหาร",
posLevelRank: 1,
posLevelAuthority: "HEAD",
posTypes: {
id: "00000000-0000-0000-0000-000000000000",
posLevelName: "นักบริหาร",
posLevelRank: 1,
posLevelAuthority: "HEAD",
posTypes: {
id: "00000000-0000-0000-0000-000000000000",
posTypeName: "นักบริหาร",
posTypeRank: 1,
},
posTypeName: "นักบริหาร",
posTypeRank: 1,
},
)
})
async GetLevelDetail(@Path() id: string) {
try {
const getPosType = await this.posLevelRepository.findOne({
select: ["id", "posLevelName", "posLevelRank", "posLevelAuthority"],
relations: ["posType"],
where: { id: id }
});
if (!getPosType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
}
const mapPosLevel = {
id: getPosType.id,
posLevelName: getPosType.posLevelName,
posLevelRank: getPosType.posLevelRank,
posLevelAuthority: getPosType.posLevelAuthority,
posTypes:{
id: getPosType.posType.id,
posTypeName: getPosType.posType.posTypeName,
posTypeRank: getPosType.posType.posTypeRank
}
}
return new HttpSuccess(mapPosLevel);
} catch (error) {
return error;
const getPosType = await this.posLevelRepository.findOne({
select: ["id", "posLevelName", "posLevelRank", "posLevelAuthority"],
relations: ["posType"],
where: { id: id },
});
if (!getPosType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
}
const mapPosLevel = {
id: getPosType.id,
posLevelName: getPosType.posLevelName,
posLevelRank: getPosType.posLevelRank,
posLevelAuthority: getPosType.posLevelAuthority,
posTypes: {
id: getPosType.posType.id,
posTypeName: getPosType.posType.posTypeName,
posTypeRank: getPosType.posType.posTypeRank,
},
};
return new HttpSuccess(mapPosLevel);
}
/**
@ -247,28 +243,24 @@ export class PosLevelController extends Controller {
},
])
async GetPosLevel() {
try {
const posLevel = await this.posLevelRepository.find({
select: ["id", "posLevelName", "posLevelRank", "posLevelAuthority", "posTypeId"],
relations: ["posType"],
});
if (!posLevel) {
return new HttpSuccess([]);
}
const mapPosLevel = posLevel.map((item) => ({
id: item.id,
posLevelName: item.posLevelName,
posLevelRank: item.posLevelRank,
posLevelAuthority: item.posLevelAuthority,
posTypes: {
id: item.posType.id,
posTypeName: item.posType.posTypeName,
posTypeRank: item.posType.posTypeRank,
}
}));
return new HttpSuccess(mapPosLevel);
} catch (error) {
return error;
const posLevel = await this.posLevelRepository.find({
select: ["id", "posLevelName", "posLevelRank", "posLevelAuthority", "posTypeId"],
relations: ["posType"],
});
if (!posLevel) {
return new HttpSuccess([]);
}
const mapPosLevel = posLevel.map((item) => ({
id: item.id,
posLevelName: item.posLevelName,
posLevelRank: item.posLevelRank,
posLevelAuthority: item.posLevelAuthority,
posTypes: {
id: item.posType.id,
posTypeName: item.posType.posTypeName,
posTypeRank: item.posType.posTypeRank,
},
}));
return new HttpSuccess(mapPosLevel);
}
}

File diff suppressed because it is too large Load diff