Browse Source

Merge branch 'change/old-db-tasks-seed' into 'stage'

CHANGE | Change seeded task id to old task id, add isReadByAll to task entity

See merge request jetup/rws/api-rws!237
merge-requests/238/merge
Coder 2 years ago
parent
commit
68d50bcd85
  1. 2
      src/core/namespaces/tasks.namespace.ts
  2. 20
      src/domain/old-database-seed/services/tasks.service.ts
  3. 3
      src/domain/tasks/entities/task.entity.ts
  4. 1
      src/domain/tasks/tasks.module.ts

2
src/core/namespaces/tasks.namespace.ts

@ -115,6 +115,8 @@ export namespace Tasks { @@ -115,6 +115,8 @@ export namespace Tasks {
/** Офлайн ключ - ідентифікатор, з яким створюється задача в режимі офлайн */
offlineKey?: string
isReadByAll?: boolean
}
export interface ITaskForResponse extends Omit<Partial<TaskModel>, 'events' | 'favorites'> {

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

@ -1,11 +1,14 @@ @@ -1,11 +1,14 @@
import { Inject, Injectable } from '@nestjs/common'
import { InjectConnection } from '@nestjs/typeorm'
import { Tasks, Taxonomies, Users } from 'src/core'
import { TASKS_EVENTS_SERVICE, TASKS_SERVICE, TAXONOMIES_SERVICE } from 'src/core/consts'
import { TASKS_EVENTS_SERVICE, TAXONOMIES_SERVICE } from 'src/core/consts'
import { TASKS_REPOSITORY } from 'src/domain/tasks/consts'
import { ITasksRepository } from 'src/domain/tasks/interfaces'
import { TAXONOMIES_REPOSITORY } from 'src/domain/taxonomies/consts'
import { ITaxonomiesRepository } from 'src/domain/taxonomies/interfaces'
import { USERS_REPOSITORY } from 'src/domain/users/consts'
import { IUsersRepository } from 'src/domain/users/interfaces'
import { dateToSqlFormat } from 'src/shared'
import { Connection, Repository } from 'typeorm'
import { OldDbRelation } from '../entities'
import { OLD_DB_RELATIONS_REPOSITORY } from '../typing/consts'
@ -14,7 +17,6 @@ import { IOldTask } from '../typing/interfaces' @@ -14,7 +17,6 @@ import { IOldTask } from '../typing/interfaces'
@Injectable()
export class OldDBTasksService {
@Inject(TASKS_SERVICE) private readonly tasksService: Tasks.ITasksService
@Inject(OLD_DB_RELATIONS_REPOSITORY)
private readonly oldDbRelationsRepository: Repository<OldDbRelation>
@Inject(TAXONOMIES_REPOSITORY)
@ -25,12 +27,12 @@ export class OldDBTasksService { @@ -25,12 +27,12 @@ export class OldDBTasksService {
private readonly usersRepository: IUsersRepository
@Inject(TASKS_EVENTS_SERVICE)
private readonly tasksEventsService: Tasks.ITasksEventsService
@Inject(TASKS_REPOSITORY) private readonly tasksRepository: ITasksRepository
constructor(@InjectConnection('old') private readonly connection: Connection) {}
public async run() {
const oldTasks = await this.getOldTasks()
for await (const oldTask of oldTasks) {
try {
await this.saveTask(oldTask)
@ -66,11 +68,12 @@ export class OldDBTasksService { @@ -66,11 +68,12 @@ export class OldDBTasksService {
: new Date(Number(oldTask.created_at)).toDateString()
const status = this.getStatus(oldTask)
const task = await this.tasksService.saveTask({
const task = await this.tasksRepository.save({
id: oldTask.id,
name: oldTask.name,
description: oldTask.description,
startDate: oldTask.start_date,
endDate: oldTask.end_date,
startDate: dateToSqlFormat(new Date(oldTask.start_date)),
endDate: dateToSqlFormat(new Date(oldTask.end_date)),
groupId: newGroupId,
reasonId: newReasonId,
authorId: newAuthorId,
@ -79,11 +82,14 @@ export class OldDBTasksService { @@ -79,11 +82,14 @@ export class OldDBTasksService {
createdAt,
doneDate: oldTask.done_date,
status,
isReadByAll: true,
})
await this.tasksRepository.update(task.id, { id: oldTask.id })
await this.oldDbRelationsRepository.insert({
oldId: oldTask.id,
newId: task.id,
newId: oldTask.id,
type: OldDbRelationType.Tasks,
})
}

3
src/domain/tasks/entities/task.entity.ts

@ -71,6 +71,9 @@ export class Task implements Tasks.TaskModel { @@ -71,6 +71,9 @@ export class Task implements Tasks.TaskModel {
@Column({ nullable: true, select: false })
offlineKey?: string
@Column({ nullable: true })
isReadByAll?: boolean
@CreateDateColumn({ type: 'timestamp', default: () => 'LOCALTIMESTAMP' })
createdAt: string

1
src/domain/tasks/tasks.module.ts

@ -47,7 +47,6 @@ export class TasksModule { @@ -47,7 +47,6 @@ export class TasksModule {
provideEntity(TASKS_REPOSITORY, Task),
provideEntity(TASKS_COMMENTS_RELATIONS_REPOSITORY, TaskCommentRelation),
provideEntity(TASKS_DOCUMENTS_REPOSITORY, TaskDocument),
provideEntity(TASKS_REPOSITORY, Task),
provideEntity(TASKS_EVENTS_REPOSITORY, TaskEvent),
provideEntity(TASKS_FAVORITES_REPOSITORY, TaskFavorite),
...TASKS_SERVICES,

Loading…
Cancel
Save