33 lines
962 B
TypeScript
33 lines
962 B
TypeScript
import { desc, lte, sql } from "drizzle-orm";
|
|
import { db } from "../../../../../database/dbclient.js";
|
|
import { prodlabels } from "../../../../../database/schema/prodLabels.js";
|
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
|
export const getLabels = async (hours: string) => {
|
|
const { data: labelInfo, error: labelError } = await tryCatch(
|
|
db
|
|
.select()
|
|
.from(prodlabels)
|
|
.where(
|
|
lte(
|
|
prodlabels.upd_date,
|
|
sql.raw(`NOW() - INTERVAL '${hours} hours'`)
|
|
)
|
|
)
|
|
.orderBy(desc(prodlabels.upd_date))
|
|
);
|
|
|
|
if (labelError) {
|
|
return {
|
|
success: false,
|
|
message: "There was an error getting the labels",
|
|
data: labelError,
|
|
};
|
|
}
|
|
|
|
return {
|
|
success: true,
|
|
message: "Current labels order by upd_Date.",
|
|
data: labelInfo,
|
|
};
|
|
};
|