fix: harden booking and meeting flows
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import { cache } from "react";
|
||||
import { getCMS } from "@/lib/payload/getPayload";
|
||||
import type { BookingRequest } from "@/payload-types";
|
||||
import { customerBookingView, type CustomerBooking } from "./customerView";
|
||||
|
||||
/**
|
||||
* These are called only after the caller has already verified who the
|
||||
* current customer is (see lib/auth/customer.ts) — the `where: { user }`
|
||||
* filter below is what actually scopes results to that one customer.
|
||||
*/
|
||||
export const getCustomerBookings = cache(async (customerId: number): Promise<BookingRequest[]> => {
|
||||
export const getCustomerBookings = cache(async (customerId: number): Promise<CustomerBooking[]> => {
|
||||
const payload = await getCMS();
|
||||
const result = await payload.find({
|
||||
collection: "booking-requests",
|
||||
@@ -16,10 +16,10 @@ export const getCustomerBookings = cache(async (customerId: number): Promise<Boo
|
||||
depth: 2,
|
||||
limit: 200,
|
||||
});
|
||||
return result.docs;
|
||||
return result.docs.map(customerBookingView);
|
||||
});
|
||||
|
||||
export async function getCustomerBookingById(customerId: number, id: number): Promise<BookingRequest | null> {
|
||||
export async function getCustomerBookingById(customerId: number, id: number): Promise<CustomerBooking | null> {
|
||||
const payload = await getCMS();
|
||||
const result = await payload.find({
|
||||
collection: "booking-requests",
|
||||
@@ -27,5 +27,5 @@ export async function getCustomerBookingById(customerId: number, id: number): Pr
|
||||
depth: 2,
|
||||
limit: 1,
|
||||
});
|
||||
return result.docs[0] ?? null;
|
||||
return result.docs[0] ? customerBookingView(result.docs[0]) : null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user