Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/app/api/notifications/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { notificationEvents } from '@/utils/notifications'
import { errorHandler } from '@/utils/common'
import httpStatus from 'http-status'
import { ApiError } from '@/exceptions/ApiError'
import { z } from 'zod'

export async function GET(request: NextRequest) {
try {
Expand Down Expand Up @@ -31,12 +32,21 @@ export async function GET(request: NextRequest) {
tasks: taskCounts,
}

notifications.forEach(({ event }) => {
if (event === notificationEvents.forms) {
notifications.forEach((notification) => {
const notificationCompanyId = z
.string()
.min(1)
// We use both fields for backwards compatibility
.parse(notification.recipientCompanyId || notification.companyId)
if (companyId !== notificationCompanyId) {
return
}

if (notification.event === notificationEvents.forms) {
counts.forms += 1
} else if (event === notificationEvents.billing) {
} else if (notification.event === notificationEvents.billing) {
counts.billing += 1
} else if (event === notificationEvents.contracts) {
} else if (notification.event === notificationEvents.contracts) {
counts.contracts += 1
}
})
Expand Down
2 changes: 2 additions & 0 deletions src/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ export type CustomFieldResponse = z.infer<typeof CustomFieldResponseSchema>
export const NotificationsSchema = z.array(
z.object({
event: z.string(),
companyId: z.string().optional(),
recipientCompanyId: z.string().optional(),
}),
)
export type Notifications = z.infer<typeof NotificationsSchema>
Expand Down
Loading