Next.js Discord

Discord Forum

Help Needed: Resolving Nested Object CRUD Operations with Prisma and Supabase - Date Type Errors on

Unanswered
jogo posted this in #help-forum
Open in Discord
Avatar
Fully describe what you're trying to accomplish
- I'm trying to have CRUD operations with Prisma and it's been a week not solving the nested objects that comes from supabase. But it has some progress but I really need some help now.
- The process that I make is create:
// lib/schemas/product.ts
// Update schema for the product including variant color and size IDs
export const updateProductSchema = productSchema.pick({
    id: true, // Include the product 'id' for updating
}).extend({
    created_at: z.date().optional().nullable(),
    updated_at: z.date().optional().nullable(),
    name: z.string().nonempty("Name is required").optional(),
    description: z.string().nullable(),
    price: z.number().positive('Price must be positive').min(1, 'Price must at least 2').optional(),
    code: z.string().nonempty('Code is required').optional(),
    category_id: z.string().uuid('Invalid UUID').optional(),
    ProductVariantColor: z.array(updateProductVariantColor).optional(),
});

// lib/types.ts
import { z } from "zod";
import { createProductSchema, productSchema, updateProductSchema } from "./schemas/product";
import { categorySchema } from "./schemas/category";

export type TProduct = z.infer<typeof productSchema>;
export type TCreateProduct = z.infer<typeof createProductSchema>;
export type TUpdateProductSchema = z.infer<typeof updateProductSchema>;

export type TProductCategory = z.infer<typeof categorySchema>;

Review the image 2 of this post to see /api/admin/inventory/[productId]/route.ts

// errors of this upsert from prisma
[PRODUCTS_PUT]: [
  {
    "code": "invalid_type",
    "expected": "date",
    "received": "string",
    "path": [
      "created_at"
    ],
    "message": "Expected date, received string"
  },
{
// more error like this
}
Image
Image

0 Replies