api add permission org
This commit is contained in:
parent
91281ba995
commit
c5b54d55de
1 changed files with 46 additions and 0 deletions
|
|
@ -30,6 +30,7 @@ import { checkQueueInProgress, setLogDataDiff } from "../interfaces/utils";
|
|||
import { sendToQueueOrg, sendToQueueOrgDraft } from "../services/rabbitmq";
|
||||
import { PosType } from "../entities/PosType";
|
||||
import { PosLevel } from "../entities/PosLevel";
|
||||
import { PermissionOrg } from "../entities/PermissionOrg";
|
||||
|
||||
@Route("api/v1/org")
|
||||
@Tags("Organization")
|
||||
|
|
@ -49,6 +50,7 @@ export class OrganizationController extends Controller {
|
|||
private profileRepo = AppDataSource.getRepository(Profile);
|
||||
private posTypeRepository = AppDataSource.getRepository(PosType);
|
||||
private posLevelRepository = AppDataSource.getRepository(PosLevel);
|
||||
private permissionOrgRepository = AppDataSource.getRepository(PermissionOrg);
|
||||
|
||||
/**
|
||||
* API ล้างข้อมูล
|
||||
|
|
@ -7869,4 +7871,48 @@ export class OrganizationController extends Controller {
|
|||
posLevelNameOrder: posLevel.map((x) => x.posLevelName),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* API เพิ่มสิทธิ์โครงสร้าง
|
||||
*
|
||||
* @summary - เพิ่มสิทธิ์โครงสร้าง (ADMIN)
|
||||
*
|
||||
*/
|
||||
@Get("root/add/permission/{child1Id}")
|
||||
async addRootPermission(@Path() child1Id: string, @Request() request: RequestWithUser) {
|
||||
const profiles = await this.profileRepo.find({
|
||||
where: {
|
||||
keycloak: Not(IsNull()),
|
||||
current_holders: {
|
||||
orgChild1Id: child1Id,
|
||||
},
|
||||
},
|
||||
});
|
||||
const orgRoots = await this.orgRootRepository.find({
|
||||
where: {
|
||||
orgRevision: {
|
||||
orgRevisionIsDraft: true,
|
||||
orgRevisionIsCurrent: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
for await (const root of orgRoots) {
|
||||
const _permissionOrg = profiles.map((profile) => {
|
||||
const permission = new PermissionOrg();
|
||||
permission.orgRootId = root.id;
|
||||
permission.profileId = profile.id;
|
||||
permission.createdUserId = request.user.sub;
|
||||
permission.createdFullName = request.user.name;
|
||||
permission.lastUpdateUserId = request.user.sub;
|
||||
permission.lastUpdateFullName = request.user.name;
|
||||
permission.createdAt = new Date();
|
||||
permission.lastUpdatedAt = new Date();
|
||||
return permission;
|
||||
});
|
||||
await this.permissionOrgRepository.save(_permissionOrg);
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue