test(notification): added framework for managment tab
This commit is contained in:
30
server/services/notifications/controller/getNotifications.ts
Normal file
30
server/services/notifications/controller/getNotifications.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { and, desc, eq, gte, inArray, lte, sql } from "drizzle-orm";
|
||||
import { db } from "../../../../database/dbclient.js";
|
||||
import { logs } from "../../../../database/schema/logs.js";
|
||||
import { createLog } from "../../logger/logger.js";
|
||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||
import { notifications } from "../../../../database/schema/notifications.js";
|
||||
|
||||
export const getNotifications = async () => {
|
||||
const { data, error } = await tryCatch(db.select().from(notifications));
|
||||
|
||||
if (error) {
|
||||
createLog(
|
||||
"error",
|
||||
"notify",
|
||||
"notify",
|
||||
`Error getting notifications: ${error}`
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
message: "Error getting notifications.",
|
||||
data: error,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
sucess: true,
|
||||
message: "Current notifications.",
|
||||
data: data,
|
||||
};
|
||||
};
|
||||
@@ -11,10 +11,11 @@ import { startNotificationMonitor } from "./utils/processNotifications.js";
|
||||
import notifyStats from "./routes/getActiveNotifications.js";
|
||||
import tiTrigger from "./routes/manualTiggerTi.js";
|
||||
import blocking from "./routes/qualityBlocking.js";
|
||||
import notify from "./routes/getNotifications.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
const routes = [sendemail, notifyStats, tiTrigger, blocking] as const;
|
||||
const routes = [sendemail, notifyStats, tiTrigger, blocking, notify] as const;
|
||||
|
||||
const appRoutes = routes.forEach((route) => {
|
||||
app.route("/notify", route);
|
||||
|
||||
44
server/services/notifications/routes/getNotifications.ts
Normal file
44
server/services/notifications/routes/getNotifications.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
// an external way to creating logs
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
//import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||
import { getNotifications } from "../controller/getNotifications.js";
|
||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["notify"],
|
||||
summary: "Gets notifications.",
|
||||
method: "get",
|
||||
path: "/notifications",
|
||||
// description:
|
||||
// "This might be a temp soltuin during the transtion between versions",
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c: any) => {
|
||||
//apiHit(c, { endpoint: `api/logger/logs` });
|
||||
const { data, error } = await tryCatch(getNotifications());
|
||||
|
||||
if (error) {
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
message: "There was an error clearing the log.",
|
||||
data: error,
|
||||
},
|
||||
400
|
||||
);
|
||||
}
|
||||
return c.json(
|
||||
{
|
||||
success: data?.success,
|
||||
message: data?.message,
|
||||
data: data?.data,
|
||||
},
|
||||
200
|
||||
);
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
Reference in New Issue
Block a user