feat: Full petmaster CRM with NestJS API and React frontend
- 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
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
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() },
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user