role โครงสร้างอัตรากำลัง

This commit is contained in:
AdisakKanthawilang 2024-08-16 17:36:08 +07:00
parent deb8194b7f
commit 2ce5138a4f
9 changed files with 109 additions and 48 deletions

View file

@ -30,6 +30,8 @@ import { PosMaster } from "../entities/PosMaster";
import { Position } from "../entities/Position";
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { EmployeePosition } from "../entities/EmployeePosition";
import { RequestWithUser } from "../middlewares/user";
import permission from "../interfaces/permission";
@Route("api/v1/org/child2")
@Tags("OrgChild2")
@Security("bearerAuth")
@ -108,8 +110,9 @@ export class OrgChild2Controller extends Controller {
async create(
@Body()
requestBody: CreateOrgChild2,
@Request() request: { user: Record<string, any> },
@Request() request: RequestWithUser,
) {
await new permission().PermissionCreate(request, "SYS_ORG");
const child1 = await this.child1Repository.findOne({
where: { id: requestBody.orgChild1Id },
});
@ -183,8 +186,9 @@ export class OrgChild2Controller extends Controller {
@Path() id: string,
@Body()
requestBody: UpdateOrgChild2,
@Request() request: { user: Record<string, any> },
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "SYS_ORG");
const child1IdExits = await this.child1Repository.findOne({
where: { id: requestBody.orgChild1Id },
});
@ -239,7 +243,8 @@ export class OrgChild2Controller extends Controller {
* @param {string} id Guid, *Id Child2
*/
@Delete("{id}")
async delete(@Path() id: string) {
async delete(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionDelete(request, "SYS_ORG");
const child2 = await this.child2Repository.findOne({ where: { id } });
if (!child2) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
@ -280,7 +285,7 @@ export class OrgChild2Controller extends Controller {
const empPositions = await this.empPositionRepository.find({
where: [{ posMasterId: In(empPosMasters.map((x) => x.id)) }],
});
await this.empPositionRepository.remove(empPositions);
await this.empPosMasterRepository.remove(empPosMasters);
await this.positionRepository.remove(positions);