import { z } from "zod"; import { CommentStatusFilter } from "@shared/types"; import { BaseSchema, ProsemirrorSchema } from "@server/routes/api/schema"; const BaseIdSchema = z.object({ /** Comment Id */ id: z.string().uuid(), }); const CommentsSortParamsSchema = z.object({ /** Specifies the attributes by which comments will be sorted in the list */ sort: z .string() .refine((val) => ["createdAt", "updatedAt"].includes(val)) .default("createdAt"), /** Specifies the sort order with respect to sort field */ direction: z .string() .optional() .transform((val) => (val !== "ASC" ? "DESC" : val)), }); export const CommentsCreateSchema = BaseSchema.extend({ body: z.object({ /** Allow creation with a specific ID */ id: z.string().uuid().optional(), /** Create comment for this document */ documentId: z.string(), /** Create comment under this parent */ parentCommentId: z.string().uuid().optional(), /** Create comment with this data */ data: ProsemirrorSchema, }), }); export type CommentsCreateReq = z.infer; export const CommentsUpdateSchema = BaseSchema.extend({ body: BaseIdSchema.extend({ /** Update comment with this data */ data: ProsemirrorSchema, }), }); export type CommentsUpdateReq = z.infer; export const CommentsDeleteSchema = BaseSchema.extend({ body: BaseIdSchema, }); export type CommentsDeleteReq = z.infer; export const CommentsListSchema = BaseSchema.extend({ body: CommentsSortParamsSchema.extend({ /** Id of a document to list comments for */ documentId: z.string().optional(), /** Id of a collection to list comments for */ collectionId: z.string().optional(), /** Id of a parent comment to list comments for */ parentCommentId: z.string().uuid().optional(), /** Comment statuses to include in results */ statusFilter: z.nativeEnum(CommentStatusFilter).array().optional(), }), }); export type CommentsListReq = z.infer; export const CommentsInfoSchema = z.object({ body: BaseIdSchema, }); export type CommentsInfoReq = z.infer; export const CommentsResolveSchema = z.object({ body: BaseIdSchema, }); export type CommentsResolveReq = z.infer; export const CommentsUnresolveSchema = z.object({ body: BaseIdSchema, }); export type CommentsUnresolveReq = z.infer;