62 lines
1.7 KiB
TypeScript
62 lines
1.7 KiB
TypeScript
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
|
|
import sendemail from "./routes/sendMail.js";
|
|
import { tryCatch } from "../../globalUtils/tryCatch.js";
|
|
import { db } from "../../../database/dbclient.js";
|
|
|
|
import { notifications } from "../../../database/schema/notifications.js";
|
|
import { createLog } from "../logger/logger.js";
|
|
import { note, notificationCreate } from "./utils/masterNotifications.js";
|
|
import { startNotificationMonitor } from "./utils/processNotifications.js";
|
|
import notifyStats from "./routes/getActiveNotifications.js";
|
|
|
|
const app = new OpenAPIHono();
|
|
|
|
const routes = [sendemail, notifyStats] as const;
|
|
|
|
const appRoutes = routes.forEach((route) => {
|
|
app.route("/notify", route);
|
|
});
|
|
|
|
app.all("/notify/*", (c) => {
|
|
return c.json({
|
|
success: false,
|
|
message: "you have encounted a notication route that dose not exist.",
|
|
});
|
|
});
|
|
|
|
// check if the mastNotications is changed compared to the db and add if needed.
|
|
const { data: notes, error: notesError } = await tryCatch(
|
|
db.select().from(notifications)
|
|
);
|
|
|
|
if (notesError) {
|
|
createLog(
|
|
"error",
|
|
"notify",
|
|
"notify",
|
|
`There was an error getting the notifications: ${JSON.stringify(
|
|
notesError
|
|
)}`
|
|
);
|
|
}
|
|
|
|
if (note.length != notes?.length) {
|
|
notificationCreate();
|
|
createLog("info", "notify", "notify", `New notifcations being added.`);
|
|
setTimeout(() => {
|
|
startNotificationMonitor();
|
|
}, 5 * 1000);
|
|
} else {
|
|
createLog(
|
|
"info",
|
|
"notify",
|
|
"notify",
|
|
`There are know new notifcations. no need to run the update. reminder all changes happen per server.`
|
|
);
|
|
setTimeout(() => {
|
|
startNotificationMonitor();
|
|
}, 5 * 1000);
|
|
}
|
|
export default app;
|