diff --git a/package-lock.json b/package-lock.json index 4b20d91a..84f21d96 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "node-cron": "^3.0.3", "node-xlsx": "^0.24.0", "promise.any": "^2.0.6", + "redis": "^3.1.2", "reflect-metadata": "^0.2.1", "swagger-ui-express": "^5.0.0", "tsoa": "^6.0.1", @@ -3478,6 +3479,56 @@ "node": ">=8.10.0" } }, + "node_modules/redis": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/redis/-/redis-3.1.2.tgz", + "integrity": "sha512-grn5KoZLr/qrRQVwoSkmzdbw6pwF+/rwODtrOr6vuBRiR/f3rjSTGupbF90Zpqm2oenix8Do6RV7pYEkGwlKkw==", + "dependencies": { + "denque": "^1.5.0", + "redis-commands": "^1.7.0", + "redis-errors": "^1.2.0", + "redis-parser": "^3.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/node-redis" + } + }, + "node_modules/redis-commands": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/redis-commands/-/redis-commands-1.7.0.tgz", + "integrity": "sha512-nJWqw3bTFy21hX/CPKHth6sfhZbdiHP6bTawSgQBlKOVRG7EZkfHbbHwQJnrE4vsQf0CMNE+3gJ4Fmm16vdVlQ==" + }, + "node_modules/redis-errors": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/redis-errors/-/redis-errors-1.2.0.tgz", + "integrity": "sha512-1qny3OExCf0UvUV/5wpYKf2YwPcOqXzkwKKSmKHiE6ZMQs5heeE/c8eXK+PNllPvmjgAbfnsbpkGZWy8cBpn9w==", + "engines": { + "node": ">=4" + } + }, + "node_modules/redis-parser": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/redis-parser/-/redis-parser-3.0.0.tgz", + "integrity": "sha512-DJnGAeenTdpMEH6uAJRK/uiyEIH9WVsUmoLwzudwGJUwZPp80PDBWPHXSAGNPwNvIXAbe7MSUB1zQFugFml66A==", + "dependencies": { + "redis-errors": "^1.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/redis/node_modules/denque": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/denque/-/denque-1.5.1.tgz", + "integrity": "sha512-XwE+iZ4D6ZUB7mfYRMb5wByE8L74HCn30FBN7sWnXksWc1LO1bPDl67pBR9o/kC4z/xSNAwkMYcGgqDV3BE3Hw==", + "engines": { + "node": ">=0.10" + } + }, "node_modules/reflect-metadata": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.2.1.tgz", diff --git a/package.json b/package.json index e950b983..5eb3416e 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "node-cron": "^3.0.3", "node-xlsx": "^0.24.0", "promise.any": "^2.0.6", + "redis": "^3.1.2", "reflect-metadata": "^0.2.1", "swagger-ui-express": "^5.0.0", "tsoa": "^6.0.1", diff --git a/src/controllers/AuthRoleController.ts b/src/controllers/AuthRoleController.ts index 20aa019d..e1ac90d6 100644 --- a/src/controllers/AuthRoleController.ts +++ b/src/controllers/AuthRoleController.ts @@ -22,14 +22,17 @@ import { AuthRoleAttr } from "../entities/AuthRoleAttr"; import { PosMaster } from "../entities/PosMaster"; import { EmployeePosMaster } from "../entities/EmployeePosMaster"; +const REDIS_HOST = process.env.REDIS_HOST; +const REDIS_PORT = process.env.REDIS_PORT; @Route("api/v1/org/auth/authRole") @Tags("AuthRole") @Security("bearerAuth") export class AuthRoleController extends Controller { private authRoleRepo = AppDataSource.getRepository(AuthRole); - private authRoleAttrRepo = AppDataSource.getRepository(AuthRoleAttr); + private authRoleAttrRepo = AppDataSource.getRepository(AuthRoleAttr); private posMasterRepository = AppDataSource.getRepository(PosMaster); - private employeePosMasterRepository = AppDataSource.getRepository(EmployeePosMaster) + private employeePosMasterRepository = AppDataSource.getRepository(EmployeePosMaster); + private redis = require("redis"); @Get("list") public async listAuthRole() { @@ -77,50 +80,51 @@ export class AuthRoleController extends Controller { } @Post("govoment") - public async AddAuthRoleGovoment(@Request() req: RequestWithUser, @Body() body: CreateAddAuthRole) { + public async AddAuthRoleGovoment( + @Request() req: RequestWithUser, + @Body() body: CreateAddAuthRole, + ) { + let NULL_: any = null; + let getDetail; - let NULL_ : any = null; - let getDetail - - if(body.authRoleId == "") { - body.authRoleId = NULL_ - } - else { + if (body.authRoleId == "") { + body.authRoleId = NULL_; + } else { getDetail = await this.authRoleRepo.findOneBy({ id: body.authRoleId }); if (!getDetail) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลสิทธิ์"); } - - const posMaster = await this.posMasterRepository.findOneBy({ id : body.posMasterId }) + + const posMaster = await this.posMasterRepository.findOneBy({ id: body.posMasterId }); if (!posMaster) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลตำแหน่ง"); posMaster.lastUpdateUserId = req.user.sub; posMaster.lastUpdateFullName = req.user.name; - posMaster.authRoleId = body.authRoleId + posMaster.authRoleId = body.authRoleId; await this.posMasterRepository.save(posMaster); return new HttpSuccess(); } @Post("employee") - public async AddAuthRoleEmployee(@Request() req: RequestWithUser, @Body() body: CreateAddAuthRole) { + public async AddAuthRoleEmployee( + @Request() req: RequestWithUser, + @Body() body: CreateAddAuthRole, + ) { + let NULL_: any = null; + let getDetail; - let NULL_ : any = null; - let getDetail - - if(body.authRoleId == "") { - body.authRoleId = NULL_ - } - else { + if (body.authRoleId == "") { + body.authRoleId = NULL_; + } else { getDetail = await this.authRoleRepo.findOneBy({ id: body.authRoleId }); if (!getDetail) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลสิทธิ์"); } - - - const posMaster = await this.employeePosMasterRepository.findOneBy({ id : body.posMasterId }) + + const posMaster = await this.employeePosMasterRepository.findOneBy({ id: body.posMasterId }); if (!posMaster) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลตำแหน่ง"); posMaster.lastUpdateUserId = req.user.sub; posMaster.lastUpdateFullName = req.user.name; - posMaster.authRoleId = body.authRoleId + posMaster.authRoleId = body.authRoleId; await this.employeePosMasterRepository.save(posMaster); return new HttpSuccess(); } diff --git a/src/controllers/ImportDataController.ts b/src/controllers/ImportDataController.ts index 04cd00bb..4635545e 100644 --- a/src/controllers/ImportDataController.ts +++ b/src/controllers/ImportDataController.ts @@ -434,33 +434,33 @@ export class ImportDataController extends Controller { return new HttpSuccess(result); } - // /** - // * @summary Import Education Code - // */ - // @Post("uploadEducation-Code") - // @UseInterceptors(FileInterceptor("file")) - // async UploadFileSQLEducationCode( - // @UploadedFile() file: Express.Multer.File, - // @Request() request: { user: Record }, - // ) { - // const workbook = xlsx.read(file.buffer, { type: "buffer" }); - // const sheetName = workbook.SheetNames[0] - // const sheet = workbook.Sheets[sheetName]; - // const getExcel = xlsx.utils.sheet_to_json(sheet); - // let educationMis_: any = []; + /** + * @summary Import Education Code + */ + @Post("uploadEducation-Code") + @UseInterceptors(FileInterceptor("file")) + async UploadFileSQLEducationCode( + @UploadedFile() file: Express.Multer.File, + @Request() request: { user: Record }, + ) { + const workbook = xlsx.read(file.buffer, { type: "buffer" }); + const sheetName = workbook.SheetNames[0] + const sheet = workbook.Sheets[sheetName]; + const getExcel = xlsx.utils.sheet_to_json(sheet); + let educationMis_: any = []; + + await Promise.all( + getExcel.map(async (item: any) => { + const educationMis = new EducationMis(); + educationMis.EDUCATION_CODE = item.EDUCATION_CODE; + educationMis.EDUCATION_CODE = item.EDUCATION_CODE; + educationMis_.push(educationMis); - // await Promise.all( - // getExcel.map(async (item: any) => { - // const educationMis = new EducationMis(); - // educationMis.EDUCATION_CODE = item.EDUCATION_CODE; - // educationMis.EDUCATION_CODE = item.EDUCATION_CODE; - // educationMis_.push(educationMis); - - // }), - // ); - // await this.educationMisRepo.save(educationMis_); - // return new HttpSuccess(educationMis_); - // } + }), + ); + await this.educationMisRepo.save(educationMis_); + return new HttpSuccess(educationMis_); + } // /** // * API upload EDU diff --git a/src/controllers/PermissionController.ts b/src/controllers/PermissionController.ts index 53935c4c..b5539005 100644 --- a/src/controllers/PermissionController.ts +++ b/src/controllers/PermissionController.ts @@ -9,6 +9,11 @@ import { AuthRole } from "../entities/AuthRole"; import { AuthRoleAttr } from "../entities/AuthRoleAttr"; import { PosMaster } from "../entities/PosMaster"; import { Profile } from "../entities/Profile"; +import { AuthSys } from "../entities/AuthSys"; +import { promisify } from "util"; +import { In } from "typeorm"; +const REDIS_HOST = process.env.REDIS_HOST; +const REDIS_PORT = process.env.REDIS_PORT; @Route("api/v1/org/permission") @Tags("Permission") @@ -18,53 +23,137 @@ export class PermissionController extends Controller { private posMasterRepository = AppDataSource.getRepository(PosMaster); private authRoleRepo = AppDataSource.getRepository(AuthRole); private authRoleAttrRepo = AppDataSource.getRepository(AuthRoleAttr); + private authSysRepo = AppDataSource.getRepository(AuthSys); + private redis = require("redis"); @Get("") public async getPermission(@Request() request: { user: Record }) { - const profile = await this.profileRepo.findOne({ - select: ["id"], - where: { keycloak: request.user.sub }, + const redisClient = await this.redis.createClient({ + host: REDIS_HOST, + port: REDIS_PORT, }); - if (!profile) { - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ"); + const getAsync = promisify(redisClient.get).bind(redisClient); + + let reply = await getAsync("role_" + request.user.sub); + if (reply != null) { + reply = JSON.parse(reply); + } else { + const profile = await this.profileRepo.findOne({ + select: ["id"], + where: { keycloak: request.user.sub }, + }); + if (!profile) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ"); + } + + const posMaster = await this.posMasterRepository.findOne({ + select: ["authRoleId"], + where: { current_holderId: profile.id }, + }); + if (!posMaster) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลสิทธิ์"); + } + + const getDetail = await this.authRoleRepo.findOne({ + select: ["id", "roleName", "roleDescription"], + where: { id: posMaster.authRoleId }, + }); + if (!getDetail) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const roleAttrData = await this.authRoleAttrRepo.find({ + select: [ + "authSysId", + "parentNode", + "attrOwnership", + "attrIsCreate", + "attrIsList", + "attrIsGet", + "attrIsUpdate", + "attrIsDelete", + "attrPrivilege", + ], + where: { authRoleId: getDetail.id }, + }); + + reply = { + ...getDetail, + roles: roleAttrData, + }; + redisClient.set("role_" + request.user.sub, JSON.stringify(reply)); + } + return new HttpSuccess(reply); + } + + @Get("menu") + public async listAuthSys(@Request() request: { user: Record }) { + const redisClient = await this.redis.createClient({ + host: REDIS_HOST, + port: REDIS_PORT, + }); + const getAsync = promisify(redisClient.get).bind(redisClient); + + let reply = await getAsync("menu_" + request.user.sub); + if (reply != null) { + reply = JSON.parse(reply); + } else { + console.log(request.user.sub); + const profile = await this.profileRepo.findOne({ + select: ["id"], + where: { keycloak: request.user.sub }, + }); + if (!profile) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ"); + } + const posMaster = await this.posMasterRepository.findOne({ + // select: ["authRoleId"], + where: { + current_holderId: profile.id, + orgRevision: { + orgRevisionIsDraft: false, + orgRevisionIsCurrent: true, + }, + }, + }); + if (!posMaster) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งในโครงสร้าง"); + } + + const authRole = await this.authRoleRepo.findOne({ + select: ["id"], + where: { id: posMaster.authRoleId }, + }); + if (!authRole) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลสิทธิ์"); + } + const roleAttrData = await this.authRoleAttrRepo.find({ + select: ["authSysId"], + where: { authRoleId: authRole.id }, + }); + + const getList = await this.authSysRepo.find({ + select: ["id", "parentId", "sysName", "sysDescription", "icon", "path", "order"], + where: { + id: In(roleAttrData.map((x) => x.authSysId)), + }, + }); + + const reply = getList + .filter((x) => x.parentId == null) + .map((item) => { + return { + ...item, + children: getList + .filter((x) => x.parentId == item.id) + .sort((a, b) => a.order - b.order), + }; + }) + .sort((a, b) => a.order - b.order); + console.log(JSON.stringify(reply)); + redisClient.set("menu_" + request.user.sub, 30, JSON.stringify(reply)); } - const posMaster = await this.posMasterRepository.findOne({ - select: ["authRoleId"], - where: { current_holderId: profile.id }, - }); - if (!posMaster) { - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลสิทธิ์"); - } - - const getDetail = await this.authRoleRepo.findOne({ - select: ["roleName", "roleDescription"], - where: { id: posMaster.authRoleId }, - }); - if (!getDetail) { - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - } - - const roleAttrData = await this.authRoleAttrRepo.find({ - select: [ - "authSysId", - "parentNode", - "attrOwnership", - "attrIsCreate", - "attrIsList", - "attrIsGet", - "attrIsUpdate", - "attrIsDelete", - "attrPrivilege", - ], - where: { authRoleId: getDetail.id }, - }); - - const formattedData = { - ...getDetail, - roleAttributes: roleAttrData, - }; - - return new HttpSuccess(formattedData); + return new HttpSuccess(reply); } } diff --git a/src/controllers/ProfileEditEmployeeController.ts b/src/controllers/ProfileEditEmployeeController.ts index 36668ed5..01d2fc98 100644 --- a/src/controllers/ProfileEditEmployeeController.ts +++ b/src/controllers/ProfileEditEmployeeController.ts @@ -52,26 +52,20 @@ export class ProfileEditEmployeeController extends Controller { if (status != "" && status != null) { qb.andWhere("ProfileEdit.status = :status", { status: status }); } - qb.andWhere("ProfileEdit.profileEmployeeId = :profileEmployeeId", { profileEmployeeId: profile.id }); + qb.andWhere("ProfileEdit.profileEmployeeId = :profileEmployeeId", { + profileEmployeeId: profile.id, + }); }) .andWhere( new Brackets((qb) => { - qb.where( - keyword != "" && keyword != null - ? "ProfileEdit.topic LIKE :keyword" - : "1=1", + qb.where(keyword != "" && keyword != null ? "ProfileEdit.topic LIKE :keyword" : "1=1", { + keyword: `%${keyword}%`, + }).orWhere( + keyword != "" && keyword != null ? "ProfileEdit.detail LIKE :keyword" : "1=1", { keyword: `%${keyword}%`, }, - ) - .orWhere( - keyword != "" && keyword != null - ? "ProfileEdit.detail LIKE :keyword" - : "1=1", - { - keyword: `%${keyword}%`, - }, - ) + ); }), ) .orderBy("ProfileEdit.createdAt", "ASC") @@ -118,22 +112,14 @@ export class ProfileEditEmployeeController extends Controller { }) .andWhere( new Brackets((qb) => { - qb.where( - keyword != "" && keyword != null - ? "ProfileEdit.topic LIKE :keyword" - : "1=1", + qb.where(keyword != "" && keyword != null ? "ProfileEdit.topic LIKE :keyword" : "1=1", { + keyword: `%${keyword}%`, + }).orWhere( + keyword != "" && keyword != null ? "ProfileEdit.detail LIKE :keyword" : "1=1", { keyword: `%${keyword}%`, }, - ) - .orWhere( - keyword != "" && keyword != null - ? "ProfileEdit.detail LIKE :keyword" - : "1=1", - { - keyword: `%${keyword}%`, - }, - ) + ); }), ) .orderBy("ProfileEdit.createdAt", "ASC") @@ -162,7 +148,7 @@ export class ProfileEditEmployeeController extends Controller { } @Get("{Id}") - public async detailProfileByIdEdit(@Path() Id: string) { + public async detailProfileEmployeeByIdEdit(@Path() Id: string) { const getProfileEdit = await this.profileEditRepository.findOne({ where: { id: Id }, }); @@ -233,7 +219,7 @@ export class ProfileEditEmployeeController extends Controller { ) { // const record = await this.profileEditRepository.findOneBy({ id: editId }); const record = await this.profileEditRepository.findOne({ - where: { id: editId } + where: { id: editId }, }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); diff --git a/src/controllers/backup-employee-temp-bmaStatic40k.xlsx b/src/controllers/backup-employee-temp-bmaStatic40k.xlsx new file mode 100644 index 00000000..aa59e232 Binary files /dev/null and b/src/controllers/backup-employee-temp-bmaStatic40k.xlsx differ diff --git a/src/entities/AuthRole.ts b/src/entities/AuthRole.ts index 8ee0b4a1..e6de3abc 100644 --- a/src/entities/AuthRole.ts +++ b/src/entities/AuthRole.ts @@ -26,10 +26,10 @@ export class AuthRole extends EntityBase { authRoles: AuthRoleAttr[]; @OneToMany(() => PosMaster, (posMaster) => posMaster.authRole) - posMaster: PosMaster[]; + posMasters: PosMaster[]; @OneToMany(() => EmployeePosMaster, (posMasters) => posMasters.authRole) - posMasterEmp: EmployeePosMaster[]; + posMasterEmps: EmployeePosMaster[]; } export class CreateAuthRole { @@ -48,4 +48,4 @@ export class CreateAddAuthRole { @Column() posMasterId: string; -} \ No newline at end of file +} diff --git a/src/entities/AuthRoleAttr.ts b/src/entities/AuthRoleAttr.ts index a6022079..78fd9372 100644 --- a/src/entities/AuthRoleAttr.ts +++ b/src/entities/AuthRoleAttr.ts @@ -75,9 +75,9 @@ export class AuthRoleAttr extends EntityBase { }) parentNode?: string; - // @ManyToOne(() => AuthSys, (authSys) => authSys.authSys) - // @JoinColumn({ name: "authSysId" }) - // authRoleAttrForSys: AuthSys; + @ManyToOne(() => AuthSys, (authSys) => authSys.authRoleAttrs) + @JoinColumn({ name: "authSysId" }) + authRoleAttrForSys: AuthSys; @ManyToOne(() => AuthRole, (authRole) => authRole.authRoles) @JoinColumn({ name: "authRoleId" }) diff --git a/src/entities/AuthSys.ts b/src/entities/AuthSys.ts index 3626578f..e6704f2a 100644 --- a/src/entities/AuthSys.ts +++ b/src/entities/AuthSys.ts @@ -1,4 +1,12 @@ -import { Entity, Column, CreateDateColumn, UpdateDateColumn, PrimaryColumn } from "typeorm"; +import { + Entity, + Column, + CreateDateColumn, + UpdateDateColumn, + PrimaryColumn, + OneToMany, +} from "typeorm"; +import { AuthRoleAttr } from "./AuthRoleAttr"; @Entity("authSys") export class AuthSys { @@ -80,8 +88,8 @@ export class AuthSys { }) sysDescription: string; - // @OneToMany(() => AuthRoleAttr, (authRoleAttr) => authRoleAttr.authRoleAttrForSys) - // authSys: AuthRoleAttr[]; + @OneToMany(() => AuthRoleAttr, (authRoleAttr) => authRoleAttr.authRoleAttrForSys) + authRoleAttrs: AuthRoleAttr[]; } export class CreateAuthSys { diff --git a/src/entities/EmployeePosMaster.ts b/src/entities/EmployeePosMaster.ts index 3b8a59d3..5401bf53 100644 --- a/src/entities/EmployeePosMaster.ts +++ b/src/entities/EmployeePosMaster.ts @@ -180,7 +180,7 @@ export class EmployeePosMaster extends EntityBase { }) authRoleId: string; - @ManyToOne(() => AuthRole, (authRole) => authRole.posMasterEmp) + @ManyToOne(() => AuthRole, (authRole) => authRole.posMasterEmps) @JoinColumn({ name: "authRoleId" }) authRole: AuthRole; diff --git a/src/entities/PosMaster.ts b/src/entities/PosMaster.ts index d3895306..cae1a556 100644 --- a/src/entities/PosMaster.ts +++ b/src/entities/PosMaster.ts @@ -180,7 +180,7 @@ export class PosMaster extends EntityBase { }) authRoleId: string; - @ManyToOne(() => AuthRole, (authRole) => authRole.posMaster) + @ManyToOne(() => AuthRole, (authRole) => authRole.posMasters) @JoinColumn({ name: "authRoleId" }) authRole: AuthRole; diff --git a/src/migration/1721872671794-update_table_authSys_add_key.ts b/src/migration/1721872671794-update_table_authSys_add_key.ts new file mode 100644 index 00000000..8b0820f6 --- /dev/null +++ b/src/migration/1721872671794-update_table_authSys_add_key.ts @@ -0,0 +1,28 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableAuthSysAddKey1721872671794 implements MigrationInterface { + name = 'UpdateTableAuthSysAddKey1721872671794' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`authRoleAttr\` CHANGE \`attrOwnership\` \`attrOwnership\` varchar(255) NULL COMMENT 'ความเป็นเจ้าของ (Ownership)'`); + await queryRunner.query(`ALTER TABLE \`authRoleAttr\` CHANGE \`attrIsCreate\` \`attrIsCreate\` tinyint NOT NULL COMMENT 'สิทธิ์ดำเนินการ (Permission) การ Create' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`authRoleAttr\` CHANGE \`attrIsList\` \`attrIsList\` tinyint NOT NULL COMMENT 'สิทธิ์ดำเนินการ (Permission) การ List' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`authRoleAttr\` CHANGE \`attrIsGet\` \`attrIsGet\` tinyint NOT NULL COMMENT 'สิทธิ์ดำเนินการ (Permission) การ Get' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`authRoleAttr\` CHANGE \`attrIsUpdate\` \`attrIsUpdate\` tinyint NOT NULL COMMENT 'สิทธิ์ดำเนินการ (Permission) การ Update' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`authRoleAttr\` CHANGE \`attrIsDelete\` \`attrIsDelete\` tinyint NOT NULL COMMENT 'สิทธิ์ดำเนินการ (Permission) การ Delete' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`authRoleAttr\` CHANGE \`attrPrivilege\` \`attrPrivilege\` varchar(255) NULL COMMENT 'สิทธิการเข้าถึง(Privilege)'`); + await queryRunner.query(`ALTER TABLE \`authRoleAttr\` ADD CONSTRAINT \`FK_b5b59c60792d518f4f025379dba\` FOREIGN KEY (\`authSysId\`) REFERENCES \`authSys\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`authRoleAttr\` DROP FOREIGN KEY \`FK_b5b59c60792d518f4f025379dba\``); + await queryRunner.query(`ALTER TABLE \`authRoleAttr\` CHANGE \`attrPrivilege\` \`attrPrivilege\` varchar(255) NULL`); + await queryRunner.query(`ALTER TABLE \`authRoleAttr\` CHANGE \`attrIsDelete\` \`attrIsDelete\` tinyint NOT NULL DEFAULT '0'`); + await queryRunner.query(`ALTER TABLE \`authRoleAttr\` CHANGE \`attrIsUpdate\` \`attrIsUpdate\` tinyint NOT NULL DEFAULT '0'`); + await queryRunner.query(`ALTER TABLE \`authRoleAttr\` CHANGE \`attrIsGet\` \`attrIsGet\` tinyint NOT NULL DEFAULT '0'`); + await queryRunner.query(`ALTER TABLE \`authRoleAttr\` CHANGE \`attrIsList\` \`attrIsList\` tinyint NOT NULL DEFAULT '0'`); + await queryRunner.query(`ALTER TABLE \`authRoleAttr\` CHANGE \`attrIsCreate\` \`attrIsCreate\` tinyint NOT NULL DEFAULT '0'`); + await queryRunner.query(`ALTER TABLE \`authRoleAttr\` CHANGE \`attrOwnership\` \`attrOwnership\` varchar(255) NULL`); + } + +}