Skip to content

Commit

Permalink
zodded realm notifications endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Reptapog committed Jan 19, 2024
1 parent 70c80a4 commit 5667989
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
7 changes: 5 additions & 2 deletions server/realms/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import {
Internal500Error,
NotFound404Error,
} from "handlers/api-errors/codes";
import {
NotificationsResponseSchema,
RealmSchema,
} from "types/open-api/generated/schemas";
import {
acceptInvite,
checkUserOnRealm,
Expand All @@ -30,7 +34,6 @@ import {

import { DbRealmBoardType } from "server/boards/sql/types";
import { RealmPermissions } from "types/permissions";
import { RealmSchema } from "types/open-api/generated/schemas";
import { createInvite } from "server/realms/queries";
import debug from "debug";
import express from "express";
Expand Down Expand Up @@ -277,7 +280,7 @@ router.get("/:realm_id/notifications", ensureLoggedIn, async (req, res) => {
pinned_boards: pinned,
realm_boards: realmBoards,
};
res.status(200).json(notificationsDataResponse);
res.status(200).json(NotificationsResponseSchema.parse(notificationsDataResponse));
});

/**
Expand Down
2 changes: 1 addition & 1 deletion server/realms/tests/notifications.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe("Tests notifications REST API", () => {

expect(res.status).toBe(200);
expect(res.body).toEqual(BOBATAN_NOTIFICATIONS);
log(res.body);
// log(res.body);
});

// TODO: check if any test user has outdated notifications or none, and test there
Expand Down
6 changes: 3 additions & 3 deletions types/open-api/generated/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ const ActivityNotifications = z.object({
id: z.string().uuid(),
has_updates: z.boolean(),
is_outdated: z.boolean(),
last_activity_at: z.union([z.string(), z.null()]),
last_activity_from_others_at: z.union([z.string(), z.null()]),
last_visited_at: z.union([z.string(), z.null()]),
last_activity_at: z.union([z.date(), z.null()]),
last_activity_from_others_at: z.union([z.date(), z.null()]),
last_visited_at: z.union([z.date(), z.null()]),
});
const NotificationsResponse = z.object({
has_notifications: z.boolean(),
Expand Down
1 change: 1 addition & 0 deletions types/open-api/notifications.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ components:
is_outdated:
description: Whether the board's notifications are older than the user's last visit.
type: boolean
# zod client generation does not generate for date and date-time types
last_activity_at:
description: When the board was last updated.
oneOf:
Expand Down

0 comments on commit 5667989

Please sign in to comment.