diff --git a/apps/main/src/lib/api.ts b/apps/main/src/lib/api.ts index 4ec94cd..64d841e 100644 --- a/apps/main/src/lib/api.ts +++ b/apps/main/src/lib/api.ts @@ -1,12 +1,10 @@ -import { notificationsRouter } from "@pkg/logic/domains/notifications/router"; import { usersRouter } from "@pkg/logic/domains/user/router"; import { twofaRouter } from "@pkg/logic/domains/2fa/router"; import { Hono } from "hono"; const baseRouter = new Hono() .route("/users", usersRouter) - .route("/twofactor", twofaRouter) - .route("/notifications", notificationsRouter); + .route("/twofactor", twofaRouter); export const apiBasePath = "/api/v1"; diff --git a/apps/main/src/lib/domains/security/twofa.remote.ts b/apps/main/src/lib/domains/security/twofa.remote.ts new file mode 100644 index 0000000..e69de29 diff --git a/packages/logic/domains/notifications/router.ts b/packages/logic/domains/notifications/router.ts deleted file mode 100644 index 0e2781e..0000000 --- a/packages/logic/domains/notifications/router.ts +++ /dev/null @@ -1,160 +0,0 @@ -import { bulkNotificationIdsSchema, getNotificationsSchema } from "./data"; -import { getNotificationController } from "./controller"; -import { sValidator } from "@hono/standard-validator"; -import { HonoContext } from "@core/hono.helpers"; -import { Hono } from "hono"; - -const nc = getNotificationController(); - -export const notificationsRouter = new Hono() - .get("/", async (c) => { - const fctx = c.env.locals.fCtx; - const userId = c.env.locals.user.id; - const url = new URL(c.req.url); - - const filters = { - userId, - isRead: url.searchParams.get("isRead") - ? url.searchParams.get("isRead") === "true" - : undefined, - isArchived: url.searchParams.get("isArchived") - ? url.searchParams.get("isArchived") === "true" - : undefined, - type: url.searchParams.get("type") || undefined, - category: url.searchParams.get("category") || undefined, - priority: url.searchParams.get("priority") || undefined, - search: url.searchParams.get("search") || undefined, - }; - - const pagination = { - page: parseInt(url.searchParams.get("page") || "1"), - pageSize: parseInt(url.searchParams.get("pageSize") || "20"), - sortBy: url.searchParams.get("sortBy") || "createdAt", - sortOrder: url.searchParams.get("sortOrder") || "desc", - }; - - const res = await nc.getNotifications(fctx, filters, pagination); - return c.json( - res.isOk() - ? { data: res.value, error: null } - : { data: null, error: res.error }, - res.isOk() ? 200 : 400, - ); - }) - .post( - "/get-notifications", - sValidator("json", getNotificationsSchema), - async (c) => { - const fctx = c.env.locals.fCtx; - const data = c.req.valid("json"); - const res = await nc.getNotifications(fctx, data.filters, data.pagination); - return c.json( - res.isOk() - ? { data: res.value, error: null } - : { data: null, error: res.error }, - res.isOk() ? 200 : 400, - ); - }, - ) - .put( - "/mark-read", - sValidator("json", bulkNotificationIdsSchema), - async (c) => { - const fctx = c.env.locals.fCtx; - const data = c.req.valid("json"); - const userId = c.env.locals.user.id; - const res = await nc.markAsRead(fctx, [...data.notificationIds], userId); - return c.json( - res.isOk() - ? { data: res.value, error: null } - : { data: null, error: res.error }, - res.isOk() ? 200 : 400, - ); - }, - ) - .put( - "/mark-unread", - sValidator("json", bulkNotificationIdsSchema), - async (c) => { - const fctx = c.env.locals.fCtx; - const data = c.req.valid("json"); - const userId = c.env.locals.user.id; - const res = await nc.markAsUnread(fctx, [...data.notificationIds], userId); - return c.json( - res.isOk() - ? { data: res.value, error: null } - : { data: null, error: res.error }, - res.isOk() ? 200 : 400, - ); - }, - ) - .put( - "/archive", - sValidator("json", bulkNotificationIdsSchema), - async (c) => { - const fctx = c.env.locals.fCtx; - const data = c.req.valid("json"); - const userId = c.env.locals.user.id; - const res = await nc.archive(fctx, [...data.notificationIds], userId); - return c.json( - res.isOk() - ? { data: res.value, error: null } - : { data: null, error: res.error }, - res.isOk() ? 200 : 400, - ); - }, - ) - .put( - "/unarchive", - sValidator("json", bulkNotificationIdsSchema), - async (c) => { - const fctx = c.env.locals.fCtx; - const data = c.req.valid("json"); - const userId = c.env.locals.user.id; - const res = await nc.unarchive(fctx, [...data.notificationIds], userId); - return c.json( - res.isOk() - ? { data: res.value, error: null } - : { data: null, error: res.error }, - res.isOk() ? 200 : 400, - ); - }, - ) - .delete( - "/delete", - sValidator("json", bulkNotificationIdsSchema), - async (c) => { - const fctx = c.env.locals.fCtx; - const data = c.req.valid("json"); - const userId = c.env.locals.user.id; - const res = await nc.deleteNotifications(fctx, [...data.notificationIds], userId); - return c.json( - res.isOk() - ? { data: res.value, error: null } - : { data: null, error: res.error }, - res.isOk() ? 200 : 400, - ); - }, - ) - .put("/mark-all-read", async (c) => { - const fctx = c.env.locals.fCtx; - const userId = c.env.locals.user.id; - const res = await nc.markAllAsRead(fctx, userId); - return c.json( - res.isOk() - ? { data: res.value, error: null } - : { data: null, error: res.error }, - res.isOk() ? 200 : 400, - ); - }) - .get("/unread-count", async (c) => { - const fctx = c.env.locals.fCtx; - const userId = c.env.locals.user.id; - const res = await nc.getUnreadCount(fctx, userId); - return c.json( - res.isOk() - ? { data: res.value, error: null } - : { data: null, error: res.error }, - res.isOk() ? 200 : 400, - ); - });