-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(proto): fix proto generation feat: add basic app endpoint functions feat: add zod validation fix(microservices): fix port assignments when running locally
- Loading branch information
Showing
35 changed files
with
817 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { createMock } from '@golevelup/ts-jest'; | ||
|
||
import { OrdersController } from './orders.controller'; | ||
import { OrdersService } from './orders.service'; | ||
|
||
describe('OrdersController', () => { | ||
let controller: OrdersController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [ | ||
{ | ||
provide: OrdersService, | ||
useValue: createMock<OrdersService>(), | ||
}, | ||
], | ||
controllers: [OrdersController], | ||
}).compile(); | ||
|
||
controller = module.get<OrdersController>(OrdersController); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Controller, Get, Param } from '@nestjs/common'; | ||
|
||
import { OrdersService } from './orders.service'; | ||
|
||
@Controller('orders') | ||
export class OrdersController { | ||
constructor(private ordersService: OrdersService) {} | ||
|
||
@Get() | ||
getAllOrders() { | ||
return this.ordersService.getAllOrders(); | ||
} | ||
|
||
@Get(':id') | ||
getOrder(@Param('id') id: string) { | ||
return this.ordersService.getOrder(id); | ||
} | ||
|
||
@Get('user/:userId') | ||
getUserOrders(@Param('userId') userId: string) { | ||
return this.ordersService.getUserOrders(userId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { ClientsModule, Transport } from '@nestjs/microservices'; | ||
|
||
import { Orders } from '@not-a-real-shop/rpc'; | ||
|
||
import { OrdersController } from './orders.controller'; | ||
import { OrdersService } from './orders.service'; | ||
|
||
@Module({ | ||
imports: [ | ||
ClientsModule.register([ | ||
{ | ||
name: Orders.ORDERS_PACKAGE_NAME, | ||
transport: Transport.GRPC, | ||
options: { | ||
url: `localhost:${process.env.ORDERS_PORT}`, | ||
package: Orders.ORDERS_PACKAGE_NAME, | ||
protoPath: './proto/orders.proto', | ||
}, | ||
}, | ||
]), | ||
], | ||
controllers: [OrdersController], | ||
providers: [OrdersService], | ||
}) | ||
export class OrdersModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { ClientGrpc } from '@nestjs/microservices'; | ||
import { createMock } from '@golevelup/ts-jest'; | ||
|
||
import { Orders } from '@not-a-real-shop/rpc'; | ||
|
||
import { OrdersService } from './orders.service'; | ||
|
||
describe('OrdersService', () => { | ||
let service: OrdersService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [ | ||
OrdersService, | ||
{ | ||
provide: Orders.ORDERS_PACKAGE_NAME, | ||
useValue: | ||
createMock<ClientGrpc>().getService<Orders.OrdersServiceClient>( | ||
Orders.ORDERS_SERVICE_NAME | ||
), | ||
}, | ||
], | ||
}).compile(); | ||
|
||
service = module.get<OrdersService>(OrdersService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Inject, Injectable, OnModuleInit } from '@nestjs/common'; | ||
import { ClientGrpc } from '@nestjs/microservices'; | ||
|
||
import { Orders } from '@not-a-real-shop/rpc'; | ||
|
||
@Injectable() | ||
export class OrdersService implements OnModuleInit { | ||
private ordersRpcService: Orders.OrdersServiceClient; | ||
|
||
constructor(@Inject(Orders.ORDERS_PACKAGE_NAME) private client: ClientGrpc) {} | ||
|
||
onModuleInit() { | ||
this.ordersRpcService = this.client.getService<Orders.OrdersServiceClient>( | ||
Orders.ORDERS_SERVICE_NAME | ||
); | ||
} | ||
|
||
getAllOrders() { | ||
return this.ordersRpcService.getAllOrders({}); | ||
} | ||
|
||
getOrder(id: string) { | ||
return this.ordersRpcService.getOrder({ id }); | ||
} | ||
|
||
getUserOrders(userId: string) { | ||
return this.ordersRpcService.getUserOrders({ userId }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { createZodDto } from 'nestjs-zod'; | ||
import { z } from 'nestjs-zod/z'; | ||
|
||
export const ReserveStockSchema = z.object({ | ||
quantity: z.number().int().positive(), | ||
cartItemId: z.string().uuid(), | ||
}); | ||
|
||
export class ReserveStockDto extends createZodDto(ReserveStockSchema) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { createMock } from '@golevelup/ts-jest'; | ||
|
||
import { UsersController } from './users.controller'; | ||
import { UsersService } from './users.service'; | ||
|
||
describe('UsersController', () => { | ||
let controller: UsersController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [ | ||
{ | ||
provide: UsersService, | ||
useValue: createMock<UsersService>(), | ||
}, | ||
], | ||
controllers: [UsersController], | ||
}).compile(); | ||
|
||
controller = module.get<UsersController>(UsersController); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Controller, Get, Param } from '@nestjs/common'; | ||
|
||
import { UsersService } from './users.service'; | ||
|
||
@Controller('users') | ||
export class UsersController { | ||
constructor(private usersService: UsersService) {} | ||
|
||
@Get(':id') | ||
getUser(@Param('id') id: string) { | ||
return this.usersService.getUser(id); | ||
} | ||
} |
Oops, something went wrong.