Skip to content

Commit 8dc1ebd

Browse files
author
Akshit Batra
committed
fix product patch api plus add Rest Client API file to test
1 parent 763727f commit 8dc1ebd

File tree

8 files changed

+97
-17
lines changed

8 files changed

+97
-17
lines changed

Apis.rest

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
@host = http://localhost:3000
3+
@productId = 2
4+
5+
### Testing API
6+
GET {{host}}/
7+
8+
9+
### Products APIs
10+
11+
### List all products
12+
GET {{host}}/product
13+
14+
### Create new product
15+
16+
POST {{host}}/product
17+
Content-Type: application/json
18+
19+
{
20+
"name": "Iphone 16 pro",
21+
"description": "Apple Iphone 16 pro, 128GB, Silver Grey color",
22+
"price": 90000,
23+
"stock": 2,
24+
"categoryId": 2,
25+
"imageUrl": ""
26+
}
27+
28+
### Get Product using Id
29+
30+
GET {{host}}/product/{{productId}}
31+
32+
### Patch API
33+
34+
PATCH {{host}}/product/{{productId}}
35+
Content-Type: application/json
36+
37+
{
38+
"name": "IPhone 16 pro Max",
39+
"price": 120000
40+
}
41+

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@
2020
"test:e2e": "jest --config ./test/jest-e2e.json",
2121
"prepare": "husky",
2222
"test:unit": "jest --config jest.config.js --coverage",
23-
"test:integration": "jest --config jest.integration.config.js --passWithNoTests"
23+
"test:integration": "jest --config jest.integration.config.js --passWithNoTests",
24+
"prisma": "prisma",
25+
"migrate": "prisma migrate deploy --schema prisma/schema.prisma",
26+
"prisma:generate": "npx prisma generate",
27+
"prisma:studio": "prisma studio --schema prisma/schema.prisma",
28+
"prisma:db_pull": "npx prisma db pull",
29+
"prisma:migrate:dev": "npx prisma migrate dev"
2430
},
2531
"dependencies": {
2632
"@nestjs/common": "^11.0.1",

src/cart/cart.controller.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
1+
import {
2+
Controller,
3+
Get,
4+
Post,
5+
Body,
6+
Patch,
7+
Param,
8+
Delete,
9+
} from '@nestjs/common';
210
import { CartService } from './cart.service';
311
import { CreateCartDto } from './dto/create-cart.dto';
412
import { UpdateCartDto } from './dto/update-cart.dto';

src/order/order.controller.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
1+
import {
2+
Controller,
3+
Get,
4+
Post,
5+
Body,
6+
Patch,
7+
Param,
8+
Delete,
9+
} from '@nestjs/common';
210
import { OrderService } from './order.service';
311
import { CreateOrderDto } from './dto/create-order.dto';
412
import { UpdateOrderDto } from './dto/update-order.dto';

src/payment/payment.controller.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
1+
import {
2+
Controller,
3+
Get,
4+
Post,
5+
Body,
6+
Patch,
7+
Param,
8+
Delete,
9+
} from '@nestjs/common';
210
import { PaymentService } from './payment.service';
311
import { CreatePaymentDto } from './dto/create-payment.dto';
412
import { UpdatePaymentDto } from './dto/update-payment.dto';

src/product/dto/update-product.dto.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1+
import { Optional } from '@nestjs/common';
12
import { ApiProperty } from '@nestjs/swagger';
23

34
export class UpdateProductDto {
45
@ApiProperty()
6+
@Optional()
57
name: string;
68
@ApiProperty()
9+
@Optional()
710
description: string;
811
@ApiProperty()
12+
@Optional()
913
price: number;
1014
@ApiProperty()
15+
@Optional()
1116
stock: number;
1217
@ApiProperty()
18+
@Optional()
1319
categoryId: number;
20+
@Optional()
1421
@ApiProperty()
1522
imageUrl: string;
1623
}

src/repositories/product.repository.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,13 @@ export class ProductRepository {
3030
}
3131

3232
async update(id: number, updateProductDto: UpdateProductDto) {
33-
return prisma.product.upsert({
33+
return prisma.product.update({
3434
where: { id },
35-
update: {
36-
name: updateProductDto.name,
37-
price: updateProductDto.price,
38-
description: updateProductDto.description,
39-
image: updateProductDto.imageUrl,
40-
},
41-
create: {
42-
name: updateProductDto.name,
43-
price: updateProductDto.price,
44-
description: updateProductDto.description,
45-
image: updateProductDto.imageUrl,
35+
data: {
36+
name: updateProductDto?.name,
37+
price: updateProductDto?.price,
38+
description: updateProductDto?.description,
39+
image: updateProductDto?.imageUrl,
4640
},
4741
});
4842
}

src/user/user.controller.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
1+
import {
2+
Controller,
3+
Get,
4+
Post,
5+
Body,
6+
Patch,
7+
Param,
8+
Delete,
9+
} from '@nestjs/common';
210
import { UserService } from './user.service';
311
import { CreateUserDto } from './dto/create-user.dto';
412
import { UpdateUserDto } from './dto/update-user.dto';

0 commit comments

Comments
 (0)