migrate && optimize

This commit is contained in:
Bright 2025-08-28 12:54:09 +07:00
parent b5e534413a
commit 8d010cd389
4 changed files with 38 additions and 18 deletions

View file

@ -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();