แก้ไขสิทธิ์
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,11 @@
|
|||
import { Entity, Column, JoinColumn, ManyToOne } from "typeorm";
|
||||
import { Entity, Column, JoinColumn, ManyToOne, OneToMany } from "typeorm";
|
||||
import { EntityBase } from "./base/Base";
|
||||
import { Command } from "./Command";
|
||||
import { Profile } from "./Profile";
|
||||
import { CommandSendCC } from "./CommandSendCC";
|
||||
|
||||
@Entity("commandSend")
|
||||
export class CommandSend extends EntityBase {
|
||||
// EMAIL = อีเมล
|
||||
// INBOX = กล่องข้อความ
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "ช่องทางการส่งสำเนา",
|
||||
length: 20,
|
||||
default: null,
|
||||
})
|
||||
sendCC: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "เลขประจำตัวประชาชน",
|
||||
|
|
@ -82,6 +73,9 @@ export class CommandSend extends EntityBase {
|
|||
@ManyToOne(() => Profile, (profile) => profile.commandSends)
|
||||
@JoinColumn({ name: "profileId" })
|
||||
profile: Profile;
|
||||
|
||||
@OneToMany(() => CommandSendCC, (commandSendCC) => commandSendCC.commandSend)
|
||||
commandSendCCs: CommandSendCC[];
|
||||
}
|
||||
|
||||
export class CreateCommandSend {
|
||||
|
|
|
|||
31
src/entities/CommandSendCC.ts
Normal file
31
src/entities/CommandSendCC.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { Entity, Column, JoinColumn, ManyToOne } from "typeorm";
|
||||
import { EntityBase } from "./base/Base";
|
||||
import { CommandSend } from "./CommandSend";
|
||||
|
||||
@Entity("commandSendCC")
|
||||
export class CommandSendCC extends EntityBase {
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "เพศ",
|
||||
length: 255,
|
||||
default: null,
|
||||
})
|
||||
name: string;
|
||||
|
||||
@Column({
|
||||
length: 40,
|
||||
comment: "คีย์นอก(FK)ของตาราง commandSend",
|
||||
})
|
||||
commandSendId: string;
|
||||
|
||||
@ManyToOne(() => CommandSend, (commandSend) => commandSend.commandSendCCs)
|
||||
@JoinColumn({ name: "commandSendId" })
|
||||
commandSend: CommandSend;
|
||||
}
|
||||
|
||||
export class CreateCommandSendCC {
|
||||
@Column()
|
||||
name: string;
|
||||
}
|
||||
|
||||
export type UpdateCommandSendCC = Partial<CreateCommandSendCC>;
|
||||
|
|
@ -116,6 +116,12 @@ export class OrgChild1 extends EntityBase {
|
|||
})
|
||||
responsibility: string;
|
||||
|
||||
@Column({
|
||||
comment: "เป็นสกจ",
|
||||
default: false,
|
||||
})
|
||||
isOfficer: boolean;
|
||||
|
||||
@ManyToOne(() => OrgRevision, (orgRevision) => orgRevision.orgChild1s)
|
||||
@JoinColumn({ name: "orgRevisionId" })
|
||||
orgRevision: OrgRevision;
|
||||
|
|
@ -167,6 +173,9 @@ export class CreateOrgChild1 {
|
|||
|
||||
@Column()
|
||||
responsibility?: string;
|
||||
|
||||
@Column()
|
||||
isOfficer: boolean;
|
||||
}
|
||||
|
||||
export type UpdateOrgChild1 = Partial<CreateOrgChild1> & { orgChild1Rank?: OrgChild1Rank };
|
||||
|
|
|
|||
18
src/migration/1726209768514-update_child1_add_isOfficer.ts
Normal file
18
src/migration/1726209768514-update_child1_add_isOfficer.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class UpdateChild1AddIsOfficer1726209768514 implements MigrationInterface {
|
||||
name = 'UpdateChild1AddIsOfficer1726209768514'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`employeePosMaster\` DROP COLUMN \`isOfficer\``);
|
||||
await queryRunner.query(`ALTER TABLE \`posMaster\` DROP COLUMN \`isOfficer\``);
|
||||
await queryRunner.query(`ALTER TABLE \`orgChild1\` ADD \`isOfficer\` tinyint NOT NULL COMMENT 'เป็นสกจ' DEFAULT 0`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`orgChild1\` DROP COLUMN \`isOfficer\``);
|
||||
await queryRunner.query(`ALTER TABLE \`posMaster\` ADD \`isOfficer\` tinyint NOT NULL COMMENT 'เป็นสกจ' DEFAULT '0'`);
|
||||
await queryRunner.query(`ALTER TABLE \`employeePosMaster\` ADD \`isOfficer\` tinyint NOT NULL COMMENT 'เป็นสกจ' DEFAULT '0'`);
|
||||
}
|
||||
|
||||
}
|
||||
18
src/migration/1726215497371-update_child1_add_isOfficer1.ts
Normal file
18
src/migration/1726215497371-update_child1_add_isOfficer1.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class UpdateChild1AddIsOfficer11726215497371 implements MigrationInterface {
|
||||
name = 'UpdateChild1AddIsOfficer11726215497371'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`CREATE TABLE \`commandSendCC\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`name\` varchar(255) NULL COMMENT 'เพศ', \`commandSendId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง commandSend', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
|
||||
await queryRunner.query(`ALTER TABLE \`commandSend\` DROP COLUMN \`sendCC\``);
|
||||
await queryRunner.query(`ALTER TABLE \`commandSendCC\` ADD CONSTRAINT \`FK_52f7c9e67d813ba4f8c213f436c\` FOREIGN KEY (\`commandSendId\`) REFERENCES \`commandSend\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`commandSendCC\` DROP FOREIGN KEY \`FK_52f7c9e67d813ba4f8c213f436c\``);
|
||||
await queryRunner.query(`ALTER TABLE \`commandSend\` ADD \`sendCC\` varchar(20) NULL COMMENT 'ช่องทางการส่งสำเนา'`);
|
||||
await queryRunner.query(`DROP TABLE \`commandSendCC\``);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue