8d742518f8
- Client management (CRUD with JSONB custom fields) - Pet profiles - Service catalog with per-client pricing - Booking calendar with recurring appointments - Invoicing with Stripe integration - Real-time messaging (WebSocket) - Self-booking portal - Staff assignment - Docker multi-stage builds - Prisma schema + seed
42 lines
1.0 KiB
TypeScript
42 lines
1.0 KiB
TypeScript
import { Injectable, NotFoundException } from '@nestjs/common';
|
|
import { PrismaService } from '../prisma/prisma.service';
|
|
import { SendMessageDto } from './dto/message.dto';
|
|
|
|
@Injectable()
|
|
export class MessagesService {
|
|
constructor(private prisma: PrismaService) {}
|
|
|
|
async getConversation(clientId: string, staffId: string) {
|
|
await this.prisma.client.findUniqueOrThrow({ where: { id: clientId } });
|
|
|
|
return this.prisma.message.findMany({
|
|
where: {
|
|
clientId,
|
|
},
|
|
orderBy: { createdAt: 'asc' },
|
|
});
|
|
}
|
|
|
|
async getUnreadCount(clientId: string, staffId: string) {
|
|
const count = await this.prisma.message.count({
|
|
where: {
|
|
clientId,
|
|
readAt: null,
|
|
},
|
|
});
|
|
return { unreadCount: count };
|
|
}
|
|
|
|
async markAsRead(clientId: string, messageIds: string[]) {
|
|
await this.prisma.client.findUniqueOrThrow({ where: { id: clientId } });
|
|
|
|
return this.prisma.message.updateMany({
|
|
where: {
|
|
id: { in: messageIds },
|
|
clientId,
|
|
},
|
|
data: { readAt: new Date() },
|
|
});
|
|
}
|
|
}
|