Browse Source

Change and fix

merge-requests/239/head
Oksana Stepanenko 2 years ago committed by Coder
parent
commit
cbd61264cb
  1. 1
      src/core/namespaces/tasks.namespace.ts
  2. 2
      src/domain/old-database-seed/services/users.service.ts
  3. 2
      src/domain/permissions/services/users-permissions.service.ts
  4. 37
      src/domain/tasks/services/tasks.service.ts
  5. 15
      src/rest/admin/tasks/services/admin-tasks.service.ts
  6. 33
      src/rest/app/tasks/services/app-tasks.service.ts

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

@ -116,6 +116,7 @@ export namespace Tasks { @@ -116,6 +116,7 @@ export namespace Tasks {
/** Офлайн ключ - ідентифікатор, з яким створюється задача в режимі офлайн */
offlineKey?: string
/** Чи має дана задача статус "Прочитана всіма" */
isReadByAll?: boolean
}

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

@ -66,7 +66,7 @@ export class OldDBUsersService { @@ -66,7 +66,7 @@ export class OldDBUsersService {
if (existRelation) return
const nameArr = oldUser.name.split(' ')
const nameArr = oldUser.name.trim().split(' ')
const newAvatarUrl = await this.getNewAvatarUrl(oldUser.avatar)
const userId = await this.usersService.save(

2
src/domain/permissions/services/users-permissions.service.ts

@ -43,6 +43,8 @@ export class UsersPermissionsService { @@ -43,6 +43,8 @@ export class UsersPermissionsService {
await this.usersPermissionsRepository.update({ userId }, { permissions: null })
this.eventEmitter.emit(Events.OnChangeUserPermission, { userId })
this.wsService.emitToUser(userId, 'user/change-permissions')
}
public async getOne(userId: number): Promise<Permissions.IUserPermissions> {

37
src/domain/tasks/services/tasks.service.ts

@ -219,11 +219,15 @@ export class TasksService implements Tasks.ITasksService { @@ -219,11 +219,15 @@ export class TasksService implements Tasks.ITasksService {
doneDate: new Date(date).toISOString(),
})
await this.afterSaveTask('task/finish-task', {
taskId: id,
executorId: task.executorId,
events: this.transformEvents(task.events),
})
await this.afterSaveTask(
'task/finish-task',
{
taskId: id,
executorId: task.executorId,
events: this.transformEvents(task.events),
},
task.isReadByAll,
)
this.eventEmitter.emit(Events.OnUpdateEntity, {
type: Versions.EntityType.Task,
@ -299,11 +303,15 @@ export class TasksService implements Tasks.ITasksService { @@ -299,11 +303,15 @@ export class TasksService implements Tasks.ITasksService {
status: Tasks.Status.Deleted,
})
await this.afterSaveTask('task/delete-task', {
taskId: id,
executorId: task.executorId,
events: this.transformEvents(task.events),
})
await this.afterSaveTask(
'task/delete-task',
{
taskId: id,
executorId: task.executorId,
events: this.transformEvents(task.events),
},
task.isReadByAll,
)
this.eventEmitter.emit(Events.OnUpdateEntity, {
type: Versions.EntityType.Task,
@ -571,6 +579,7 @@ export class TasksService implements Tasks.ITasksService { @@ -571,6 +579,7 @@ export class TasksService implements Tasks.ITasksService {
.createQueryBuilder('it')
.leftJoinAndSelect('it.events', 'events')
.andWhere('it.status = :active', { active: Tasks.Status.Active })
.andWhere('it.isReadByAll IS NOT TRUE')
const role = await this.usersService.getUserRole(userId)
@ -610,9 +619,13 @@ export class TasksService implements Tasks.ITasksService { @@ -610,9 +619,13 @@ export class TasksService implements Tasks.ITasksService {
return _.uniq(userIds)
}
private async afterSaveTask(eventKey: string, data?: any) {
private async afterSaveTask(eventKey: string, data?: any, addReadByUser?: boolean) {
const usersIds = await this.wsService.getUsersOnlineIds()
usersIds.map(it => this.wsService.emitToUser(it, eventKey, data))
usersIds.map(it => {
if (addReadByUser && data.events) data.events.push({ [it]: Tasks.Event.Read })
this.wsService.emitToUser(it, eventKey, data)
})
}
private transformEvents(events: Tasks.ITaskEvent[]): Record<string, Tasks.Event>[] {

15
src/rest/admin/tasks/services/admin-tasks.service.ts

@ -98,18 +98,21 @@ export class AdminTasksService { @@ -98,18 +98,21 @@ export class AdminTasksService {
* @returns Повертає детальну інформацію про задачу з коментарями та документами
*/
public async getTask(taskId: number, userId: number) {
const task = await this.tasksService.getOneTask(taskId, userId, {
// withComments: true,
// withDocuments: true,
withUsersInfo: true,
withTaxonomies: true,
})
await this.tasksEventsService.addEvent({
taskId: taskId,
userId: userId,
event: Tasks.Event.Read,
allowDuplicate: false,
})
return this.tasksService.getOneTask(taskId, userId, {
// withComments: true,
// withDocuments: true,
withUsersInfo: true,
withTaxonomies: true,
})
return task
}
public async update(id: number, userId: number, dto: UpdateTaskDto) {

33
src/rest/app/tasks/services/app-tasks.service.ts

@ -143,13 +143,18 @@ export class AppTasksService { @@ -143,13 +143,18 @@ export class AppTasksService {
const taskForResponse: Tasks.ITaskForResponse = {
...task,
isRead: _.some(
task.events,
it => it.userId === userId && it.event === Tasks.Event.Read,
),
isRead: task.isReadByAll
? true
: _.some(task.events, it => it.userId === userId && it.event === Tasks.Event.Read),
events: this.transformEvents(task.events),
}
if (task.isReadByAll && !task.events[userId])
taskForResponse.events = {
...taskForResponse.events,
[`${userId}`]: Tasks.Event.Read,
}
return taskForResponse
}
@ -177,10 +182,12 @@ export class AppTasksService { @@ -177,10 +182,12 @@ export class AppTasksService {
_.find(it.favorites, favorite => favorite.userId === userId),
)
item.isRead = _.some(
it.events,
item => item.userId === userId && item.event === Tasks.Event.Read,
)
item.isRead = it.isReadByAll
? true
: _.some(
it.events,
item => item.userId === userId && item.event === Tasks.Event.Read,
)
item.hasComments = item.commentRelations
? item.commentRelations.length > 0
@ -458,10 +465,12 @@ export class AppTasksService { @@ -458,10 +465,12 @@ export class AppTasksService {
)
const comments = await this.tasksService.getTaskComments(item.id)
const isRead = _.some(
item.events,
it => it.userId === userId && it.event === Tasks.Event.Read,
)
const isRead = item.isReadByAll
? true
: _.some(
item.events,
it => it.userId === userId && it.event === Tasks.Event.Read,
)
return {
..._.omit(item, ['favorites']),
isFavorite,

Loading…
Cancel
Save