Notification UI and house invitation

This commit is contained in:
2026-02-19 19:16:26 +07:00
parent 84ed1e6c21
commit fa689ea4aa
35 changed files with 2592 additions and 112 deletions

80
src/service/notify.api.ts Normal file
View File

@@ -0,0 +1,80 @@
import { prisma } from '@/db';
import { parseError } from '@lib/errors';
import { authMiddleware } from '@lib/middleware';
import { createServerFn } from '@tanstack/react-start';
import { notificationListSchema } from './notify.schema';
export const getTopFiveNotification = createServerFn({ method: 'GET' })
.middleware([authMiddleware])
.handler(async ({ context: { user } }) => {
try {
const list = await prisma.notification.findMany({
where: {
userId: user.id,
},
orderBy: {
createdAt: 'asc',
},
take: 5,
});
return list;
} catch (error) {
console.error(error);
const { message, code } = parseError(error);
throw { message, code };
}
});
export const getAllNotifications = createServerFn({ method: 'GET' })
.middleware([authMiddleware])
.inputValidator(notificationListSchema)
.handler(async ({ data, context: { user } }) => {
try {
const skip = (data.page - 1) * data.limit;
const [list, total]: [NotificationWithUser[], number] =
await prisma.$transaction([
prisma.notification.findMany({
where: {
userId: user.id,
},
include: {
user: {
select: {
id: true,
name: true,
email: true,
image: true,
},
},
},
orderBy: {
createdAt: 'asc',
},
take: data.limit,
skip,
}),
prisma.notification.count({
where: {
userId: user.id,
},
}),
]);
const totalPage = Math.ceil(+total / data.limit);
return {
result: list,
pagination: {
currentPage: data.page,
totalPage,
totalItem: total,
},
};
} catch (error) {
console.error(error);
const { message, code } = parseError(error);
throw { message, code };
}
});