Fix validation error message to match existing tests

- Split validation into two separate refine calls for clearer error messages
- First validation ensures one of documentId or collectionId is required for non-folders
- Second validation ensures folders cannot have documentId or collectionId
- This maintains backward compatibility with existing test expectations
This commit is contained in:
codegen-sh[bot]
2025-09-14 14:40:31 +00:00
parent b7957a607d
commit 5b6e47e1bc
+21 -4
View File
@@ -32,7 +32,22 @@ export const StarsCreateSchema = BaseSchema.extend({
return !(isEmpty(body.documentId) && isEmpty(body.collectionId));
},
{
message: "Folders cannot have documentId or collectionId. Regular stars require one of documentId or collectionId.",
message: "One of documentId or collectionId is required",
}
)
.refine(
(body) => {
// Additional validation: folders cannot have documentId or collectionId
if (
body.isFolder &&
(!isEmpty(body.documentId) || !isEmpty(body.collectionId))
) {
return false;
}
return true;
},
{
message: "Folders cannot have documentId or collectionId",
}
),
});
@@ -40,9 +55,11 @@ export const StarsCreateSchema = BaseSchema.extend({
export type StarsCreateReq = z.infer<typeof StarsCreateSchema>;
export const StarsListSchema = BaseSchema.extend({
body: z.object({
parentId: z.string().uuid().optional(),
}).optional(),
body: z
.object({
parentId: z.string().uuid().optional(),
})
.optional(),
});
export type StarsListReq = z.infer<typeof StarsListSchema>;