Browse Source

FIX | Old db seed

merge-requests/237/head
Vitalik 2 years ago
parent
commit
d5cdf9e601
  1. 15
      src/domain/old-database-seed/services/factories.service.ts
  2. 2
      src/domain/old-database-seed/services/main.service.ts
  3. 4
      src/domain/old-database-seed/services/tasks.service.ts
  4. 2
      src/domain/users/services/index.ts
  5. 3
      src/domain/users/users.module.ts
  6. 5
      src/main.ts

15
src/domain/old-database-seed/services/factories.service.ts

@ -24,6 +24,7 @@ export class OldDBFactoriesService { @@ -24,6 +24,7 @@ export class OldDBFactoriesService {
public async run() {
const oldFactories: IOldFactory[] = await this.getOldFactories()
console.log('OLD FACTORIES COUNT', oldFactories.length)
await this.saveFactories(oldFactories)
}
@ -43,6 +44,20 @@ export class OldDBFactoriesService { @@ -43,6 +44,20 @@ export class OldDBFactoriesService {
}
}
if (attempts > 9 && !_.isEmpty(unsaved)) {
for await (const oldFactory of unsaved) {
try {
await this.saveFactory({
...oldFactory,
parent_factory: null,
})
} catch (e) {
console.log('Error on save factory', oldFactory, e)
unsaved.push(oldFactory)
}
}
}
await this.saveFactories(unsaved, attempts + 1)
}

2
src/domain/old-database-seed/services/main.service.ts

@ -49,5 +49,7 @@ export class OldDatabaseSeedMainService { @@ -49,5 +49,7 @@ export class OldDatabaseSeedMainService {
console.log('END USERS RELATIONS \n START FILES')
await this.oldDbFilesService.run()
console.log('END FILES')
await this.oldDBTasksService.readAllTasks()
console.log('END Read')
}
}

4
src/domain/old-database-seed/services/tasks.service.ts

@ -38,8 +38,6 @@ export class OldDBTasksService { @@ -38,8 +38,6 @@ export class OldDBTasksService {
console.log('Error on save task', oldTask, e)
}
}
// await this.readAllTasks()
}
private async getOldTasks(): Promise<IOldTask[]> {
@ -184,7 +182,7 @@ export class OldDBTasksService { @@ -184,7 +182,7 @@ export class OldDBTasksService {
return relations.map(it => it.newId)
}
private async readAllTasks() {
public async readAllTasks() {
const usersIds = await this.getNewEntitiesIds(OldDbRelationType.Users)
const tasksIds = await this.getNewEntitiesIds(OldDbRelationType.Tasks)

2
src/domain/users/services/index.ts

@ -4,7 +4,6 @@ import { UsersPhoneNumbersService } from './users-phone-numbers.service' @@ -4,7 +4,6 @@ import { UsersPhoneNumbersService } from './users-phone-numbers.service'
import { UsersFactoriesRelationsService } from './users-factories-relations.service'
import { UsersListService } from './users-list.service'
import { UsersFactoriesDirectorsService } from './users-factories-directors.service'
import { UsersCroneService } from './users-cron.service'
import { UsersCacheService } from './users-cache.service'
export const USERS_SERVICES = [
@ -12,7 +11,6 @@ export const USERS_SERVICES = [ @@ -12,7 +11,6 @@ export const USERS_SERVICES = [
UsersFactoriesRelationsService,
UsersListService,
UsersFactoriesDirectorsService,
UsersCroneService,
UsersCacheService,
]

3
src/domain/users/users.module.ts

@ -19,6 +19,7 @@ import { UsersModuleOptions } from './interfaces' @@ -19,6 +19,7 @@ import { UsersModuleOptions } from './interfaces'
import { UsersRepository } from './repositories'
import { USERS_SEEDERS } from './seeders'
import { USERS_SERVICES, UsersService, UsersPhoneNumbersService } from './services'
import { UsersCroneService } from './services/users-cron.service'
@Module({})
export class UsersModule {
@ -65,7 +66,7 @@ export class UsersModule { @@ -65,7 +66,7 @@ export class UsersModule {
return {
module: UsersModule,
providers: [...UsersModule.getProviders(), ...USERS_SEEDERS],
providers: [...UsersModule.getProviders(), ...USERS_SEEDERS, UsersCroneService],
imports: UsersModule.getImports(),
exports: UsersModule.getExports(),
}

5
src/main.ts

@ -6,10 +6,11 @@ import { NestFactory } from '@nestjs/core' @@ -6,10 +6,11 @@ import { NestFactory } from '@nestjs/core'
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'
import * as basicAuth from 'express-basic-auth'
import { AppModule } from './app.module'
import { RedisIoAdapter } from './domain/real-time'
import { IpGuard } from './domain/sessions/guards'
import { DomainExceptionsFilter } from './shared/filters'
import { LoggingInterceptor } from './shared/interceptors/log.interceptor'
process.setMaxListeners(0)
async function bootstrap() {
const app = await NestFactory.create(AppModule)

Loading…
Cancel
Save