Good morning guys.. blz? What do you think of thi...
# orm-help
o
Good morning guys.. blz? What do you think of this procedure? Using select was a way I found to omit the password in the client-side return. In Prisma Studio when I click on the Product within the Model OrderClient it shows the product, but when I click on the field in name Client it shows in the field name the Model User because the Model Client is related to the User. Is correct? Remembering that in Insomnia it shows right. I had a look at the prism connect option, but I managed to solve it this way. What do you think? Apparently it's working as expected, but I'd like opinions! Thank you very much in advance. schema.prisma:
Copy code
generator 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:
Copy code
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 };
v
Hello @Orcioly Andrade Alves , I appreciate all your contributions to our Slack community and your support for Prisma! 💚 To help our Dev Success Engineers answer questions faster, and help other users find similar problems please be sure to post your questions in English. You can write your question in Portuguese in Google Translate and copy the output. Thank you for the collaboration!
(PS - you can edit your current Slack message, once you've translated into English).
o
Ok. Thanks.
🙌 1
n
Hey 👋 In Prisma studio when you click on the
name
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.
o
Good morning, Thank you very much. In the Customer model name field, it only shows User, which is a model that is related to the Customer Model, that is, the customer's name does not appear, only the name of the Model User that is related. When I search for Insomnia or Postman it shows all the data as I need it. Thanks.
n
Can you please share a screenshot of what doesn’t appear in prisma studio and appears in your postman response? And when you say customer model, you mean client model, right? Because I cannot see the customer model in the above schema that you have shared.