Merge branch 'develop' of github.com:Frappet/bma-ehr-organization into develop

This commit is contained in:
Kittapath 2024-02-06 15:44:16 +07:00
commit 08f2c8753e
10 changed files with 265 additions and 85 deletions

View file

@ -22,7 +22,10 @@ import {
import HttpStatusCode from "../interfaces/http-status";
import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error";
import { Not } from "typeorm";
import { In, Not } from "typeorm";
import { OrgChild4 } from "../entities/OrgChild4";
import { PosMaster } from "../entities/PosMaster";
import { Position } from "../entities/Position";
@Route("api/v1/org/child1")
@Tags("OrgChild1")
@Security("bearerAuth")
@ -36,6 +39,9 @@ export class OrgChild1Controller {
private child1Repository = AppDataSource.getRepository(OrgChild1);
private child2Repository = AppDataSource.getRepository(OrgChild2);
private child3Repository = AppDataSource.getRepository(OrgChild3);
private child4Repository = AppDataSource.getRepository(OrgChild4);
private posMasterRepository = AppDataSource.getRepository(PosMaster);
private positionRepository = AppDataSource.getRepository(Position);
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
/**
@ -240,15 +246,27 @@ export class OrgChild1Controller {
"not found. orgRevisionIsDraft:true, orgRevisionIsCurrent:false",
);
}
const exitsChild2 = await this.child2Repository.findOne({ where: { orgChild1Id: id } });
if (exitsChild2) {
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถลบได้ เนื่องจาก id ผูกกับโครงสร้างระดับ2",
);
}
// const exitsChild2 = await this.child2Repository.findOne({ where: { orgChild1Id: id } });
// if (exitsChild2) {
// throw new HttpError(
// HttpStatusCode.INTERNAL_SERVER_ERROR,
// "ไม่สามารถลบได้ เนื่องจาก id ผูกกับโครงสร้างระดับ2",
// );
// }
try {
await this.child1Repository.remove(child1);
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;

View file

@ -19,11 +19,15 @@ import {
import HttpStatusCode from "../interfaces/http-status";
import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error";
import { In } from "typeorm";
import { OrgRevision } from "../entities/OrgRevision";
import { OrgRoot } from "../entities/OrgRoot";
import { CreateOrgChild2, OrgChild2, UpdateOrgChild2 } from "../entities/OrgChild2";
import { OrgChild1 } from "../entities/OrgChild1";
import { OrgChild3 } from "../entities/OrgChild3";
import { OrgChild4 } from "../entities/OrgChild4";
import { PosMaster } from "../entities/PosMaster";
import { Position } from "../entities/Position";
@Route("api/v1/org/child2")
@Tags("OrgChild2")
@Security("bearerAuth")
@ -37,6 +41,9 @@ export class OrgChild2Controller extends Controller {
private child1Repository = AppDataSource.getRepository(OrgChild1);
private child2Repository = AppDataSource.getRepository(OrgChild2);
private child3Repository = AppDataSource.getRepository(OrgChild3);
private child4Repository = AppDataSource.getRepository(OrgChild4);
private posMasterRepository = AppDataSource.getRepository(PosMaster);
private positionRepository = AppDataSource.getRepository(Position);
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
/**
@ -253,15 +260,26 @@ export class OrgChild2Controller extends Controller {
);
}
const exitsChild3 = await this.child3Repository.findOne({ where: { orgChild2Id: id } });
if (exitsChild3) {
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถลบได้ เนื่องจาก id ผูกกับโครงสร้างระดับ4",
);
}
// const exitsChild3 = await this.child3Repository.findOne({ where: { orgChild2Id: id } });
// if (exitsChild3) {
// throw new HttpError(
// HttpStatusCode.INTERNAL_SERVER_ERROR,
// "ไม่สามารถลบได้ เนื่องจาก id ผูกกับโครงสร้างระดับ4",
// );
// }
try {
await this.child2Repository.remove(child2);
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;

View file

@ -22,6 +22,9 @@ import {
import HttpStatusCode from "../interfaces/http-status";
import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error";
import { In } from "typeorm";
import { PosMaster } from "../entities/PosMaster";
import { Position } from "../entities/Position";
@Route("api/v1/org/child3")
@Tags("OrgChild3")
@Security("bearerAuth")
@ -35,6 +38,8 @@ export class OrgChild3Controller {
private child2Repository = AppDataSource.getRepository(OrgChild2);
private child3Repository = AppDataSource.getRepository(OrgChild3);
private child4Repository = AppDataSource.getRepository(OrgChild4);
private posMasterRepository = AppDataSource.getRepository(PosMaster);
private positionRepository = AppDataSource.getRepository(Position);
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
/**
@ -225,15 +230,25 @@ export class OrgChild3Controller {
);
}
const exitsChild4 = await this.child4Repository.findOne({ where: { orgChild3Id: id } });
if (exitsChild4) {
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถลบได้ เนื่องจาก id ผูกกับโครงสร้างระดับ4",
);
}
// const exitsChild4 = await this.child4Repository.findOne({ where: { orgChild3Id: id } });
// if (exitsChild4) {
// throw new HttpError(
// HttpStatusCode.INTERNAL_SERVER_ERROR,
// "ไม่สามารถลบได้ เนื่องจาก id ผูกกับโครงสร้างระดับ4",
// );
// }
try {
await this.child3Repository.remove(child3);
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;

View file

@ -19,11 +19,14 @@ import {
import HttpStatusCode from "../interfaces/http-status";
import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error";
import { In } from "typeorm";
import { OrgRevision } from "../entities/OrgRevision";
import { OrgRoot } from "../entities/OrgRoot";
import { CreateOrgChild4, OrgChild4, UpdateOrgChild4 } from "../entities/OrgChild4";
import { OrgChild1 } from "../entities/OrgChild1";
import { OrgChild3 } from "../entities/OrgChild3";
import { PosMaster } from "../entities/PosMaster";
import { Position } from "../entities/Position";
@Route("api/v1/org/child4")
@Tags("OrgChild4")
@ -37,6 +40,8 @@ export class OrgChild4Controller extends Controller {
private orgRootRepository = AppDataSource.getRepository(OrgRoot);
private child3Repository = AppDataSource.getRepository(OrgChild3);
private child4Repository = AppDataSource.getRepository(OrgChild4);
private posMasterRepository = AppDataSource.getRepository(PosMaster);
private positionRepository = AppDataSource.getRepository(Position);
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
/**
@ -258,7 +263,16 @@ export class OrgChild4Controller extends Controller {
);
}
try {
await this.child4Repository.remove(child4);
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;

View file

@ -728,28 +728,28 @@ export class OrganizationController extends Controller {
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
profileIdCurrentHolder: Not(IsNull()) || Not(""),
current_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionCurrentVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
profileIdCurrentHolder: IsNull() || "",
current_holderId: IsNull() || "",
},
}),
totalPositionNextUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
profileIdNextHolder: Not(IsNull()) || Not(""),
next_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionNextVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
profileIdNextHolder: IsNull() || "",
next_holderId: IsNull() || "",
},
}),
@ -780,28 +780,28 @@ export class OrganizationController extends Controller {
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild1Id: orgChild1.id,
profileIdCurrentHolder: Not(IsNull()) || Not(""),
current_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionCurrentVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild1Id: orgChild1.id,
profileIdCurrentHolder: IsNull() || "",
current_holderId: IsNull() || "",
},
}),
totalPositionNextUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild1Id: orgChild1.id,
profileIdNextHolder: Not(IsNull()) || Not(""),
next_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionNextVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild1Id: orgChild1.id,
profileIdNextHolder: IsNull() || "",
next_holderId: IsNull() || "",
},
}),
children: await Promise.all(
@ -834,28 +834,28 @@ export class OrganizationController extends Controller {
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild2Id: orgChild2.id,
profileIdCurrentHolder: Not(IsNull()) || Not(""),
current_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionCurrentVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild2Id: orgChild2.id,
profileIdCurrentHolder: IsNull() || "",
current_holderId: IsNull() || "",
},
}),
totalPositionNextUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild2Id: orgChild2.id,
profileIdNextHolder: Not(IsNull()) || Not(""),
next_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionNextVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild2Id: orgChild2.id,
profileIdNextHolder: IsNull() || "",
next_holderId: IsNull() || "",
},
}),
children: await Promise.all(
@ -884,25 +884,25 @@ export class OrganizationController extends Controller {
totalPositionCurrentUse: await this.posMasterRepository.count({
where: {
orgChild3Id: orgChild3.id,
profileIdCurrentHolder: Not(IsNull()) || Not(""),
current_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionCurrentVacant: await this.posMasterRepository.count({
where: {
orgChild3Id: orgChild3.id,
profileIdCurrentHolder: IsNull() || "",
current_holderId: IsNull() || "",
},
}),
totalPositionNextUse: await this.posMasterRepository.count({
where: {
orgChild3Id: orgChild3.id,
profileIdNextHolder: Not(IsNull()) || Not(""),
next_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionNextVacant: await this.posMasterRepository.count({
where: {
orgChild3Id: orgChild3.id,
profileIdNextHolder: IsNull() || "",
next_holderId: IsNull() || "",
},
}),
children: await Promise.all(
@ -931,26 +931,26 @@ export class OrganizationController extends Controller {
totalPositionCurrentUse: await this.posMasterRepository.count({
where: {
orgChild4Id: orgChild4.id,
profileIdCurrentHolder: Not(IsNull()) || Not(""),
current_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionCurrentVacant:
await this.posMasterRepository.count({
where: {
orgChild4Id: orgChild4.id,
profileIdCurrentHolder: IsNull() || "",
current_holderId: IsNull() || "",
},
}),
totalPositionNextUse: await this.posMasterRepository.count({
where: {
orgChild4Id: orgChild4.id,
profileIdNextHolder: Not(IsNull()) || Not(""),
next_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionNextVacant: await this.posMasterRepository.count({
where: {
orgChild4Id: orgChild4.id,
profileIdNextHolder: IsNull() || "",
next_holderId: IsNull() || "",
},
}),
})),

View file

@ -1112,25 +1112,25 @@ export class PositionController extends Controller {
totalPositionCurrentUse = await this.posMasterRepository.count({
where: {
orgRootId: requestBody.id,
profileIdCurrentHolder: Not(IsNull()) && Not(""),
current_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgRootId: requestBody.id,
profileIdCurrentHolder: IsNull() && "",
current_holderId: IsNull() && "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgRootId: requestBody.id,
profileIdNextHolder: Not(IsNull()) && Not(""),
next_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgRootId: requestBody.id,
profileIdNextHolder: IsNull() && "",
next_holderId: IsNull() && "",
},
});
break;
@ -1151,25 +1151,25 @@ export class PositionController extends Controller {
totalPositionCurrentUse = await this.posMasterRepository.count({
where: {
orgChild1Id: requestBody.id,
profileIdCurrentHolder: Not(IsNull()) && Not(""),
current_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgChild1Id: requestBody.id,
profileIdCurrentHolder: IsNull() && "",
current_holderId: IsNull() && "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgChild1Id: requestBody.id,
profileIdNextHolder: Not(IsNull()) && Not(""),
next_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgChild1Id: requestBody.id,
profileIdNextHolder: IsNull() && "",
next_holderId: IsNull() && "",
},
});
break;
@ -1190,25 +1190,25 @@ export class PositionController extends Controller {
totalPositionCurrentUse = await this.posMasterRepository.count({
where: {
orgChild2Id: requestBody.id,
profileIdCurrentHolder: Not(IsNull()) && Not(""),
current_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgChild2Id: requestBody.id,
profileIdCurrentHolder: IsNull() && "",
current_holderId: IsNull() && "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgChild2Id: requestBody.id,
profileIdNextHolder: Not(IsNull()) && Not(""),
next_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgChild2Id: requestBody.id,
profileIdNextHolder: IsNull() && "",
next_holderId: IsNull() && "",
},
});
break;
@ -1229,25 +1229,25 @@ export class PositionController extends Controller {
totalPositionCurrentUse = await this.posMasterRepository.count({
where: {
orgChild3Id: requestBody.id,
profileIdCurrentHolder: Not(IsNull()) && Not(""),
current_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgChild3Id: requestBody.id,
profileIdCurrentHolder: IsNull() && "",
current_holderId: IsNull() && "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgChild3Id: requestBody.id,
profileIdNextHolder: Not(IsNull()) && Not(""),
next_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgChild3Id: requestBody.id,
profileIdNextHolder: IsNull() && "",
next_holderId: IsNull() && "",
},
});
break;
@ -1268,25 +1268,25 @@ export class PositionController extends Controller {
totalPositionCurrentUse = await this.posMasterRepository.count({
where: {
orgChild4Id: requestBody.id,
profileIdCurrentHolder: Not(IsNull()) && Not(""),
current_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgChild4Id: requestBody.id,
profileIdCurrentHolder: IsNull() && "",
current_holderId: IsNull() && "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgChild4Id: requestBody.id,
profileIdNextHolder: Not(IsNull()) && Not(""),
next_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgChild4Id: requestBody.id,
profileIdNextHolder: IsNull() && "",
next_holderId: IsNull() && "",
},
});
break;