refactor: add server-side validation schema for events (#4622)
* refactor: move files to subfolder * refactor: schema for events.list * refactor: update nullable fields in Event model * fix: event actor not nullable * fix: team not nullable
This commit is contained in:
committed by
GitHub
parent
05a4f050bb
commit
dc795604a4
32
server/routes/api/events/schema.ts
Normal file
32
server/routes/api/events/schema.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const EventsListSchema = z.object({
|
||||
/** Id of the user who performed the action */
|
||||
actorId: z.string().uuid().optional(),
|
||||
|
||||
/** Id of the document to filter the events for */
|
||||
documentId: z.string().uuid().optional(),
|
||||
|
||||
/** Id of the collection to filter the events for */
|
||||
collectionId: z.string().uuid().optional(),
|
||||
|
||||
/** Whether to include audit events */
|
||||
auditLog: z.boolean().default(false),
|
||||
|
||||
/** Name of the event to retrieve */
|
||||
name: z.string().optional(),
|
||||
|
||||
/** The attribute to sort the events by */
|
||||
sort: z
|
||||
.string()
|
||||
.refine((val) => ["name", "createdAt"].includes(val))
|
||||
.default("createdAt"),
|
||||
|
||||
/** The direction to sort the events */
|
||||
direction: z
|
||||
.string()
|
||||
.optional()
|
||||
.transform((val) => (val !== "ASC" ? "DESC" : val)),
|
||||
});
|
||||
|
||||
export type EventsListReq = z.infer<typeof EventsListSchema>;
|
||||
Reference in New Issue
Block a user