no message

This commit is contained in:
kittapath 2024-09-24 16:42:24 +07:00
parent 317920ad0d
commit b2b97aecf0
6 changed files with 225 additions and 6 deletions

View file

@ -234,6 +234,78 @@ export class CommandController extends Controller {
return new HttpSuccess();
}
/**
* API tab2
*
* @summary API tab2
*
* @param {string} id Id
*/
@Get("tab2/{id}")
async GetByIdTab2(@Path() id: string) {
const command = await this.commandRepository.findOne({
where: { id },
relations: ["commandSalary", "commandRecives"],
});
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
}
const _command = {
id: command.id,
commandSalaryId: command.commandSalaryId,
commandSalary: command.commandSalary?.name || null,
positionDetail: command.positionDetail,
sendCC: command.commandRecives
.sort((a, b) => a.order - b.order)
.map((x) => ({
citizenId: x.citizenId,
prefix: x.prefix,
fristName: x.fristName,
lastName: x.lastName,
profileId: x.profileId,
order: x.order,
})),
};
return new HttpSuccess(_command);
}
/**
* API body Tab2
*
* @summary API body Tab2
*
* @param {string} id Id
*/
@Put("tab2/{id}")
async PutTab2(
@Path() id: string,
@Body()
requestBody: {
commandNo: string | null;
commandYear: number | null;
issue: string | null;
detailHeader: string | null;
detailBody: string | null;
detailFooter: string | null;
commandAffectDate: Date | null;
commandExcecuteDate: Date | null;
},
@Request() request: RequestWithUser,
) {
const command = await this.commandRepository.findOne({ where: { id: id } });
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
}
const data = new Command();
Object.assign(data, { ...command, ...requestBody });
data.lastUpdateUserId = request.user.sub;
data.lastUpdateFullName = request.user.name;
data.lastUpdatedAt = new Date();
await this.commandRepository.save(data);
return new HttpSuccess();
}
/**
* API tab3
*
@ -526,6 +598,7 @@ export class CommandController extends Controller {
status: command.status,
isDraft: command.isDraft,
isSign: command.isSign,
isAttachment: command.isAttachment,
};
return new HttpSuccess(_command);
}
@ -568,14 +641,14 @@ export class CommandController extends Controller {
async PutSelectDraft(
@Path() id: string,
@Body()
requestBody: { sign?: boolean },
requestBody: { sign: boolean },
@Request() request: RequestWithUser,
) {
const command = await this.commandRepository.findOne({ where: { id: id } });
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
}
command.isDraft = true;
command.isDraft = requestBody.sign;
command.status = "PENDING";
command.lastUpdateUserId = request.user.sub;
command.lastUpdateFullName = request.user.name;

View file

@ -2,6 +2,8 @@ import { Entity, Column, JoinColumn, ManyToOne, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base";
import { CommandType } from "./CommandType";
import { CommandSend } from "./CommandSend";
import { CommandSalary } from "./CommandSalary";
import { CommandRecive } from "./CommandRecive";
@Entity("command")
export class Command extends EntityBase {
@ -83,10 +85,12 @@ export class Command extends EntityBase {
detailFooter: string;
@Column({
length: 40,
comment: "คีย์นอก(FK)ของตาราง commandType",
nullable: true,
comment: "ตำแหน่ง",
type: "text",
default: null,
})
commandTypeId: string;
positionDetail: string;
@Column({
comment: "สถานะบัญชีแนบท้าย",
@ -112,12 +116,33 @@ export class Command extends EntityBase {
})
isSign: boolean;
@Column({
length: 40,
comment: "คีย์นอก(FK)ของตาราง commandType",
})
commandTypeId: string;
@ManyToOne(() => CommandType, (commandType) => commandType.commands)
@JoinColumn({ name: "commandTypeId" })
commandType: CommandType;
@Column({
nullable: true,
length: 40,
comment: "คีย์นอก(FK)ของตาราง commandSalary",
default: null,
})
commandSalaryId: string;
@ManyToOne(() => CommandSalary, (commandSalary) => commandSalary.commands)
@JoinColumn({ name: "commandSalaryId" })
commandSalary: CommandSalary;
@OneToMany(() => CommandSend, (commandSend) => commandSend.command)
commandSends: CommandSend[];
@OneToMany(() => CommandRecive, (commandRecive) => commandRecive.command)
commandRecives: CommandRecive[];
}
export class CreateCommand {

View file

@ -0,0 +1,89 @@
import { Entity, Column, JoinColumn, ManyToOne, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base";
import { Command } from "./Command";
import { Profile } from "./Profile";
@Entity("commandRecive")
export class CommandRecive extends EntityBase {
@Column({
nullable: true,
comment: "เลขประจำตัวประชาชน",
length: 255,
default: null,
})
citizenId: string;
@Column({
nullable: true,
comment: "คำนำหน้า",
length: 255,
default: null,
})
prefix: string;
@Column({
nullable: true,
comment: "ชื่อ",
length: 255,
default: null,
})
fristName: string;
@Column({
nullable: true,
comment: "สกุล",
length: 255,
default: null,
})
lastName: string;
@Column({
nullable: true,
comment: "ตำแหน่ง",
length: 255,
default: null,
})
position: string;
@Column({
nullable: true,
comment: "หน่วยงาน",
length: 255,
default: null,
})
org: string;
@Column({
nullable: true,
comment: "ลำดับแสดงผล",
default: null,
})
order: number;
@Column({
length: 40,
comment: "คีย์นอก(FK)ของตาราง command",
})
commandId: string;
@ManyToOne(() => Command, (command) => command.commandRecives)
@JoinColumn({ name: "commandId" })
command: Command;
@Column({
length: 40,
comment: "คีย์นอก(FK)ของตาราง profile",
})
profileId: string;
@ManyToOne(() => Profile, (profile) => profile.commandRecives)
@JoinColumn({ name: "profileId" })
profile: Profile;
}
export class CreateCommandRecive {
@Column()
name: string;
}
// export type UpdateCommandRecive = Partial<CreateCommandRecive>;

View file

@ -1,6 +1,7 @@
import { Entity, Column, JoinColumn, ManyToOne } from "typeorm";
import { Entity, Column, JoinColumn, ManyToOne, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base";
import { CommandSys } from "./CommandSys";
import { Command } from "./Command";
@Entity("commandSalary")
export class CommandSalary extends EntityBase {
@ -29,6 +30,9 @@ export class CommandSalary extends EntityBase {
@ManyToOne(() => CommandSys, (commandSys) => commandSys.commandSalarys)
@JoinColumn({ name: "commandSysId" })
commandSalarySys: CommandSys;
@OneToMany(() => Command, (command) => command.commandSalary)
commands: Command[];
}
export class CreateCommandSalary {

View file

@ -32,6 +32,7 @@ import { ProfileDevelopment } from "./ProfileDevelopment";
import { OrgRoot } from "./OrgRoot";
import { PermissionOrg } from "./PermissionOrg";
import { CommandSend } from "./CommandSend";
import { CommandRecive } from "./CommandRecive";
@Entity("profile")
export class Profile extends EntityBase {
@ -375,6 +376,9 @@ export class Profile extends EntityBase {
@OneToMany(() => CommandSend, (v) => v.profile)
commandSends: CommandSend[];
@OneToMany(() => CommandRecive, (v) => v.profile)
commandRecives: CommandRecive[];
@ManyToOne(() => PosLevel, (posLevel) => posLevel.profiles)
@JoinColumn({ name: "posLevelId" })
posLevel: PosLevel;

View file

@ -0,0 +1,24 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateCommandAddPositiondetail1727167169710 implements MigrationInterface {
name = 'UpdateCommandAddPositiondetail1727167169710'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE \`commandRecive\` (\`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', \`citizenId\` varchar(255) NULL COMMENT 'เลขประจำตัวประชาชน', \`prefix\` varchar(255) NULL COMMENT 'คำนำหน้า', \`fristName\` varchar(255) NULL COMMENT 'ชื่อ', \`lastName\` varchar(255) NULL COMMENT 'สกุล', \`position\` varchar(255) NULL COMMENT 'ตำแหน่ง', \`org\` varchar(255) NULL COMMENT 'หน่วยงาน', \`commandId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง command', \`profileId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง profile', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`ALTER TABLE \`command\` ADD \`positionDetail\` text NULL COMMENT 'ตำแหน่ง'`);
await queryRunner.query(`ALTER TABLE \`command\` ADD \`commandSalaryId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง commandSalary'`);
await queryRunner.query(`ALTER TABLE \`commandRecive\` ADD CONSTRAINT \`FK_66de028b0d8e4cff62bc43a58be\` FOREIGN KEY (\`commandId\`) REFERENCES \`command\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`commandRecive\` ADD CONSTRAINT \`FK_fb29bfd315d0d43d0b49b362995\` FOREIGN KEY (\`profileId\`) REFERENCES \`profile\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`command\` ADD CONSTRAINT \`FK_c85f006fc84cebf07b0980c6b94\` FOREIGN KEY (\`commandSalaryId\`) REFERENCES \`commandSalary\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`command\` DROP FOREIGN KEY \`FK_c85f006fc84cebf07b0980c6b94\``);
await queryRunner.query(`ALTER TABLE \`commandRecive\` DROP FOREIGN KEY \`FK_fb29bfd315d0d43d0b49b362995\``);
await queryRunner.query(`ALTER TABLE \`commandRecive\` DROP FOREIGN KEY \`FK_66de028b0d8e4cff62bc43a58be\``);
await queryRunner.query(`ALTER TABLE \`command\` DROP COLUMN \`commandSalaryId\``);
await queryRunner.query(`ALTER TABLE \`command\` DROP COLUMN \`positionDetail\``);
await queryRunner.query(`DROP TABLE \`commandRecive\``);
}
}