fixing platform admin

This commit is contained in:
root
2026-05-06 22:58:23 -04:00
parent 695a7f7cc7
commit 750ae56a29
175 changed files with 31249 additions and 328 deletions
+51
View File
@@ -23,6 +23,15 @@ router.get('/company', ...companyAuth, async (req: any, res: any, next: any) =>
} catch (err) { next(err) }
})
router.get('/unread-count', ...companyAuth, async (req: any, res: any, next: any) => {
try {
const unread = await prisma.notification.count({
where: { companyId: req.companyId, channel: 'IN_APP', readAt: null },
})
res.json({ data: { unread } })
} catch (err) { next(err) }
})
router.post('/company/:id/read', ...companyAuth, async (req: any, res: any, next: any) => {
try {
await prisma.notification.updateMany({ where: { id: req.params.id, companyId: req.companyId }, data: { readAt: new Date(), status: 'READ' } })
@@ -74,4 +83,46 @@ router.post('/renter/:id/read', requireRenterAuth, async (req: any, res: any, ne
} catch (err) { next(err) }
})
router.post('/renter/read-all', requireRenterAuth, async (req: any, res: any, next: any) => {
try {
await prisma.notification.updateMany({
where: { renterId: req.renterId, channel: 'IN_APP', readAt: null },
data: { readAt: new Date(), status: 'READ' },
})
res.json({ data: { success: true } })
} catch (err) { next(err) }
})
router.get('/renter/preferences', requireRenterAuth, async (req: any, res: any, next: any) => {
try {
const prefs = await prisma.notificationPreference.findMany({ where: { renterId: req.renterId } })
res.json({ data: prefs })
} catch (err) { next(err) }
})
router.patch('/renter/preferences', requireRenterAuth, async (req: any, res: any, next: any) => {
try {
const body = z.array(z.object({ notificationType: z.string(), channel: z.string(), enabled: z.boolean() })).parse(req.body)
for (const pref of body) {
await prisma.notificationPreference.upsert({
where: {
renterId_notificationType_channel: {
renterId: req.renterId,
notificationType: pref.notificationType as NotificationType,
channel: pref.channel as NotificationChannel,
},
},
create: {
renterId: req.renterId,
notificationType: pref.notificationType as NotificationType,
channel: pref.channel as NotificationChannel,
enabled: pref.enabled,
},
update: { enabled: pref.enabled },
})
}
res.json({ data: { success: true } })
} catch (err) { next(err) }
})
export default router