Payment
We'll now create the Payment
model, which will be very simple.
model Payment {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
Let's then create a relation between Order
and Payment
. An order
may or may not have a payment
, and a payment
always belongs to an order
. Therefore, we have a one-to-one relation. Lastly, we want that an order
is deleted together with its payment
.
So, in the Order
model we should have
payment Payment?
And in Payment
order Order @relation(fields: [orderId], references: [id], onDelete: Cascade)
orderId Int @unique
Then, let's generate and run its migration
yarn migrate:create create-payment
yarn migrate:run
And now, create the payments resource. Remember to choose no to CRUD entry points.
nest g res domain/payments
Commit - Creating payment model
Last updated