Skip to content

Commit f3c2170

Browse files
committed
50. Update a cart
1 parent bcac7ed commit f3c2170

4 files changed

Lines changed: 31 additions & 5 deletions

File tree

17-nest-course/02-car-dealership/src/cars/cars.controller.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Body, Controller, Delete, Get, Param, ParseIntPipe, Patch, Post, ParseUUIDPipe, UsePipes, ValidationPipe } from '@nestjs/common';
22
import { CarsService } from './cars.service';
3-
import { CreateCarDto } from './dto/create-car.dto';
3+
import { CreateCarDto, UpdateCarDto } from './dto';
44

55
@Controller('cars')
66
// @UsePipes( ValidationPipe )
@@ -28,9 +28,10 @@ export class CarsController {
2828

2929
@Patch(':id')
3030
updateCar(
31-
@Param('id', ParseIntPipe ) id: number,
32-
@Body() body: any ) {
33-
return body;
31+
@Param('id', ParseUUIDPipe ) id: string,
32+
@Body() updateCarDto: UpdateCarDto )
33+
{
34+
return updateCarDto;
3435
}
3536

3637
@Delete(':id')

17-nest-course/02-car-dealership/src/cars/cars.service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Injectable, NotFoundException } from '@nestjs/common';
22
import { v4 as uuid } from 'uuid';
33

4+
import { CreateCarDto, UpdateCarDto } from './dto';
45
import { Car } from './interfaces/car.interface';
5-
import { CreateCarDto } from './dto/create-car.dto';
66

77
@Injectable()
88
export class CarsService {
@@ -49,4 +49,8 @@ export class CarsService {
4949
return car;
5050
}
5151

52+
update( id: string, updateCarDto: UpdateCarDto ) {
53+
54+
}
55+
5256
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { UpdateCarDto } from './update-car.dto';
2+
export { CreateCarDto } from './create-car.dto';
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { IsString, IsUUID, IsOptional } from "class-validator";
2+
3+
4+
export class UpdateCarDto {
5+
6+
@IsString()
7+
@IsUUID()
8+
@IsOptional()
9+
readonly id?: string;
10+
11+
@IsString()
12+
@IsOptional()
13+
readonly brand?: string;
14+
15+
@IsString()
16+
@IsOptional()
17+
readonly model?: string;
18+
19+
}

0 commit comments

Comments
 (0)