feat: v2 GET bookings updated at filters and sort (#19133)
* fix: make Booking.updatedAt update automatically * feat: return updatedAt by bookings endpoints * feat: GET bookings beforeUpdatedAt, afterUpdatedAt, sortUpdated params * docs: api * chore: bump platform-libraries * refactor: sortUpdated -> sortUpdatedAt query param * chore: delete wrong migration
This commit is contained in:
1 parent
c211f181fc
commit
08bcc77e2c
14 files changed
+6261
-95
No files matched your search
@@ -8,6 +8,7 @@ type SortOptions = {
|
||||
sortStart?: "asc" | "desc";
|
||||
sortEnd?: "asc" | "desc";
|
||||
sortCreated?: "asc" | "desc";
|
||||
sortUpdated?: "asc" | "desc";
|
||||
};
|
||||
type GetOptions = {
|
||||
ctx: {
|
||||
@@ -127,6 +128,9 @@ function getOrderBy(
|
||||
if (sort?.sortCreated) {
|
||||
return { createdAt: sort.sortCreated };
|
||||
}
|
||||
if (sort?.sortUpdated) {
|
||||
return { updatedAt: sort.sortUpdated };
|
||||
}
|
||||
|
||||
return { startTime: "asc" };
|
||||
}
|
||||
|
||||
@@ -152,6 +152,26 @@ export class GetBookingsInput_2024_08_13 {
|
||||
})
|
||||
beforeEnd?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsISO8601({ strict: true }, { message: "fromDate must be a valid ISO 8601 date." })
|
||||
@ApiProperty({
|
||||
type: String,
|
||||
required: false,
|
||||
description: "Filter bookings that have been updated after this date string.",
|
||||
example: "?afterUpdatedAt=2025-03-07T10:00:00.000Z",
|
||||
})
|
||||
afterUpdatedAt?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsISO8601({ strict: true }, { message: "toDate must be a valid ISO 8601 date." })
|
||||
@ApiProperty({
|
||||
type: String,
|
||||
required: false,
|
||||
description: "Filter bookings that have been updated before this date string.",
|
||||
example: "?beforeUpdatedAt=2025-03-14T11:00:00.000Z",
|
||||
})
|
||||
beforeUpdatedAt?: string;
|
||||
|
||||
// note(Lauris): sort
|
||||
@IsOptional()
|
||||
@IsEnum(SortOrder, {
|
||||
@@ -190,6 +210,19 @@ export class GetBookingsInput_2024_08_13 {
|
||||
})
|
||||
sortCreated?: SortOrderType;
|
||||
|
||||
@IsOptional()
|
||||
@IsEnum(SortOrder, {
|
||||
message: 'SortCreated must be either "asc" or "desc".',
|
||||
})
|
||||
@ApiProperty({
|
||||
required: false,
|
||||
description:
|
||||
"Sort results by their updated time (for example when booking status changes) in ascending or descending order.",
|
||||
example: "?sortUpdated=asc OR ?sortUpdated=desc",
|
||||
enum: SortOrder,
|
||||
})
|
||||
sortUpdatedAt?: SortOrderType;
|
||||
|
||||
// note(Lauris): pagination
|
||||
@ApiProperty({ required: false, description: "The number of items to return", example: 10 })
|
||||
@Transform(({ value }: { value: string }) => value && parseInt(value))
|
||||
|
||||
@@ -236,6 +236,11 @@ class BaseBookingOutput_2024_08_13 {
|
||||
@Expose()
|
||||
createdAt!: string;
|
||||
|
||||
@ApiProperty({ type: String, example: "2024-08-13T15:30:00Z" })
|
||||
@IsDateString()
|
||||
@Expose()
|
||||
updatedAt!: string | null;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
type: Object,
|
||||
example: { key: "value" },
|
||||
|
||||
+1
-1
@@ -128,7 +128,7 @@ export class UpdateEventTypeInput_2024_06_14 {
|
||||
@ArrayUnique()
|
||||
@IsInt({ each: true })
|
||||
@Min(1, { each: true })
|
||||
@DocsProperty({
|
||||
@DocsPropertyOptional({
|
||||
example: [15, 30, 60],
|
||||
description:
|
||||
"If you want that user can choose between different lengths of the event you can specify them here. Must include the provided `lengthInMinutes`.",
|
||||
|
||||
@@ -643,7 +643,7 @@ model Booking {
|
||||
attendees Attendee[]
|
||||
location String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime?
|
||||
updatedAt DateTime? @updatedAt
|
||||
status BookingStatus @default(ACCEPTED)
|
||||
paid Boolean @default(false)
|
||||
payment Payment[]
|
||||
|
||||
@@ -201,6 +201,22 @@ export async function getBookings({
|
||||
};
|
||||
}
|
||||
|
||||
if (filters?.afterUpdatedDate) {
|
||||
bookingWhereInputFilters.afterUpdatedDate = {
|
||||
updatedAt: {
|
||||
gte: dayjs.utc(filters.afterUpdatedDate).toDate(),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
if (filters?.beforeUpdatedDate) {
|
||||
bookingWhereInputFilters.beforeUpdatedDate = {
|
||||
updatedAt: {
|
||||
lte: dayjs.utc(filters.beforeUpdatedDate).toDate(),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const filtersCombined: Prisma.BookingWhereInput[] = !filters
|
||||
? []
|
||||
: Object.keys(filters)
|
||||
|
||||
@@ -10,6 +10,8 @@ export const ZGetInputSchema = z.object({
|
||||
attendeeName: z.string().optional(),
|
||||
afterStartDate: z.string().optional(),
|
||||
beforeEndDate: z.string().optional(),
|
||||
afterUpdatedDate: z.string().optional(),
|
||||
beforeUpdatedDate: z.string().optional(),
|
||||
}),
|
||||
limit: z.number().min(1).max(100).nullish(),
|
||||
cursor: z.number().nullish(), // <-- "cursor" needs to exist when using useInfiniteQuery, but can be any type
|
||||
|
||||
Reference in new issue
Block a user