HotTRDealsBackend/db/comment.db.js
2026-01-23 17:28:21 +00:00

40 lines
812 B
JavaScript

const prisma = require("./client")
function getDb(db) {
return db || prisma
}
async function findComments(where, options = {}) {
return prisma.comment.findMany({
where,
include: options.include || undefined,
select: options.select || undefined,
orderBy: options.orderBy || { createdAt: "desc" },
})
}
async function createComment(data, options = {}, db) {
const p = getDb(db)
return p.comment.create({
data,
include: options.include || undefined,
select: options.select || undefined,
})
}
async function deleteComment(where) {
return prisma.comment.delete({ where })
}
async function countComments(where = {}, db) {
const p = getDb(db)
return p.comment.count({ where })
}
module.exports = {
findComments,
countComments,
createComment,
deleteComment,
}