Argument { } is missing
I'm stuck on a problem related to ORM PRISMA.
My SCHEMA is
model customers {
id String @id @default(uuid())
name String
email String? @unique
phone String? @unique
notes String?
personType PersonType?
document String? @unique
createdById String
updatedById String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
createdBy users @relation("CustomerCreatedBy", fields: [createdById], references: [id])
updatedBy users @relation("CustomerUpdatedBy", fields: [updatedById], references: [id])
sales sales[]
@@index([name])
}
model sales {
id String @id @default(uuid())
saleNumber Int @default(autoincrement())
saleCode String? @unique
customerId String?
subtotalValue Float
discountValue Float
totalValue Float
paymentMethod PaymentMethod
notes String?
createdById String
updatedById String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
customer customers? @relation(fields: [customerId], references: [id])
createdBy users @relation("SaleCreatedBy", fields: [createdById], references: [id])
updatedBy users @relation("SaleUpdatedBy", fields: [updatedById], references: [id])
items saleItems[]
@@index([createdById])
}
But when i make
let sale
await prisma.$transaction(async tx => {
sale = await tx.sales.create({
data: {
customer: saleData.customerId
? { connect: { id: saleData.customerId } }
: undefined,
subtotalValue: saleData.subtotalValue,
discountValue: saleData.discountValue,
totalValue: saleData.totalValue,
paymentMethod: saleData.paymentMethod,
notes: saleData.notes,
createdBy: { connect: { id: userId } },
updatedBy: { connect: { id: userId } },
},
})
I receive the error
PrismaClientValidationError:
Invalid `prisma.sales.create()` invocation:
{
data: {
subtotalValue: 48.36,
discountValue: 0,
totalValue: 48.36,
paymentMethod: "CASH",
notes: "string",
createdBy: {
connect: {
id: "5ad3693d-a786-4f31-8779-1da2cfb39ac9"
}
},
updatedBy: {
connect: {
id: "5ad3693d-a786-4f31-8779-1da2cfb39ac9"
}
},
+ customer: {
+ create: customersCreateWithoutSalesInput | customersUncheckedCreateWithoutSalesInput,
+ connectOrCreate: customersCreateOrConnectWithoutSalesInput,
+ connect: customersWhereUniqueInput
+ }
}
}
Argument `customer` is missing.
Therefore, if I send the customer as undefined, I get an error saying that the argument is missing; if I send the customer as null, I get the error "Argument `customer` must not be null." And so I don't know how I can create a sale without an associated customer.