feat(notifications): migrated all from v1
This commit is contained in:
@@ -1,9 +1,17 @@
|
||||
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] as const;
|
||||
const routes = [sendemail, notifyStats] as const;
|
||||
|
||||
const appRoutes = routes.forEach((route) => {
|
||||
app.route("/notify", route);
|
||||
@@ -16,4 +24,37 @@ app.all("/notify/*", (c) => {
|
||||
});
|
||||
});
|
||||
|
||||
// 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;
|
||||
|
||||
Reference in New Issue
Block a user