-
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.
feat(orders): add service to list all orders and end point to list all
- Loading branch information
Showing
29 changed files
with
530 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const rootDir = process.env.NODE_ENV === 'production' ? './dist' : './src'; | ||
|
||
module.exports = [ | ||
{ | ||
name: 'default', | ||
type: 'mongodb', | ||
url: process.env.MONGODB_URL, | ||
useNewUrlParser: true, | ||
logging: !!(process.env.NODE_ENV !== 'production'), | ||
useUnifiedTopology: true, | ||
entities: [`${rootDir}/modules/**/infra/typeorm/schemas/*.{js,ts}`] | ||
} | ||
] |
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,6 @@ | ||
interface ICreateOrderDTO { | ||
date: string; | ||
value: number; | ||
} | ||
|
||
export { ICreateOrderDTO }; |
16 changes: 16 additions & 0 deletions
16
src/modules/bling/infra/http/controllers/OrdersController.ts
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,16 @@ | ||
import { Response, Request } from 'express'; | ||
import { container } from 'tsyringe'; | ||
|
||
import { ListOrdersService } from '~modules/bling/services/ListOrdersService'; | ||
|
||
class OrdersController { | ||
public async index(request: Request, response: Response): Promise<Response> { | ||
const listOrders = container.resolve(ListOrdersService); | ||
|
||
const orders = await listOrders.execute(); | ||
|
||
return response.json(orders); | ||
} | ||
} | ||
|
||
export { OrdersController }; |
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,11 @@ | ||
import { Router } from 'express'; | ||
|
||
import { OrdersController } from '../controllers/OrdersController'; | ||
|
||
const orderRoutes = Router(); | ||
|
||
const ordersController = new OrdersController(); | ||
|
||
orderRoutes.get('/', ordersController.index); | ||
|
||
export { orderRoutes }; |
32 changes: 32 additions & 0 deletions
32
src/modules/bling/infra/typeorm/repositories/OrdersRepository.ts
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 { getMongoRepository, MongoRepository, ObjectLiteral } from 'typeorm'; | ||
|
||
import { ICreateOrderDTO } from '~modules/bling/dtos/ICreateOrderDTO'; | ||
import { IOrdersRepository } from '~modules/bling/repositories/IOrdersRepository'; | ||
|
||
import { Order } from '../schemas/Order'; | ||
|
||
class OrdersRepository implements IOrdersRepository { | ||
private ormRepository: MongoRepository<Order>; | ||
|
||
constructor() { | ||
this.ormRepository = getMongoRepository(Order, 'default'); | ||
} | ||
|
||
public async create({ date, value }: ICreateOrderDTO): Promise<void> { | ||
const update: ObjectLiteral = { | ||
$set: { value: { $sum: ['$value', value] } }, | ||
}; | ||
|
||
await this.ormRepository.updateOne({ date }, [update], { | ||
upsert: true, | ||
}); | ||
} | ||
|
||
public async find(): Promise<Order[]> { | ||
const orders = await this.ormRepository.find(); | ||
|
||
return orders; | ||
} | ||
} | ||
|
||
export { OrdersRepository }; |
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,14 @@ | ||
import { Entity, Column } from 'typeorm'; | ||
|
||
import { BaseSchema } from '~shared/infra/typeorm/schemas/BaseSchema'; | ||
|
||
@Entity('orders') | ||
class Order extends BaseSchema { | ||
@Column() | ||
date: string; | ||
|
||
@Column() | ||
value: number; | ||
} | ||
|
||
export { Order }; |
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
File renamed without changes.
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 { container } from 'tsyringe'; | ||
|
||
import { OrdersRepository } from '../infra/typeorm/repositories/OrdersRepository'; | ||
import { IOrdersRepository } from '../repositories/IOrdersRepository'; | ||
|
||
container.registerSingleton<IOrdersRepository>( | ||
'OrdersRepository', | ||
OrdersRepository, | ||
); |
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 { ICreateOrderDTO } from '../dtos/ICreateOrderDTO'; | ||
import { Order } from '../infra/typeorm/schemas/Order'; | ||
|
||
interface IOrdersRepository { | ||
create(data: ICreateOrderDTO): Promise<void>; | ||
find(): Promise<Order[]>; | ||
} | ||
|
||
export { IOrdersRepository }; |
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,20 @@ | ||
import { inject, injectable } from 'tsyringe'; | ||
|
||
import { Order } from '../infra/typeorm/schemas/Order'; | ||
import { IOrdersRepository } from '../repositories/IOrdersRepository'; | ||
|
||
@injectable() | ||
class ListOrdersService { | ||
constructor( | ||
@inject('OrdersRepository') | ||
private readonly ordersRepository: IOrdersRepository, | ||
) {} | ||
|
||
public async execute(): Promise<Order[]> { | ||
const orders = await this.ordersRepository.find(); | ||
|
||
return orders; | ||
} | ||
} | ||
|
||
export { ListOrdersService }; |
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 |
---|---|---|
@@ -1,13 +1,16 @@ | ||
export interface IDealData { | ||
interface IDealData { | ||
id: string; | ||
won_time: string; | ||
title: string; | ||
value: number; | ||
person_id: { | ||
name: string; | ||
}; | ||
} | ||
|
||
export interface IGetDealsResponseDTO { | ||
interface IGetDealsResponseDTO { | ||
success: boolean; | ||
data: IDealData[]; | ||
} | ||
|
||
export { IDealData, IGetDealsResponseDTO }; |
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 |
---|---|---|
@@ -1 +1 @@ | ||
import '~modules/pipedrive/jobs'; | ||
import '~modules/bling/jobs'; |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export interface IHeaders { | ||
interface IHeaders { | ||
headers?: Record<string, unknown>; | ||
} | ||
|
||
export { IHeaders }; |
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { IHeaders } from './IHeaders'; | ||
|
||
export interface IHttpSetup extends IHeaders { | ||
interface IHttpSetup extends IHeaders { | ||
baseURL: string; | ||
params?: any; | ||
} | ||
|
||
export { IHttpSetup }; |
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
import './HttpProvider'; | ||
|
||
import '~modules/bling/providers'; |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import { Router } from 'express'; | ||
|
||
import { orderRoutes } from '~modules/bling/infra/http/routes/orders.routes'; | ||
import { dealsRouter } from '~modules/pipedrive/infra/http/routes/deals.routes'; | ||
|
||
const router = Router(); | ||
|
||
router.use('/deals', dealsRouter); | ||
router.use('/orders', orderRoutes); | ||
|
||
export { router }; |
Oops, something went wrong.