fix table name
This commit is contained in:
parent
cf15998765
commit
7ab642616f
5 changed files with 99 additions and 99 deletions
96
src/controllers/AuthSysController.ts
Normal file
96
src/controllers/AuthSysController.ts
Normal file
|
|
@ -0,0 +1,96 @@
|
||||||
|
import {
|
||||||
|
Body,
|
||||||
|
Controller,
|
||||||
|
Delete,
|
||||||
|
Get,
|
||||||
|
Patch,
|
||||||
|
Path,
|
||||||
|
Post,
|
||||||
|
Request,
|
||||||
|
Route,
|
||||||
|
Security,
|
||||||
|
Tags,
|
||||||
|
} from "tsoa";
|
||||||
|
import { AppDataSource } from "../database/data-source";
|
||||||
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
|
import HttpError from "../interfaces/http-error";
|
||||||
|
import HttpStatus from "../interfaces/http-status";
|
||||||
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
|
import { AuthSys, CreateAuthSys, UpdateAuthSys } from "../entities/AuthSys";
|
||||||
|
|
||||||
|
@Route("api/v1/org/auth/authSys")
|
||||||
|
@Tags("AuthSystem")
|
||||||
|
@Security("bearerAuth")
|
||||||
|
export class AuthSysController extends Controller {
|
||||||
|
private authSysRepo = AppDataSource.getRepository(AuthSys);
|
||||||
|
|
||||||
|
@Get("list")
|
||||||
|
public async listAuthSys(@Request() request: { user: Record<string, any> }) {
|
||||||
|
const profile = await this.authSysRepo.findOneBy({ id: request.user.sub });
|
||||||
|
if (!profile) {
|
||||||
|
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||||
|
}
|
||||||
|
const getList = await this.authSysRepo.find();
|
||||||
|
if (!getList || getList.length === 0) {
|
||||||
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
}
|
||||||
|
return new HttpSuccess(getList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get("{systemId}")
|
||||||
|
public async detailAuthSys(@Path() systemId: string) {
|
||||||
|
const getDetail = await this.authSysRepo.findBy({ id: systemId });
|
||||||
|
if (!getDetail) {
|
||||||
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
}
|
||||||
|
return new HttpSuccess(getDetail);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
public async newAuthSys(@Request() req: RequestWithUser, @Body() body: CreateAuthSys) {
|
||||||
|
if (!body.id) {
|
||||||
|
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบค่าไอดีที่ส่งมา");
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = new AuthSys();
|
||||||
|
const meta = {
|
||||||
|
createdUserId: req.user.sub,
|
||||||
|
createdFullName: req.user.name,
|
||||||
|
lastUpdateUserId: req.user.sub,
|
||||||
|
lastUpdateFullName: req.user.name,
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.assign(data, { ...body, ...meta });
|
||||||
|
|
||||||
|
await this.authSysRepo.save(data);
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Patch("{systemId}")
|
||||||
|
public async editAuthSys(
|
||||||
|
@Body() requestBody: UpdateAuthSys,
|
||||||
|
@Request() req: RequestWithUser,
|
||||||
|
@Path() systemId: string,
|
||||||
|
) {
|
||||||
|
const record = await this.authSysRepo.findOneBy({ id: systemId });
|
||||||
|
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
Object.assign(record, requestBody);
|
||||||
|
record.lastUpdateFullName = req.user.name;
|
||||||
|
|
||||||
|
await Promise.all([this.authSysRepo.save(record)]);
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete("{systemId}")
|
||||||
|
public async deleteProfileAbility(@Path() systemId: string) {
|
||||||
|
|
||||||
|
const result = await this.authSysRepo.delete({ id: systemId });
|
||||||
|
|
||||||
|
if (result.affected == undefined || result.affected <= 0)
|
||||||
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,7 +2,7 @@ import { Entity, Column, OneToMany } from "typeorm";
|
||||||
import { EntityBase } from "./base/Base";
|
import { EntityBase } from "./base/Base";
|
||||||
import { AuthRoleAttr } from "./AuthRoleAttr";
|
import { AuthRoleAttr } from "./AuthRoleAttr";
|
||||||
|
|
||||||
@Entity("AuthRole")
|
@Entity("authRole")
|
||||||
export class AuthRole extends EntityBase {
|
export class AuthRole extends EntityBase {
|
||||||
@Column({
|
@Column({
|
||||||
nullable: true,
|
nullable: true,
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { EntityBase } from "./base/Base";
|
||||||
import { AuthSys } from "./AuthSys";
|
import { AuthSys } from "./AuthSys";
|
||||||
import { AuthRole } from "./AuthRole";
|
import { AuthRole } from "./AuthRole";
|
||||||
|
|
||||||
@Entity("AuthRoleAttr")
|
@Entity("authRoleAttr")
|
||||||
export class AuthRoleAttr extends EntityBase {
|
export class AuthRoleAttr extends EntityBase {
|
||||||
@Column({
|
@Column({
|
||||||
nullable: true,
|
nullable: true,
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import {
|
||||||
} from "typeorm";
|
} from "typeorm";
|
||||||
import { AuthRoleAttr } from "./AuthRoleAttr";
|
import { AuthRoleAttr } from "./AuthRoleAttr";
|
||||||
|
|
||||||
@Entity("AuthSys")
|
@Entity("authSys")
|
||||||
export class AuthSys {
|
export class AuthSys {
|
||||||
@PrimaryColumn({
|
@PrimaryColumn({
|
||||||
comment: "ไอดีหลักของตาราง",
|
comment: "ไอดีหลักของตาราง",
|
||||||
|
|
|
||||||
|
|
@ -1,96 +0,0 @@
|
||||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
|
||||||
|
|
||||||
export class UpdateTableProfileempAddGroup31718072994129 implements MigrationInterface {
|
|
||||||
name = 'UpdateTableProfileempAddGroup31718072994129'
|
|
||||||
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`isLeave\` tinyint NOT NULL COMMENT 'เกษียณ' DEFAULT 0`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`leaveReason\` varchar(255) NULL COMMENT 'เหตุผลเกษียณ'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`dateLeave\` datetime NULL COMMENT 'วันพ้นราชการ'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`posmasterIdTemp\` varchar(255) NULL COMMENT 'id อัตรา'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`nodeTemp\` varchar(255) NULL COMMENT 'node'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`nodeIdTemp\` varchar(255) NULL COMMENT 'id node'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`orgRevisionIdTemp\` varchar(255) NULL COMMENT 'id Revision'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`positionIdTemp\` varchar(255) NULL COMMENT 'id position'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`posMasterNoTemp\` varchar(255) NULL COMMENT 'เลขที่ตำแหน่ง'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`positionTemp\` varchar(255) NULL COMMENT 'ตำแหน่ง'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`positionFieldTemp\` varchar(255) NULL COMMENT 'ตำแหน่ง'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`posTypeIdTemp\` varchar(255) NULL COMMENT 'id ประเภท'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`posTypeNameTemp\` varchar(255) NULL COMMENT 'ประเภท'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`posLevelIdTemp\` varchar(255) NULL COMMENT 'id ระดับ'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`posLevelNameTemp\` varchar(255) NULL COMMENT 'ระดับ'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`rootTemp\` varchar(255) NULL COMMENT 'ชื่อ root'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`rootIdTemp\` varchar(255) NULL COMMENT 'id root'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`rootShortNameTemp\` varchar(255) NULL COMMENT 'ชื่อย่อ root'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`child1Temp\` varchar(255) NULL COMMENT 'ชื่อ child1'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`child1IdTemp\` varchar(255) NULL COMMENT 'id child1'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`child1ShortNameTemp\` varchar(255) NULL COMMENT 'ชื่อย่อ child1'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`child2Temp\` varchar(255) NULL COMMENT 'ชื่อ child2'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`child2IdTemp\` varchar(255) NULL COMMENT 'id child2'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`child2ShortNameTemp\` varchar(255) NULL COMMENT 'ชื่อย่อ child2'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`child3Temp\` varchar(255) NULL COMMENT 'ชื่อ child3'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`child3IdTemp\` varchar(255) NULL COMMENT 'id child3'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`child3ShortNameTemp\` varchar(255) NULL COMMENT 'ชื่อย่อ child3'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`child4Temp\` varchar(255) NULL COMMENT 'ชื่อ child4'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`child4IdTemp\` varchar(255) NULL COMMENT 'id child4'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`child4ShortNameTemp\` varchar(255) NULL COMMENT 'ชื่อย่อ child4'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`statusTemp\` varchar(255) NULL COMMENT 'สถานะลูกจ้างชั่วคราว'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`positionEmployeeGroupId\` varchar(255) NULL COMMENT 'กลุ่มงาน'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`positionEmployeeLineId\` varchar(255) NULL COMMENT 'สายงาน'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`positionEmployeePositionId\` varchar(255) NULL COMMENT 'ชื่อตำแหน่งทางสายงาน'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`employeeOc\` varchar(255) NULL COMMENT 'สังกัด'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`employeeTypeIndividual\` varchar(255) NULL COMMENT 'ประเภทบุคคล'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`employeeWage\` varchar(255) NULL COMMENT 'ค่าจ้าง'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`employeeMoneyIncrease\` varchar(255) NULL COMMENT 'เงินเพิ่มการครองชีพชั่วคราว'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`employeeMoneyAllowance\` varchar(255) NULL COMMENT 'เงินช่วยเหลือการครองชีพชั่วคราว'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`employeeMoneyEmployee\` varchar(255) NULL COMMENT 'เงินสมทบประกันสังคม(ลูกจ้าง)'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`employeeMoneyEmployer\` varchar(255) NULL COMMENT 'เงินสมทบประกันสังคม(นายจ้าง)'`);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profile\` ADD \`dateLeave\` datetime NULL COMMENT 'วันพ้นราชการ'`);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profile\` DROP COLUMN \`dateLeave\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`employeeMoneyEmployer\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`employeeMoneyEmployee\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`employeeMoneyAllowance\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`employeeMoneyIncrease\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`employeeWage\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`employeeTypeIndividual\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`employeeOc\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`positionEmployeePositionId\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`positionEmployeeLineId\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`positionEmployeeGroupId\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`statusTemp\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`child4ShortNameTemp\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`child4IdTemp\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`child4Temp\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`child3ShortNameTemp\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`child3IdTemp\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`child3Temp\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`child2ShortNameTemp\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`child2IdTemp\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`child2Temp\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`child1ShortNameTemp\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`child1IdTemp\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`child1Temp\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`rootShortNameTemp\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`rootIdTemp\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`rootTemp\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`posLevelNameTemp\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`posLevelIdTemp\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`posTypeNameTemp\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`posTypeIdTemp\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`positionFieldTemp\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`positionTemp\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`posMasterNoTemp\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`positionIdTemp\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`orgRevisionIdTemp\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`nodeIdTemp\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`nodeTemp\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`posmasterIdTemp\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`dateLeave\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`leaveReason\``);
|
|
||||||
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`isLeave\``);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue