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")
|
@Get("Registry")
|
||||||
public async Registry() {
|
public async Registry() {
|
||||||
await this.registryRepo.clear();
|
await this.registryRepo.clear();
|
||||||
const profile = await this.profileRepo.find();
|
const allRegis = await AppDataSource.getRepository(viewRegistryOfficer)
|
||||||
for await (const x of profile) {
|
.createQueryBuilder("registryOfficer")
|
||||||
const _regis = await AppDataSource.getRepository(viewRegistryOfficer)
|
.getMany();
|
||||||
.createQueryBuilder("registryOfficer")
|
const profileIds = new Set((await this.profileRepo.find()).map(p => p.id));
|
||||||
.where("registryOfficer.profileId IN (:id)", { id: x.id })
|
const mapData = allRegis
|
||||||
.getMany();
|
.filter(x => profileIds.has(x.profileId))
|
||||||
|
.map(x => ({
|
||||||
const mapData = _regis.map(x => ({
|
|
||||||
...x,
|
...x,
|
||||||
Educations: x.Educations ? JSON.stringify(x.Educations) : "",
|
Educations: x.Educations ? JSON.stringify(x.Educations) : "",
|
||||||
}));
|
}));
|
||||||
|
if (mapData.length > 0) {
|
||||||
await this.registryRepo.save(mapData);
|
await this.registryRepo.save(mapData);
|
||||||
}
|
}
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
|
|
@ -359,17 +359,17 @@ export class ProfileSalaryController extends Controller {
|
||||||
@Get("RegistryEmployee")
|
@Get("RegistryEmployee")
|
||||||
public async RegistryEmployee() {
|
public async RegistryEmployee() {
|
||||||
await this.registryEmployeeRepo.clear();
|
await this.registryEmployeeRepo.clear();
|
||||||
const profileEmp = await this.profileEmployeeRepo.find();
|
const allRegis = await AppDataSource.getRepository(viewRegistryEmployee)
|
||||||
for await (const x of profileEmp) {
|
.createQueryBuilder("registryEmployee")
|
||||||
const _regisEmp = await AppDataSource.getRepository(viewRegistryEmployee)
|
.getMany();
|
||||||
.createQueryBuilder("registryEmployee")
|
const profileEmpIds = new Set((await this.profileEmployeeRepo.find()).map(p => p.id));
|
||||||
.where("registryEmployee.profileEmployeeId IN (:id)", { id: x.id })
|
const mapData = allRegis
|
||||||
.getMany();
|
.filter(x => profileEmpIds.has(x.profileEmployeeId))
|
||||||
|
.map(x => ({
|
||||||
const mapData = _regisEmp.map(x => ({
|
|
||||||
...x,
|
...x,
|
||||||
Educations: x.Educations ? JSON.stringify(x.Educations) : "",
|
Educations: x.Educations ? JSON.stringify(x.Educations) : "",
|
||||||
}));
|
}));
|
||||||
|
if (mapData.length > 0) {
|
||||||
await this.registryEmployeeRepo.save(mapData);
|
await this.registryEmployeeRepo.save(mapData);
|
||||||
}
|
}
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ export class Registry extends EntityBase {
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
nullable: true,
|
nullable: true,
|
||||||
length: 20,
|
length: 40,
|
||||||
comment: "คำนำหน้าชื่อ เช่น นาย นาง นางสาว",
|
comment: "คำนำหน้าชื่อ เช่น นาย นาง นางสาว",
|
||||||
default: null,
|
default: null,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ export class RegistryEmployee extends EntityBase {
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
nullable: true,
|
nullable: true,
|
||||||
length: 20,
|
length: 40,
|
||||||
comment: "คำนำหน้าชื่อ เช่น นาย นาง นางสาว",
|
comment: "คำนำหน้าชื่อ เช่น นาย นาง นางสาว",
|
||||||
default: null,
|
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