48 lines
1.0 KiB
JavaScript
48 lines
1.0 KiB
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 findComment(where, options = {}) {
|
|
return prisma.comment.findFirst({
|
|
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,
|
|
findComment
|
|
}
|