const crypto = require("node:crypto"); const DB = require("./connection"); exports.createCatalog = createCatalog; exports.getCatalogs = getCatalogs; exports.countCatalogs = countCatalogs; exports.updateCatalog = updateCatalog; async function createCatalog( owner_id, name, score, description ) { const [id] = await DB.table("events") .insert({ owner_id, name, score, description }) .returning("id"); return id; } async function updateCatalog( id, owner_id, name, score, description ) { await DB.table("events") .where("id",id) .where("owner_id", owner_id) .update({ name, score, description }); } async function getCatalogs( owner_id, offset, limit, searchTerm ) { return await DB.table("events") .where("owner_id",owner_id) .whereNull("deleted_at") .where("name","like",`%${searchTerm ?? ""}%`) .limit(limit) .offset(offset); } async function countCatalogs(owner_id, searchTerm) { return ( await DB.table("events") .where("owner_id",owner_id) .whereNull("deleted_at") .where("name","like",`%${searchTerm ?? ""}%`) .count("id as total") .first() ).total; }