Browse Source

FIX | Task db stage

merge-requests/238/merge
Vitalik 2 years ago
parent
commit
73c3b1e107
  1. 6
      src/domain/old-database-seed/services/factories.service.ts
  2. 2
      src/domain/old-database-seed/services/main.service.ts
  3. 9
      src/domain/old-database-seed/services/tasks-comments.service.ts
  4. 4
      src/domain/old-database-seed/services/tasks-documents.service.ts
  5. 16
      src/domain/old-database-seed/services/tasks.service.ts
  6. 5
      src/domain/old-database-seed/services/taxonomies.service.ts
  7. 5
      src/domain/old-database-seed/services/users.service.ts
  8. 2
      src/domain/real-time/services/ws.service.ts
  9. 1
      src/domain/versions/services/versions.service.ts

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

@ -24,7 +24,6 @@ export class OldDBFactoriesService { @@ -24,7 +24,6 @@ export class OldDBFactoriesService {
public async run() {
const oldFactories: IOldFactory[] = await this.getOldFactories()
console.log('OLD FACTORIES COUNT', oldFactories.length)
await this.saveFactories(oldFactories)
}
@ -62,7 +61,10 @@ export class OldDBFactoriesService { @@ -62,7 +61,10 @@ export class OldDBFactoriesService {
}
private async getOldFactories(): Promise<IOldFactory[]> {
const result: IOldFactory[] = await this.connection.query(`SELECT * FROM factory`, [])
const result: IOldFactory[] = await this.connection.query(
`SELECT * FROM factory ORDER BY factory.id ASC`,
[],
)
return result
}

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

@ -49,7 +49,7 @@ export class OldDatabaseSeedMainService { @@ -49,7 +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()
// await this.oldDBTasksService.readAllTasks()
console.log('END Read')
}
}

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

@ -43,12 +43,19 @@ export class OldDBTasksCommentsService { @@ -43,12 +43,19 @@ export class OldDBTasksCommentsService {
}
private async getOldComments(): Promise<IOldTaskComment[]> {
const result: IOldTaskComment[] = await this.connection.query(`SELECT * FROM comment`, [])
const result: IOldTaskComment[] = await this.connection.query(
`SELECT * FROM comment ORDER BY comment.id ASC`,
[],
)
return result
}
private async saveComment(oldComment: IOldTaskComment, newUsersIds: number[]) {
const newTaskId = await this.getNewEntityId(oldComment.task, OldDbRelationType.Tasks)
if (!newTaskId) {
console.log('Not save comment because task null')
return
}
const newAuthorId = await this.getNewEntityId(
oldComment.user_created,
OldDbRelationType.Users,

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

@ -54,6 +54,10 @@ export class OldDBTasksDocumentsService { @@ -54,6 +54,10 @@ export class OldDBTasksDocumentsService {
private async saveDocument(oldDocument: IOldTaskDocument) {
const newTaskId = await this.getNewEntityId(oldDocument.task, OldDbRelationType.Tasks)
if (!newTaskId) {
console.log('Not save document')
return
}
const createdAt = new Date(Number(oldDocument.created_at)).toDateString()
const newUrl = await this.getNewDocumentUrl(oldDocument.url, oldDocument.name)

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

@ -29,10 +29,16 @@ export class OldDBTasksService { @@ -29,10 +29,16 @@ export class OldDBTasksService {
private readonly tasksEventsService: Tasks.ITasksEventsService
@Inject(TASKS_REPOSITORY) private readonly tasksRepository: ITasksRepository
constructor(@InjectConnection('old') private readonly connection: Connection) {}
constructor(
@InjectConnection('old') private readonly connection: Connection,
@InjectConnection() private readonly connectionCurrent: Connection,
) {}
public async run() {
await this.connectionCurrent.query('ALTER SEQUENCE tasks_id_seq RESTART WITH 100000;')
const oldTasks = await this.getOldTasks()
for await (const oldTask of oldTasks) {
try {
await this.saveTask(oldTask)
@ -40,10 +46,15 @@ export class OldDBTasksService { @@ -40,10 +46,15 @@ export class OldDBTasksService {
console.log('Error on save task', oldTask, e)
}
}
const lastTask = oldTasks[oldTasks.length - 1].id + 50
await this.connectionCurrent.query(`ALTER SEQUENCE tasks_id_seq RESTART WITH ${lastTask};`)
}
private async getOldTasks(): Promise<IOldTask[]> {
const result = await this.connection.query('SELECT * FROM task', [])
const result = await this.connection.query('SELECT * FROM task ORDER BY task.id ASC', [])
return result
}
@ -66,6 +77,7 @@ export class OldDBTasksService { @@ -66,6 +77,7 @@ export class OldDBTasksService {
const createdAt = oldTask.create_date
? new Date(oldTask.create_date).toDateString()
: new Date(Number(oldTask.created_at)).toDateString()
const status = this.getStatus(oldTask)
const task = await this.tasksRepository.save({

5
src/domain/old-database-seed/services/taxonomies.service.ts

@ -126,7 +126,10 @@ export class OldDBTaxonomiesService { @@ -126,7 +126,10 @@ export class OldDBTaxonomiesService {
}
private async getTaxonomies(): Promise<IOldTaxonomy[]> {
const result = await this.connection.query(`SELECT * FROM taxonomy`, [])
const result = await this.connection.query(
`SELECT * FROM taxonomy ORDER BY taxonomy.id ASC`,
[],
)
return result
}

5
src/domain/old-database-seed/services/users.service.ts

@ -51,7 +51,10 @@ export class OldDBUsersService { @@ -51,7 +51,10 @@ export class OldDBUsersService {
}
private async getOldUsers(): Promise<IOldUser[]> {
const result: IOldUser[] = await this.connection.query(`SELECT * FROM "user"`, [])
const result: IOldUser[] = await this.connection.query(
`SELECT * FROM "user" ORDER BY "user"."id" ASC`,
[],
)
return result
}

2
src/domain/real-time/services/ws.service.ts

@ -23,7 +23,7 @@ export class WsService implements WebSockets.Service { @@ -23,7 +23,7 @@ export class WsService implements WebSockets.Service {
}
public emitToUser(userId: number, key: string, data?: any) {
console.log('EDIT TO USER', userId, key)
// console.log('EDIT TO USER', userId, key)
this.wsServerService.emitToRoom(`user-${userId}`, key, data)
}
}

1
src/domain/versions/services/versions.service.ts

@ -18,7 +18,6 @@ export class VersionsService implements Versions.VersionsService { @@ -18,7 +18,6 @@ export class VersionsService implements Versions.VersionsService {
}
public async update(type: Versions.EntityType, entityId: number) {
console.log('update version', type, entityId)
const current = await this.get(type, entityId)
const version = randomstring.generate(4)

Loading…
Cancel
Save