improvement: notify counter badge added to treatment and tasks tabs for upadted and edited cases.
This commit is contained in:
@@ -5,7 +5,7 @@ import {
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
import { createReadStream, existsSync } from 'fs';
|
||||
import { CatalogEntityKind, LabTaskStatus, Prisma } from '@prisma/client';
|
||||
import { CatalogEntityKind, LabCaseActivityType, LabTaskStatus, Prisma } from '@prisma/client';
|
||||
import { PrismaService } from '../../../prisma/prisma.service';
|
||||
import { normalizeMobile } from '../../common/phone';
|
||||
import {
|
||||
@@ -20,6 +20,8 @@ import {
|
||||
} from '../../common/lab-case-due-date';
|
||||
import { normalizeTaskTeeth } from './lab-case-task.util';
|
||||
import { hasEffectivePermission } from '../../common/membership-permissions';
|
||||
import { LAB_CASES_TAB_ACTIVITY_TYPES } from '../../common/lab-case-activity';
|
||||
import { LabCaseActivityService } from '../notifications/lab-case-activity.service';
|
||||
|
||||
const labCaseListInclude = {
|
||||
treatment: {
|
||||
@@ -92,6 +94,7 @@ export class CasesService {
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly treatmentCatalog: TreatmentCatalogService,
|
||||
private readonly catalogLabels: CatalogLabelService,
|
||||
private readonly labCaseActivity: LabCaseActivityService,
|
||||
) {}
|
||||
|
||||
getOrganizationIdFromUser(user: { organizationId?: string }) {
|
||||
@@ -138,10 +141,21 @@ export class CasesService {
|
||||
this.prisma.labCase.count({ where }),
|
||||
]);
|
||||
|
||||
const unreadCaseIds = await this.labCaseActivity.unreadCaseIdsInBatch(
|
||||
actorUserId,
|
||||
labOrganizationId,
|
||||
items.map((lc) => lc.id),
|
||||
LAB_CASES_TAB_ACTIVITY_TYPES,
|
||||
'LAB',
|
||||
);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: {
|
||||
items: items.map((lc) => this.mapLabCaseListItem(lc)),
|
||||
items: items.map((lc) => ({
|
||||
...this.mapLabCaseListItem(lc),
|
||||
hasUnread: unreadCaseIds.has(lc.id),
|
||||
})),
|
||||
pagination: {
|
||||
page,
|
||||
limit,
|
||||
@@ -356,7 +370,7 @@ export class CasesService {
|
||||
sentAt: { not: null },
|
||||
sends: { some: { organizationId: labOrganizationId } },
|
||||
},
|
||||
select: { id: true },
|
||||
select: { id: true, isImportant: true },
|
||||
});
|
||||
|
||||
if (!existing) {
|
||||
@@ -368,6 +382,14 @@ export class CasesService {
|
||||
data: { isImportant: dto.isImportant },
|
||||
});
|
||||
|
||||
if (dto.isImportant && !existing.isImportant) {
|
||||
await this.labCaseActivity.record({
|
||||
labCaseId,
|
||||
type: LabCaseActivityType.CASE_IMPORTANT,
|
||||
actorUserId,
|
||||
});
|
||||
}
|
||||
|
||||
const labCase = await this.prisma.labCase.findFirstOrThrow({
|
||||
where: { id: labCaseId },
|
||||
include: labCaseListInclude,
|
||||
|
||||
Reference in New Issue
Block a user