Orcioly Andrade Alves
03/30/2022, 12:52 PMgenerator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id String @id @default(uuid())
name String
email String @unique
password String
isAdmin Boolean @default(false)
created_at DateTime @default(now())
updated_at DateTime @updatedAt
Client Client[]
@@map("users")
}
model Client {
id String @id @default(uuid())
user_id String
name User @relation(fields: [user_id], references: [id])
address String
city String
district String
state String
zipcode String
cnpj String @unique
stateregistered String
telephone String
mobile String
active Boolean
created_at DateTime @default(now())
updated_at DateTime @updatedAt
Order OrderClient[]
@@map("clients")
}
model Product {
id String @id @default(uuid())
followUp String
fabric String?
name String
size String
color String
status String
code_karsten String
price Decimal @default(0.00)
isActive Boolean
created_at DateTime @default(now())
updated_at DateTime @updatedAt
Order OrderClient[]
@@map("products")
}
model OrderClient {
id String @id @default(uuid())
name Client @relation(fields: [client_id], references: [id])
client_id String
product Product @relation(fields: [product_id], references: [id])
product_id String
quantity Int
size String
color String
status String
code_karsten String
price Decimal @default(0.00)
liquid Decimal @default(0.00)
priceTotal Decimal @default(0.00)
created_at DateTime @default(now())
updated_at DateTime @updatedAt
@@map("orders_clients")
}
CreateOrderClientService.ts:
import { AppError } from '../shared/errors/AppError';
import prismaClient from '../prisma';
import { CreateOrderClientDTO } from '../dtos/order_client/CreateOrderClientDto';
class CreateOrderClientService {
async execute({
client_id,
product_id,
quantity,
size,
color,
status,
code_karsten,
price,
liquid,
priceTotal,
}: CreateOrderClientDTO) {
const order = await prismaClient.orderClient.create({
data: {
client_id,
product_id,
quantity,
size,
color,
status,
code_karsten,
price,
liquid,
priceTotal,
},
include: {
name: {
select: {
name: {
select: {
id: true,
name: true,
email: true,
isAdmin: true,
created_at: true,
updated_at: true,
},
},
},
},
product: true,
},
});
return order;
}
}
export { CreateOrderClientService };
Vladi Stevanovic
Vladi Stevanovic
Orcioly Andrade Alves
03/30/2022, 1:55 PMNurul
04/01/2022, 11:17 AMname
field in the Client
model the studio shows the User
information, this behaviour is correct and expected as from the schema file that you have mentioned I could see that the name field has a relation to the User model.Orcioly Andrade Alves
04/01/2022, 12:39 PMNurul
04/01/2022, 1:31 PM