also change some var names and headings to reflect when data is in borrower role and when data is in lender
54 lines
1.1 KiB
TypeScript
54 lines
1.1 KiB
TypeScript
'use server'
|
|
|
|
import { getPayload } from 'payload'
|
|
import config from '@/payload.config'
|
|
import type { PaginatedDocs } from "payload"
|
|
import { Checkout } from '@/payload-types'
|
|
|
|
type Props = {
|
|
userId: number
|
|
}
|
|
export const getUserBorrows = async (props: Props) => {
|
|
const { userId } = props
|
|
|
|
const payloadConfig = await config
|
|
const payload = await getPayload({ config: payloadConfig })
|
|
|
|
let userBorrows: PaginatedDocs<Checkout> | null = null
|
|
if (userId)
|
|
userBorrows = await payload.find({
|
|
collection: 'checkouts',
|
|
depth: 3,
|
|
limit: 10,
|
|
select: {
|
|
id: true,
|
|
copy: true,
|
|
dateDue: true,
|
|
ownerVerifiedReturnedDate: true,
|
|
loaneeReturnedDate: true,
|
|
},
|
|
sort: 'dateDue',
|
|
where: {
|
|
and: [
|
|
{
|
|
isReturned: {
|
|
not_equals: true,
|
|
},
|
|
},
|
|
{
|
|
'user.id': {
|
|
equals: userId,
|
|
},
|
|
},
|
|
{
|
|
ownerVerifiedReturnedDate: {
|
|
equals: null,
|
|
},
|
|
}
|
|
],
|
|
},
|
|
}) as PaginatedDocs<Checkout>
|
|
|
|
return userBorrows
|
|
}
|