also change some var names and headings to reflect when data is in borrower role and when data is in lender
50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
'use server'
|
|
|
|
import { getPayload } from 'payload'
|
|
import config from '@/payload.config'
|
|
import { Checkout } from '@/payload-types'
|
|
|
|
type Props = {
|
|
checkoutId: number
|
|
}
|
|
export const loaneeReturnCheckout = async (props: Props): Promise<Checkout | null> => {
|
|
const { checkoutId } = props
|
|
|
|
const payloadConfig = await config
|
|
const payload = await getPayload({ config: payloadConfig })
|
|
|
|
try {
|
|
const updatedCheckout = await payload.update({
|
|
collection: 'checkouts',
|
|
id: checkoutId,
|
|
data: {
|
|
loaneeReturnedDate: new Date().toDateString(),
|
|
}
|
|
})
|
|
return updatedCheckout
|
|
} catch (err) {
|
|
console.log(err)
|
|
return null
|
|
}
|
|
}
|
|
|
|
export const ownerReturnCheckout = async (props: Props): Promise<Checkout | null> => {
|
|
const { checkoutId } = props
|
|
|
|
const payloadConfig = await config
|
|
const payload = await getPayload({ config: payloadConfig })
|
|
|
|
try {
|
|
const updatedCheckout = await payload.update({
|
|
collection: 'checkouts',
|
|
id: checkoutId,
|
|
data: {
|
|
ownerVerifiedReturnedDate: new Date().toString(),
|
|
}
|
|
})
|
|
return updatedCheckout
|
|
} catch (_) {
|
|
return null
|
|
}
|
|
}
|