This commit is contained in:
2026-07-19 19:45:32 +08:00
parent b68bfc6287
commit bbfc055c21
12 changed files with 910 additions and 431 deletions
+16 -12
View File
@@ -123,6 +123,20 @@ export async function getCaregiverOverview(caregiverId: string) {
};
}
export function getCaregiverUnreadIncomingCount(caregiverId: string) {
return prisma.familyMessage.count({
where: {
direction: MessageDirection.ELDER_TO_FAMILY,
elderDevice: {
bindings: {
some: { caregiverId },
},
},
readAt: null,
},
});
}
export async function getCaregiverMessages(caregiverId: string) {
const [messages, unreadIncomingCount, unreadOutgoingCount] = await prisma.$transaction([
prisma.familyMessage.findMany({
@@ -141,17 +155,7 @@ export async function getCaregiverMessages(caregiverId: string) {
orderBy: [{ createdAt: "desc" }, { publicId: "desc" }],
take: 120,
}),
prisma.familyMessage.count({
where: {
direction: MessageDirection.ELDER_TO_FAMILY,
elderDevice: {
bindings: {
some: { caregiverId },
},
},
readAt: null,
},
}),
getCaregiverUnreadIncomingCount(caregiverId),
prisma.familyMessage.count({
where: {
direction: MessageDirection.FAMILY_TO_ELDER,
@@ -394,4 +398,4 @@ export async function getCaregiverSettingsOverview(caregiverId: string) {
deviceCount,
pushSubscriptionCount,
};
}
}