migrate && optimize
This commit is contained in:
parent
b5e534413a
commit
8d010cd389
4 changed files with 38 additions and 18 deletions
|
|
@ -340,17 +340,17 @@ export class ProfileSalaryController extends Controller {
|
|||
@Get("Registry")
|
||||
public async Registry() {
|
||||
await this.registryRepo.clear();
|
||||
const profile = await this.profileRepo.find();
|
||||
for await (const x of profile) {
|
||||
const _regis = await AppDataSource.getRepository(viewRegistryOfficer)
|
||||
.createQueryBuilder("registryOfficer")
|
||||
.where("registryOfficer.profileId IN (:id)", { id: x.id })
|
||||
.getMany();
|
||||
|
||||
const mapData = _regis.map(x => ({
|
||||
const allRegis = await AppDataSource.getRepository(viewRegistryOfficer)
|
||||
.createQueryBuilder("registryOfficer")
|
||||
.getMany();
|
||||
const profileIds = new Set((await this.profileRepo.find()).map(p => p.id));
|
||||
const mapData = allRegis
|
||||
.filter(x => profileIds.has(x.profileId))
|
||||
.map(x => ({
|
||||
...x,
|
||||
Educations: x.Educations ? JSON.stringify(x.Educations) : "",
|
||||
}));
|
||||
if (mapData.length > 0) {
|
||||
await this.registryRepo.save(mapData);
|
||||
}
|
||||
return new HttpSuccess();
|
||||
|
|
@ -359,17 +359,17 @@ export class ProfileSalaryController extends Controller {
|
|||
@Get("RegistryEmployee")
|
||||
public async RegistryEmployee() {
|
||||
await this.registryEmployeeRepo.clear();
|
||||
const profileEmp = await this.profileEmployeeRepo.find();
|
||||
for await (const x of profileEmp) {
|
||||
const _regisEmp = await AppDataSource.getRepository(viewRegistryEmployee)
|
||||
.createQueryBuilder("registryEmployee")
|
||||
.where("registryEmployee.profileEmployeeId IN (:id)", { id: x.id })
|
||||
.getMany();
|
||||
|
||||
const mapData = _regisEmp.map(x => ({
|
||||
const allRegis = await AppDataSource.getRepository(viewRegistryEmployee)
|
||||
.createQueryBuilder("registryEmployee")
|
||||
.getMany();
|
||||
const profileEmpIds = new Set((await this.profileEmployeeRepo.find()).map(p => p.id));
|
||||
const mapData = allRegis
|
||||
.filter(x => profileEmpIds.has(x.profileEmployeeId))
|
||||
.map(x => ({
|
||||
...x,
|
||||
Educations: x.Educations ? JSON.stringify(x.Educations) : "",
|
||||
}));
|
||||
if (mapData.length > 0) {
|
||||
await this.registryEmployeeRepo.save(mapData);
|
||||
}
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ export class Registry extends EntityBase {
|
|||
|
||||
@Column({
|
||||
nullable: true,
|
||||
length: 20,
|
||||
length: 40,
|
||||
comment: "คำนำหน้าชื่อ เช่น นาย นาง นางสาว",
|
||||
default: null,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ export class RegistryEmployee extends EntityBase {
|
|||
|
||||
@Column({
|
||||
nullable: true,
|
||||
length: 20,
|
||||
length: 40,
|
||||
comment: "คำนำหน้าชื่อ เช่น นาย นาง นางสาว",
|
||||
default: null,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class UpdateRegistryFixLengthPrefix1756357065498 implements MigrationInterface {
|
||||
name = 'UpdateRegistryFixLengthPrefix1756357065498'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`registryEmployee\` DROP COLUMN \`prefix\``);
|
||||
await queryRunner.query(`ALTER TABLE \`registryEmployee\` ADD \`prefix\` varchar(40) NULL COMMENT 'คำนำหน้าชื่อ เช่น นาย นาง นางสาว'`);
|
||||
await queryRunner.query(`ALTER TABLE \`registry\` DROP COLUMN \`prefix\``);
|
||||
await queryRunner.query(`ALTER TABLE \`registry\` ADD \`prefix\` varchar(40) NULL COMMENT 'คำนำหน้าชื่อ เช่น นาย นาง นางสาว'`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`registry\` DROP COLUMN \`prefix\``);
|
||||
await queryRunner.query(`ALTER TABLE \`registry\` ADD \`prefix\` varchar(20) NULL COMMENT 'คำนำหน้าชื่อ เช่น นาย นาง นางสาว'`);
|
||||
await queryRunner.query(`ALTER TABLE \`registryEmployee\` DROP COLUMN \`prefix\``);
|
||||
await queryRunner.query(`ALTER TABLE \`registryEmployee\` ADD \`prefix\` varchar(20) NULL COMMENT 'คำนำหน้าชื่อ เช่น นาย นาง นางสาว'`);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue