> For the complete documentation index, see [llms.txt](https://kinesis-school-of-programming.gitbook.io/nestjs-unleashed/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kinesis-school-of-programming.gitbook.io/nestjs-unleashed/parallel-module-prisma/remaining-domain/logic/product.md).

# Product

With the <mark style="color:blue;">`Product`</mark> logic, there are also similarities with the lesson in the **Core module**, such as when copying the contents of the users' **CreateDTO** and **Service**, we should

* In the **CreateDTO**, have the following

```typescript
export class CreateProductDto {
  @Length(2, 50)
  readonly name: string;

  @IsOptional()
  @Length(1, 500)
  readonly description?: string;

  @IsCurrency()
  readonly price: number;

  @ArrayNotEmpty()
  @IsEntity()
  readonly categories: IdDto[];
}
```

* In the **Service**, in <mark style="color:blue;">`findOne()`</mark>, also fetch its <mark style="color:blue;">`categories`</mark>

Now what's **different**: in the methods <mark style="color:blue;">`create()`</mark> and <mark style="color:blue;">`update()`</mark>, we should explicitly state what to do with the <mark style="color:blue;">`categories`</mark>. In our case, we wish that, when a <mark style="color:blue;">`product`</mark> is created, to associate it with existing <mark style="color:blue;">`categories`</mark>. And when it's updated, that it receives a new set of relations. Due to this, in both methods, we shall first extract the <mark style="color:blue;">`categories`</mark> from the DTO, and then...

In <mark style="color:blue;">`create()`</mark>, associate the <mark style="color:blue;">`categories`</mark> through the <mark style="color:blue;">`connect`</mark> option.

```typescript
data: {
  ...createProductDto,
  categories: { connect: categories },
},
```

And in <mark style="color:blue;">`update()`</mark>, replace the associations with the <mark style="color:blue;">`set`</mark> option.

```typescript
categories: { set: categories },
```

<mark style="color:green;">**Commit**</mark> - Implementing product logic
