เพิ่มselect detail tree
This commit is contained in:
parent
35ba5b91f3
commit
cd21c42710
7 changed files with 175 additions and 147 deletions
|
|
@ -47,17 +47,18 @@ export class OrgChild1Controller {
|
||||||
*/
|
*/
|
||||||
@Get("{id}")
|
@Get("{id}")
|
||||||
async GetChild1(@Path() id: string) {
|
async GetChild1(@Path() id: string) {
|
||||||
const orgChild1 = await this.child1Repository.findOne({ where: { id } });
|
const orgChild1 = await this.child1Repository.findOne({
|
||||||
|
where: { id },
|
||||||
|
relations: ["orgRoot"],
|
||||||
|
});
|
||||||
if (!orgChild1) {
|
if (!orgChild1) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ 1");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ 1");
|
||||||
}
|
}
|
||||||
const orgRoot = await this.orgRootRepository.findOne({ where: { id: orgChild1.orgRootId } });
|
|
||||||
if (!orgRoot) {
|
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ Root");
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
const getOrgChild1 = {
|
const getOrgChild1 = {
|
||||||
orgChild1Id: orgChild1.id,
|
orgChild1Id: orgChild1.id,
|
||||||
|
orgRootName: orgChild1.orgRoot.orgRootName,
|
||||||
|
orgName: `${orgChild1.orgChild1Name}/${orgChild1.orgRoot.orgRootName}`,
|
||||||
orgChild1Name: orgChild1.orgChild1Name,
|
orgChild1Name: orgChild1.orgChild1Name,
|
||||||
orgChild1ShortName: orgChild1.orgChild1ShortName,
|
orgChild1ShortName: orgChild1.orgChild1ShortName,
|
||||||
orgChild1Code: orgChild1.orgChild1Code,
|
orgChild1Code: orgChild1.orgChild1Code,
|
||||||
|
|
@ -67,7 +68,7 @@ export class OrgChild1Controller {
|
||||||
orgChild1PhoneIn: orgChild1.orgChild1PhoneIn,
|
orgChild1PhoneIn: orgChild1.orgChild1PhoneIn,
|
||||||
orgChild1Fax: orgChild1.orgChild1Fax,
|
orgChild1Fax: orgChild1.orgChild1Fax,
|
||||||
orgRevisionId: orgChild1.orgRevisionId,
|
orgRevisionId: orgChild1.orgRevisionId,
|
||||||
orgCode: orgRoot.orgRootCode + orgChild1.orgChild1Code,
|
orgCode: orgChild1.orgRoot.orgRootCode + orgChild1.orgChild1Code,
|
||||||
};
|
};
|
||||||
return new HttpSuccess(getOrgChild1);
|
return new HttpSuccess(getOrgChild1);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -48,17 +48,18 @@ export class OrgChild2Controller extends Controller {
|
||||||
*/
|
*/
|
||||||
@Get("{id}")
|
@Get("{id}")
|
||||||
async GetChild2(@Path() id: string) {
|
async GetChild2(@Path() id: string) {
|
||||||
const orgChild2 = await this.child2Repository.findOne({ where: { id } });
|
const orgChild2 = await this.child2Repository.findOne({
|
||||||
|
where: { id },
|
||||||
|
relations: ["orgRoot", "orgChild1"],
|
||||||
|
});
|
||||||
if (!orgChild2) {
|
if (!orgChild2) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ 2");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ 2");
|
||||||
}
|
}
|
||||||
const orgRoot = await this.orgRootRepository.findOne({ where: { id: orgChild2.orgRootId } });
|
|
||||||
if (!orgRoot) {
|
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ Root");
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
const getOrgChild2 = {
|
const getOrgChild2 = {
|
||||||
orgChild2Id: orgChild2.id,
|
orgChild2Id: orgChild2.id,
|
||||||
|
orgRootName: orgChild2.orgRoot.orgRootName,
|
||||||
|
orgName: `${orgChild2.orgChild2Name}/${orgChild2.orgChild1.orgChild1Name}/${orgChild2.orgRoot.orgRootName}`,
|
||||||
orgChild2Name: orgChild2.orgChild2Name,
|
orgChild2Name: orgChild2.orgChild2Name,
|
||||||
orgChild2ShortName: orgChild2.orgChild2ShortName,
|
orgChild2ShortName: orgChild2.orgChild2ShortName,
|
||||||
orgChild2Code: orgChild2.orgChild2Code,
|
orgChild2Code: orgChild2.orgChild2Code,
|
||||||
|
|
@ -68,7 +69,7 @@ export class OrgChild2Controller extends Controller {
|
||||||
orgChild2PhoneIn: orgChild2.orgChild2PhoneIn,
|
orgChild2PhoneIn: orgChild2.orgChild2PhoneIn,
|
||||||
orgChild2Fax: orgChild2.orgChild2Fax,
|
orgChild2Fax: orgChild2.orgChild2Fax,
|
||||||
orgRevisionId: orgChild2.orgRevisionId,
|
orgRevisionId: orgChild2.orgRevisionId,
|
||||||
orgCode: orgRoot.orgRootCode + orgChild2.orgChild2Code,
|
orgCode: orgChild2.orgRoot.orgRootCode + orgChild2.orgChild2Code,
|
||||||
};
|
};
|
||||||
return new HttpSuccess(getOrgChild2);
|
return new HttpSuccess(getOrgChild2);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -46,17 +46,18 @@ export class OrgChild3Controller {
|
||||||
*/
|
*/
|
||||||
@Get("{id}")
|
@Get("{id}")
|
||||||
async GetChild3(@Path() id: string) {
|
async GetChild3(@Path() id: string) {
|
||||||
const orgChild3 = await this.child3Repository.findOne({ where: { id } });
|
const orgChild3 = await this.child3Repository.findOne({
|
||||||
|
where: { id },
|
||||||
|
relations: ["orgRoot", "orgChild1", "orgChild2"],
|
||||||
|
});
|
||||||
if (!orgChild3) {
|
if (!orgChild3) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ 3");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ 3");
|
||||||
}
|
}
|
||||||
const orgRoot = await this.orgRootRepository.findOne({ where: { id: orgChild3.orgRootId } });
|
|
||||||
if (!orgRoot) {
|
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ Root");
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
const getOrgChild3 = {
|
const getOrgChild3 = {
|
||||||
orgChild3Id: orgChild3.id,
|
orgChild3Id: orgChild3.id,
|
||||||
|
orgRootName: orgChild3.orgRoot.orgRootName,
|
||||||
|
orgName: `${orgChild3.orgChild3Name}/${orgChild3.orgChild2.orgChild2Name}/${orgChild3.orgChild1.orgChild1Name}/${orgChild3.orgRoot.orgRootName}`,
|
||||||
orgChild3Name: orgChild3.orgChild3Name,
|
orgChild3Name: orgChild3.orgChild3Name,
|
||||||
orgChild3ShortName: orgChild3.orgChild3ShortName,
|
orgChild3ShortName: orgChild3.orgChild3ShortName,
|
||||||
orgChild3Code: orgChild3.orgChild3Code,
|
orgChild3Code: orgChild3.orgChild3Code,
|
||||||
|
|
@ -66,7 +67,7 @@ export class OrgChild3Controller {
|
||||||
orgChild3PhoneIn: orgChild3.orgChild3PhoneIn,
|
orgChild3PhoneIn: orgChild3.orgChild3PhoneIn,
|
||||||
orgChild3Fax: orgChild3.orgChild3Fax,
|
orgChild3Fax: orgChild3.orgChild3Fax,
|
||||||
orgRevisionId: orgChild3.orgRevisionId,
|
orgRevisionId: orgChild3.orgRevisionId,
|
||||||
orgCode: orgRoot.orgRootCode + orgChild3.orgChild3Code,
|
orgCode: orgChild3.orgRoot.orgRootCode + orgChild3.orgChild3Code,
|
||||||
};
|
};
|
||||||
return new HttpSuccess(getOrgChild3);
|
return new HttpSuccess(getOrgChild3);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -48,17 +48,18 @@ export class OrgChild4Controller extends Controller {
|
||||||
*/
|
*/
|
||||||
@Get("{id}")
|
@Get("{id}")
|
||||||
async GetChild4(@Path() id: string) {
|
async GetChild4(@Path() id: string) {
|
||||||
const orgChild4 = await this.child4Repository.findOne({ where: { id } });
|
const orgChild4 = await this.child4Repository.findOne({
|
||||||
|
where: { id },
|
||||||
|
relations: ["orgRoot", "orgChild1", "orgChild2", "orgChild3"],
|
||||||
|
});
|
||||||
if (!orgChild4) {
|
if (!orgChild4) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ 4");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ 4");
|
||||||
}
|
}
|
||||||
const orgRoot = await this.orgRootRepository.findOne({ where: { id: orgChild4.orgRootId } });
|
|
||||||
if (!orgRoot) {
|
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ Root");
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
const getOrgChild4 = {
|
const getOrgChild4 = {
|
||||||
orgChild4Id: orgChild4.id,
|
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,
|
orgChild4Name: orgChild4.orgChild4Name,
|
||||||
orgChild4ShortName: orgChild4.orgChild4ShortName,
|
orgChild4ShortName: orgChild4.orgChild4ShortName,
|
||||||
orgChild4Code: orgChild4.orgChild4Code,
|
orgChild4Code: orgChild4.orgChild4Code,
|
||||||
|
|
@ -68,7 +69,7 @@ export class OrgChild4Controller extends Controller {
|
||||||
orgChild4PhoneIn: orgChild4.orgChild4PhoneIn,
|
orgChild4PhoneIn: orgChild4.orgChild4PhoneIn,
|
||||||
orgChild4Fax: orgChild4.orgChild4Fax,
|
orgChild4Fax: orgChild4.orgChild4Fax,
|
||||||
orgRevisionId: orgChild4.orgRevisionId,
|
orgRevisionId: orgChild4.orgRevisionId,
|
||||||
orgCode: orgRoot.orgRootCode + orgChild4.orgChild4Code,
|
orgCode: orgChild4.orgRoot.orgRootCode + orgChild4.orgChild4Code,
|
||||||
};
|
};
|
||||||
return new HttpSuccess(getOrgChild4);
|
return new HttpSuccess(getOrgChild4);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ export class OrgRootController extends Controller {
|
||||||
const getOrgRoot = {
|
const getOrgRoot = {
|
||||||
orgRootId: orgRoot.id,
|
orgRootId: orgRoot.id,
|
||||||
orgRootName: orgRoot.orgRootName,
|
orgRootName: orgRoot.orgRootName,
|
||||||
|
orgName: "-",
|
||||||
orgRootShortName: orgRoot.orgRootShortName,
|
orgRootShortName: orgRoot.orgRootShortName,
|
||||||
orgRootCode: orgRoot.orgRootCode,
|
orgRootCode: orgRoot.orgRootCode,
|
||||||
orgRootRank: orgRoot.orgRootRank,
|
orgRootRank: orgRoot.orgRootRank,
|
||||||
|
|
|
||||||
|
|
@ -595,6 +595,7 @@ export class OrganizationController extends Controller {
|
||||||
orgTreePhoneIn: orgChild2.orgChild2PhoneIn,
|
orgTreePhoneIn: orgChild2.orgChild2PhoneIn,
|
||||||
orgTreeFax: orgChild2.orgChild2Fax,
|
orgTreeFax: orgChild2.orgChild2Fax,
|
||||||
orgRevisionId: orgRoot.orgRevisionId,
|
orgRevisionId: orgRoot.orgRevisionId,
|
||||||
|
orgRootName: orgRoot.orgRootName,
|
||||||
children: orgChild3Data
|
children: orgChild3Data
|
||||||
.filter((orgChild3) => orgChild3.orgChild2Id === orgChild2.id)
|
.filter((orgChild3) => orgChild3.orgChild2Id === orgChild2.id)
|
||||||
.map((orgChild3) => ({
|
.map((orgChild3) => ({
|
||||||
|
|
@ -802,119 +803,119 @@ export class OrganizationController extends Controller {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Post("sort")
|
@Post("sort")
|
||||||
async Sort(
|
async Sort(@Body() requestBody: { id: string; type: number; sortId: string[] }) {
|
||||||
@Body() requestBody: {
|
|
||||||
id: string, type: number, sortId: string[]
|
|
||||||
}
|
|
||||||
){
|
|
||||||
try {
|
try {
|
||||||
switch(requestBody.type){
|
switch (requestBody.type) {
|
||||||
case 0 :{
|
case 0: {
|
||||||
const revisionId = await this.orgRevisionRepository.findOne({ where: {id : requestBody.id} })
|
const revisionId = await this.orgRevisionRepository.findOne({
|
||||||
if(!revisionId?.id){
|
where: { id: requestBody.id },
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found revisionId: "+ requestBody.id);
|
});
|
||||||
|
if (!revisionId?.id) {
|
||||||
|
throw new HttpError(
|
||||||
|
HttpStatusCode.NOT_FOUND,
|
||||||
|
"not found revisionId: " + requestBody.id,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
const listRootId = await this.orgRootRepository.find({
|
const listRootId = await this.orgRootRepository.find({
|
||||||
where: { orgRevisionId: requestBody.id},
|
where: { orgRevisionId: requestBody.id },
|
||||||
select: ["id", "orgRootOrder"],
|
select: ["id", "orgRootOrder"],
|
||||||
})
|
});
|
||||||
if(!listRootId){
|
if (!listRootId) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found rootId.");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found rootId.");
|
||||||
}
|
}
|
||||||
const sortData = listRootId.map((data) => ({
|
const sortData = listRootId.map((data) => ({
|
||||||
id : data.id,
|
id: data.id,
|
||||||
orgRootOrder: requestBody.sortId.indexOf(data.id) + 1
|
orgRootOrder: requestBody.sortId.indexOf(data.id) + 1,
|
||||||
}));
|
}));
|
||||||
await this.orgRootRepository.save(sortData);
|
await this.orgRootRepository.save(sortData);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 1 :{
|
case 1: {
|
||||||
const rootId = await this.orgRootRepository.findOne({ where: {id : requestBody.id} })
|
const rootId = await this.orgRootRepository.findOne({ where: { id: requestBody.id } });
|
||||||
if(!rootId?.id){
|
if (!rootId?.id) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found rootId: "+ requestBody.id);
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found rootId: " + requestBody.id);
|
||||||
}
|
}
|
||||||
const listChild1Id = await this.child1Repository.find({
|
const listChild1Id = await this.child1Repository.find({
|
||||||
where: { orgRootId: requestBody.id},
|
where: { orgRootId: requestBody.id },
|
||||||
select: ["id", "orgChild1Order"],
|
select: ["id", "orgChild1Order"],
|
||||||
})
|
});
|
||||||
if(!listChild1Id){
|
if (!listChild1Id) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child1Id.");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child1Id.");
|
||||||
}
|
}
|
||||||
const sortData = listChild1Id.map((data) => ({
|
const sortData = listChild1Id.map((data) => ({
|
||||||
id : data.id,
|
id: data.id,
|
||||||
orgChild1Order: requestBody.sortId.indexOf(data.id) + 1
|
orgChild1Order: requestBody.sortId.indexOf(data.id) + 1,
|
||||||
}));
|
}));
|
||||||
await this.child1Repository.save(sortData);
|
await this.child1Repository.save(sortData);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 2 :{
|
case 2: {
|
||||||
const child1Id = await this.child1Repository.findOne({ where: {id : requestBody.id} })
|
const child1Id = await this.child1Repository.findOne({ where: { id: requestBody.id } });
|
||||||
if(!child1Id?.id){
|
if (!child1Id?.id) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child1Id: "+ requestBody.id);
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child1Id: " + requestBody.id);
|
||||||
}
|
}
|
||||||
const listChild2Id = await this.child2Repository.find({
|
const listChild2Id = await this.child2Repository.find({
|
||||||
where: { orgChild1Id: requestBody.id},
|
where: { orgChild1Id: requestBody.id },
|
||||||
select: ["id", "orgChild2Order"],
|
select: ["id", "orgChild2Order"],
|
||||||
})
|
});
|
||||||
if(!listChild2Id){
|
if (!listChild2Id) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child2Id.");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child2Id.");
|
||||||
}
|
}
|
||||||
const sortData = listChild2Id.map((data) => ({
|
const sortData = listChild2Id.map((data) => ({
|
||||||
id : data.id,
|
id: data.id,
|
||||||
orgChild2Order: requestBody.sortId.indexOf(data.id) + 1
|
orgChild2Order: requestBody.sortId.indexOf(data.id) + 1,
|
||||||
}));
|
}));
|
||||||
await this.child2Repository.save(sortData);
|
await this.child2Repository.save(sortData);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 3 :{
|
case 3: {
|
||||||
const child2Id = await this.child2Repository.findOne({ where: {id : requestBody.id} })
|
const child2Id = await this.child2Repository.findOne({ where: { id: requestBody.id } });
|
||||||
if(!child2Id?.id){
|
if (!child2Id?.id) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child2Id: "+ requestBody.id);
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child2Id: " + requestBody.id);
|
||||||
}
|
}
|
||||||
const listChild3Id = await this.child3Repository.find({
|
const listChild3Id = await this.child3Repository.find({
|
||||||
where: { orgChild2Id: requestBody.id},
|
where: { orgChild2Id: requestBody.id },
|
||||||
select: ["id", "orgChild3Order"],
|
select: ["id", "orgChild3Order"],
|
||||||
})
|
});
|
||||||
if(!listChild3Id){
|
if (!listChild3Id) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child3Id.");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child3Id.");
|
||||||
}
|
}
|
||||||
const sortData = listChild3Id.map((data) => ({
|
const sortData = listChild3Id.map((data) => ({
|
||||||
id : data.id,
|
id: data.id,
|
||||||
orgChild3Order: requestBody.sortId.indexOf(data.id) + 1
|
orgChild3Order: requestBody.sortId.indexOf(data.id) + 1,
|
||||||
}));
|
}));
|
||||||
await this.child3Repository.save(sortData);
|
await this.child3Repository.save(sortData);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 4 :{
|
case 4: {
|
||||||
const child3Id = await this.child3Repository.findOne({ where: {id : requestBody.id} })
|
const child3Id = await this.child3Repository.findOne({ where: { id: requestBody.id } });
|
||||||
if(!child3Id?.id){
|
if (!child3Id?.id) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child3Id: "+ requestBody.id);
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child3Id: " + requestBody.id);
|
||||||
}
|
}
|
||||||
const listChild4Id = await this.child4Repository.find({
|
const listChild4Id = await this.child4Repository.find({
|
||||||
where: { orgChild3Id: requestBody.id},
|
where: { orgChild3Id: requestBody.id },
|
||||||
select: ["id", "orgChild4Order"],
|
select: ["id", "orgChild4Order"],
|
||||||
})
|
});
|
||||||
if(!listChild4Id){
|
if (!listChild4Id) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child4Id.");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child4Id.");
|
||||||
}
|
}
|
||||||
const sortData = listChild4Id.map((data) => ({
|
const sortData = listChild4Id.map((data) => ({
|
||||||
id : data.id,
|
id: data.id,
|
||||||
orgChild4Order: requestBody.sortId.indexOf(data.id) + 1
|
orgChild4Order: requestBody.sortId.indexOf(data.id) + 1,
|
||||||
}));
|
}));
|
||||||
await this.child4Repository.save(sortData);
|
await this.child4Repository.save(sortData);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found type: "+ requestBody.type);
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found type: " + requestBody.type);
|
||||||
}
|
}
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
}
|
} catch (error) {
|
||||||
catch(error){
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -418,25 +418,35 @@ export class PositionController extends Controller {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
}
|
}
|
||||||
|
|
||||||
const orgRoot = await this.orgRootRepository.findOne({
|
let orgRoot: any = null;
|
||||||
where: { id: requestBody.orgRootId },
|
if (requestBody.orgRootId != null)
|
||||||
});
|
orgRoot = await this.orgRootRepository.findOne({
|
||||||
if (!orgRoot) {
|
where: { id: requestBody.orgRootId },
|
||||||
const orgChild1 = await this.child1Repository.findOne({
|
|
||||||
where: { id: requestBody.orgChild1Id },
|
|
||||||
});
|
});
|
||||||
if (!orgChild1) {
|
if (!orgRoot) {
|
||||||
const orgChild2 = await this.child2Repository.findOne({
|
let orgChild1: any = null;
|
||||||
where: { id: requestBody.orgChild2Id },
|
if (requestBody.orgChild1Id != null)
|
||||||
|
orgChild1 = await this.child1Repository.findOne({
|
||||||
|
where: { id: requestBody.orgChild1Id },
|
||||||
});
|
});
|
||||||
if (!orgChild2) {
|
if (!orgChild1) {
|
||||||
const orgChild3 = await this.child3Repository.findOne({
|
let orgChild2: any = null;
|
||||||
where: { id: requestBody.orgChild3Id },
|
if (requestBody.orgChild2Id != null)
|
||||||
|
orgChild2 = await this.child2Repository.findOne({
|
||||||
|
where: { id: requestBody.orgChild2Id },
|
||||||
});
|
});
|
||||||
if (!orgChild3) {
|
if (!orgChild2) {
|
||||||
const orgChild4 = await this.child4Repository.findOne({
|
let orgChild3: any = null;
|
||||||
where: { id: requestBody.orgChild4Id },
|
if (requestBody.orgChild3Id != null)
|
||||||
|
orgChild3 = await this.child3Repository.findOne({
|
||||||
|
where: { id: requestBody.orgChild3Id },
|
||||||
});
|
});
|
||||||
|
if (!orgChild3) {
|
||||||
|
let orgChild4: any = null;
|
||||||
|
if (requestBody.orgChild4Id != null)
|
||||||
|
orgChild4 = await this.child4Repository.findOne({
|
||||||
|
where: { id: requestBody.orgChild4Id },
|
||||||
|
});
|
||||||
if (!orgChild4) {
|
if (!orgChild4) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้าง");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้าง");
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -541,25 +551,35 @@ export class PositionController extends Controller {
|
||||||
posMaster.orgChild3Id = "";
|
posMaster.orgChild3Id = "";
|
||||||
posMaster.orgChild4Id = "";
|
posMaster.orgChild4Id = "";
|
||||||
|
|
||||||
const orgRoot = await this.orgRootRepository.findOne({
|
let orgRoot: any = null;
|
||||||
where: { id: requestBody.orgRootId },
|
if (requestBody.orgRootId != null)
|
||||||
});
|
orgRoot = await this.orgRootRepository.findOne({
|
||||||
if (!orgRoot) {
|
where: { id: requestBody.orgRootId },
|
||||||
const orgChild1 = await this.child1Repository.findOne({
|
|
||||||
where: { id: requestBody.orgChild1Id },
|
|
||||||
});
|
});
|
||||||
if (!orgChild1) {
|
if (!orgRoot) {
|
||||||
const orgChild2 = await this.child2Repository.findOne({
|
let orgChild1: any = null;
|
||||||
where: { id: requestBody.orgChild2Id },
|
if (requestBody.orgChild1Id != null)
|
||||||
|
orgChild1 = await this.child1Repository.findOne({
|
||||||
|
where: { id: requestBody.orgChild1Id },
|
||||||
});
|
});
|
||||||
if (!orgChild2) {
|
if (!orgChild1) {
|
||||||
const orgChild3 = await this.child3Repository.findOne({
|
let orgChild2: any = null;
|
||||||
where: { id: requestBody.orgChild3Id },
|
if (requestBody.orgChild2Id != null)
|
||||||
|
orgChild2 = await this.child2Repository.findOne({
|
||||||
|
where: { id: requestBody.orgChild2Id },
|
||||||
});
|
});
|
||||||
if (!orgChild3) {
|
if (!orgChild2) {
|
||||||
const orgChild4 = await this.child4Repository.findOne({
|
let orgChild3: any = null;
|
||||||
where: { id: requestBody.orgChild4Id },
|
if (requestBody.orgChild3Id != null)
|
||||||
|
orgChild3 = await this.child3Repository.findOne({
|
||||||
|
where: { id: requestBody.orgChild3Id },
|
||||||
});
|
});
|
||||||
|
if (!orgChild3) {
|
||||||
|
let orgChild4: any = null;
|
||||||
|
if (requestBody.orgChild4Id != null)
|
||||||
|
orgChild4 = await this.child4Repository.findOne({
|
||||||
|
where: { id: requestBody.orgChild4Id },
|
||||||
|
});
|
||||||
if (!orgChild4) {
|
if (!orgChild4) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้าง");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้าง");
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -737,36 +757,38 @@ export class PositionController extends Controller {
|
||||||
const posMaster = await this.posMasterRepository.find({
|
const posMaster = await this.posMasterRepository.find({
|
||||||
where: typeCondition,
|
where: typeCondition,
|
||||||
});
|
});
|
||||||
if (!posMaster || posMaster.length === 0 ) {
|
if (!posMaster || posMaster.length === 0) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
}
|
}
|
||||||
const formattedData = await Promise.all(posMaster.map(async (posMaster) => {
|
const formattedData = await Promise.all(
|
||||||
const positions = await this.positionRepository.find({
|
posMaster.map(async (posMaster) => {
|
||||||
where: { posMasterId: posMaster.id },
|
const positions = await this.positionRepository.find({
|
||||||
});
|
where: { posMasterId: posMaster.id },
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: posMaster.id,
|
id: posMaster.id,
|
||||||
posMasterNoPrefix: posMaster.posMasterNoPrefix,
|
posMasterNoPrefix: posMaster.posMasterNoPrefix,
|
||||||
posMasterNo: posMaster.posMasterNo,
|
posMasterNo: posMaster.posMasterNo,
|
||||||
posMasterNoSuffix: posMaster.posMasterNoSuffix,
|
posMasterNoSuffix: posMaster.posMasterNoSuffix,
|
||||||
positions: positions.map((position) => ({
|
positions: positions.map((position) => ({
|
||||||
id: position.id,
|
id: position.id,
|
||||||
positionName: position.positionName,
|
positionName: position.positionName,
|
||||||
positionField: position.positionField,
|
positionField: position.positionField,
|
||||||
posTypeId: position.posTypeId,
|
posTypeId: position.posTypeId,
|
||||||
posTypeName: position.posType == null ? null : position.posType.posTypeName,
|
posTypeName: position.posType == null ? null : position.posType.posTypeName,
|
||||||
posLevelId: position.posLevelId,
|
posLevelId: position.posLevelId,
|
||||||
posLevelName: position.posLevel == null ? null : position.posLevel.posLevelName,
|
posLevelName: position.posLevel == null ? null : position.posLevel.posLevelName,
|
||||||
posExecutiveId: position.posExecutiveId,
|
posExecutiveId: position.posExecutiveId,
|
||||||
posExecutiveName:
|
posExecutiveName:
|
||||||
position.posExecutive == null ? null : position.posExecutive.posExecutiveName,
|
position.posExecutive == null ? null : position.posExecutive.posExecutiveName,
|
||||||
positionExecutiveField: position.positionExecutiveField,
|
positionExecutiveField: position.positionExecutiveField,
|
||||||
positionArea: position.positionArea,
|
positionArea: position.positionArea,
|
||||||
positionIsSelected: position.positionIsSelected,
|
positionIsSelected: position.positionIsSelected,
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
}));
|
}),
|
||||||
|
);
|
||||||
return new HttpSuccess(formattedData);
|
return new HttpSuccess(formattedData);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error;
|
return error;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue