แก้ไขสิทธิ์
This commit is contained in:
parent
4641362b95
commit
0024ed9414
9 changed files with 154 additions and 27 deletions
|
|
@ -25,6 +25,7 @@ import { CommandSend } from "../entities/CommandSend";
|
|||
import { Profile } from "../entities/Profile";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { OrgRevision } from "../entities/OrgRevision";
|
||||
import { CommandSendCC } from "../entities/CommandSendCC";
|
||||
|
||||
@Route("api/v1/org/command")
|
||||
@Tags("Command")
|
||||
|
|
@ -38,6 +39,7 @@ export class CommandController extends Controller {
|
|||
private commandRepository = AppDataSource.getRepository(Command);
|
||||
private commandTypeRepository = AppDataSource.getRepository(CommandType);
|
||||
private commandSendRepository = AppDataSource.getRepository(CommandSend);
|
||||
private commandSendCCRepository = AppDataSource.getRepository(CommandSendCC);
|
||||
private profileRepository = AppDataSource.getRepository(Profile);
|
||||
private orgRevisionRepo = AppDataSource.getRepository(OrgRevision);
|
||||
|
||||
|
|
@ -232,7 +234,7 @@ export class CommandController extends Controller {
|
|||
async GetByIdTab3(@Path() id: string) {
|
||||
const command = await this.commandRepository.findOne({
|
||||
where: { id },
|
||||
relations: ["commandSends"],
|
||||
relations: ["commandSends", "commandSends.commandSendCCs"],
|
||||
});
|
||||
if (!command) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
|
||||
|
|
@ -246,7 +248,7 @@ export class CommandController extends Controller {
|
|||
lastName: item.lastName,
|
||||
position: item.position,
|
||||
org: item.org,
|
||||
sendCC: item.sendCC,
|
||||
sendCC: item.commandSendCCs.map((x) => x.name),
|
||||
profileId: item.profileId,
|
||||
}));
|
||||
return new HttpSuccess(_command);
|
||||
|
|
@ -330,7 +332,7 @@ export class CommandController extends Controller {
|
|||
requestBody: {
|
||||
commandSend: {
|
||||
id: string;
|
||||
sendCC: string;
|
||||
sendCC: string[];
|
||||
}[];
|
||||
},
|
||||
@Request() request: RequestWithUser,
|
||||
|
|
@ -342,16 +344,25 @@ export class CommandController extends Controller {
|
|||
|
||||
await Promise.all(
|
||||
requestBody.commandSend.map(async (item) => {
|
||||
const commandSend = await this.commandSendRepository.findOne({
|
||||
where: { id: item.id },
|
||||
const commandSendCC = await this.commandSendCCRepository.find({
|
||||
where: { commandSendId: item.id },
|
||||
});
|
||||
if (!commandSend) return;
|
||||
await this.commandSendCCRepository.remove(commandSendCC);
|
||||
|
||||
commandSend.sendCC = item.sendCC;
|
||||
commandSend.lastUpdateUserId = request.user.sub;
|
||||
commandSend.lastUpdateFullName = request.user.name;
|
||||
commandSend.lastUpdatedAt = new Date();
|
||||
await this.commandSendRepository.save(commandSend);
|
||||
await Promise.all(
|
||||
item.sendCC.map(async (item1) => {
|
||||
const _commandSendCC = new CommandSendCC();
|
||||
_commandSendCC.name = item1;
|
||||
_commandSendCC.commandSendId = item.id;
|
||||
_commandSendCC.createdUserId = request.user.sub;
|
||||
_commandSendCC.createdFullName = request.user.name;
|
||||
_commandSendCC.createdAt = new Date();
|
||||
_commandSendCC.lastUpdateUserId = request.user.sub;
|
||||
_commandSendCC.lastUpdateFullName = request.user.name;
|
||||
_commandSendCC.lastUpdatedAt = new Date();
|
||||
await this.commandSendCCRepository.save(_commandSendCC);
|
||||
}),
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ export class CommandTypeController extends Controller {
|
|||
where: { id: requestBody.commandSysId },
|
||||
});
|
||||
|
||||
if (checkNameSys) {
|
||||
if (!checkNameSys) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อประเภทนี้มีอยู่ในระบบ");
|
||||
}
|
||||
|
||||
|
|
@ -190,7 +190,7 @@ export class CommandTypeController extends Controller {
|
|||
where: { id: requestBody.commandSysId },
|
||||
});
|
||||
|
||||
if (checkNameSys) {
|
||||
if (!checkNameSys) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อประเภทนี้มีอยู่ในระบบ");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@ export class OrgChild1Controller {
|
|||
orgChild1PhoneIn: orgChild1.orgChild1PhoneIn,
|
||||
orgChild1Fax: orgChild1.orgChild1Fax,
|
||||
orgRevisionId: orgChild1.orgRevisionId,
|
||||
isOfficer: orgChild1.isOfficer,
|
||||
orgCode: orgChild1.orgRoot.orgRootCode + orgChild1.orgChild1Code,
|
||||
};
|
||||
return new HttpSuccess(getOrgChild1);
|
||||
|
|
@ -97,10 +98,23 @@ export class OrgChild1Controller {
|
|||
await new permission().PermissionCreate(request, "SYS_ORG");
|
||||
const rootIdExits = await this.orgRootRepository.findOne({
|
||||
where: { id: requestBody.orgRootId },
|
||||
relations: ["orgChild1s"],
|
||||
});
|
||||
if (!rootIdExits) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgRootId");
|
||||
}
|
||||
|
||||
if (requestBody.isOfficer == true) {
|
||||
await Promise.all(
|
||||
rootIdExits.orgChild1s
|
||||
.filter((x: OrgChild1) => x.isOfficer == true)
|
||||
.map(async (item: OrgChild1) => {
|
||||
item.isOfficer = false;
|
||||
await this.child1Repository.save(item);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
||||
where: { id: rootIdExits.orgRevisionId },
|
||||
});
|
||||
|
|
@ -193,10 +207,23 @@ export class OrgChild1Controller {
|
|||
await new permission().PermissionUpdate(request, "SYS_ORG");
|
||||
const rootIdExits = await this.orgRootRepository.findOne({
|
||||
where: { id: requestBody.orgRootId },
|
||||
relations: ["orgChild1s"],
|
||||
});
|
||||
if (!rootIdExits) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RootId");
|
||||
}
|
||||
|
||||
if (requestBody.isOfficer == true) {
|
||||
await Promise.all(
|
||||
rootIdExits.orgChild1s
|
||||
.filter((x: OrgChild1) => x.isOfficer == true)
|
||||
.map(async (item: OrgChild1) => {
|
||||
item.isOfficer = false;
|
||||
await this.child1Repository.save(item);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
||||
where: { id: rootIdExits.orgRevisionId },
|
||||
});
|
||||
|
|
|
|||
|
|
@ -623,9 +623,8 @@ export class OrganizationController extends Controller {
|
|||
orgRevision.orgRevisionIsCurrent == true &&
|
||||
orgRevision.orgRevisionIsDraft == false
|
||||
) {
|
||||
_data = await new permission().PermissionOrgList(request, "SYS_ORG");
|
||||
await new permission().PermissionList(request, "SYS_ORG");
|
||||
}
|
||||
|
||||
if (_data.root != null) {
|
||||
if (orgRevision.orgRevisionIsDraft == true && orgRevision.orgRevisionIsCurrent == false) {
|
||||
const profile = await this.profileRepo.findOne({
|
||||
|
|
@ -636,7 +635,7 @@ export class OrganizationController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ใช้งานในทะเบียนประวัติ");
|
||||
}
|
||||
_data = {
|
||||
root: [profile.permissionProfiles.map((x) => x.orgRootId)],
|
||||
root: profile.permissionProfiles.map((x) => x.orgRootId),
|
||||
child1: null,
|
||||
child2: null,
|
||||
child3: null,
|
||||
|
|
@ -692,6 +691,7 @@ export class OrganizationController extends Controller {
|
|||
)
|
||||
.select([
|
||||
"orgChild1.id",
|
||||
"orgChild1.isOfficer",
|
||||
"orgChild1.orgChild1Name",
|
||||
"orgChild1.orgChild1ShortName",
|
||||
"orgChild1.orgChild1Code",
|
||||
|
|
@ -943,6 +943,7 @@ export class OrganizationController extends Controller {
|
|||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootName: orgRoot.orgRootName,
|
||||
responsibility: orgChild1.responsibility,
|
||||
isOfficer: orgChild1.isOfficer,
|
||||
labelName:
|
||||
orgChild1.orgChild1Name +
|
||||
" " +
|
||||
|
|
@ -4737,4 +4738,22 @@ export class OrganizationController extends Controller {
|
|||
|
||||
return new HttpSuccess(formattedData);
|
||||
}
|
||||
/**
|
||||
* API เช็คสกจในระบบ
|
||||
*
|
||||
* @summary - เช็คสกจในระบบ (ADMIN)
|
||||
*
|
||||
*/
|
||||
@Get("check/child1/{id}")
|
||||
async findIsOfficerChild1(@Path() id: string, @Request() request: RequestWithUser) {
|
||||
const orgRevision = await this.orgRevisionRepository.findOne({
|
||||
where: { id },
|
||||
relations: ["orgChild1s"],
|
||||
});
|
||||
if (!orgRevision) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
const check = orgRevision.orgChild1s.find((x) => x.isOfficer == true);
|
||||
return new HttpSuccess(check != null);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue