refactor(ocp): change the way logs are brought in and other changes to clean the code up
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import {eq, sql} from "drizzle-orm";
|
||||
import {db} from "../../../../database/dbclient.js";
|
||||
import {logs} from "../../../../database/schema/logs.js";
|
||||
import {createLog} from "../logger.js";
|
||||
import { eq, sql } from "drizzle-orm";
|
||||
import { db } from "../../../../database/dbclient.js";
|
||||
import { logs } from "../../../../database/schema/logs.js";
|
||||
import { createLog } from "../logger.js";
|
||||
|
||||
export const clearLog = async (id: string) => {
|
||||
/**
|
||||
@@ -10,13 +10,21 @@ export const clearLog = async (id: string) => {
|
||||
|
||||
try {
|
||||
const clear = await db
|
||||
.update(logs)
|
||||
.set({checked: true, checkedAt: sql`NOW()`})
|
||||
.where(eq(logs.log_id, id));
|
||||
.update(logs)
|
||||
.set({ checked: true, created_at: sql`NOW()` })
|
||||
.where(eq(logs.log_id, id));
|
||||
createLog("info", "lst", "logger", "Log just cleared.");
|
||||
return {success: true, message: "Log was just cleared."};
|
||||
return { success: true, message: "Log was just cleared." };
|
||||
} catch (error) {
|
||||
createLog("error", "lst", "logger", "There was an error clearing the log.");
|
||||
return {success: false, message: "There was an error clearing the log."};
|
||||
createLog(
|
||||
"error",
|
||||
"lst",
|
||||
"logger",
|
||||
"There was an error clearing the log."
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
message: "There was an error clearing the log.",
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { and, eq, gte, inArray, lte, sql } from "drizzle-orm";
|
||||
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.js";
|
||||
@@ -21,7 +21,8 @@ export const getLogs = async (data: any) => {
|
||||
inArray(logs.level, data.level),
|
||||
eq(logs.checked, checked)
|
||||
)
|
||||
);
|
||||
)
|
||||
.orderBy(desc(logs.created_at));
|
||||
|
||||
return { success: true, message: "logs returned", data: logData };
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user