Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
feat(money): add api declarations for transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkamyshev committed Jan 27, 2019
1 parent 899d3c8 commit 7e63148
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 1 deletion.
3 changes: 2 additions & 1 deletion back/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common'

import { MoneyModule } from './money/money.module'
import { UserModule } from './user/user.module'

@Module({
imports: [UserModule],
imports: [UserModule, MoneyModule],
})
export class AppModule implements NestModule {
public configure(consumer: MiddlewareConsumer) {
Expand Down
12 changes: 12 additions & 0 deletions back/src/money/money.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common'

import { TransactionController } from './presentation/http/controller/TransactionController'

@Module({
controllers: [TransactionController],
})
export class MoneyModule implements NestModule {
public configure(consumer: MiddlewareConsumer) {
// pass
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Body, Controller, Post } from '@nestjs/common'
import {
ApiBearerAuth,
ApiCreatedResponse,
ApiOperation,
ApiUseTags,
} from '@nestjs/swagger'

import { IncomeRequest } from '../request/IncomeRequest'
import { OutcomeRequest } from '../request/OutcomeRequest'
import { IncomeResponse } from '../response/IncomeResponse'
import { OutcomeResponse } from '../response/OutcomeResponse'

@Controller('money/transaction')
@ApiUseTags('money')
@ApiBearerAuth()
export class TransactionController {
@Post('income')
@ApiOperation({ title: 'Create new income transaction' })
@ApiCreatedResponse({
description: 'Transaction created',
type: IncomeResponse,
})
public async income(@Body() request: IncomeRequest): Promise<IncomeResponse> {
const { amount, currency, source, date } = request

return {
amount,
currency,
source,
date,
}
}

@Post('outcome')
@ApiOperation({ title: 'Create new outcome transaction' })
@ApiCreatedResponse({
description: 'Transaction created',
type: OutcomeResponse,
})
public async outcome(
@Body() request: OutcomeRequest,
): Promise<OutcomeResponse> {
const { amount, currency, category, date } = request

return {
amount,
currency,
category,
date,
}
}
}
1 change: 1 addition & 0 deletions back/src/money/presentation/http/request/IncomeRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { IncomeResponse as IncomeRequest } from '../response/IncomeResponse'
1 change: 1 addition & 0 deletions back/src/money/presentation/http/request/OutcomeRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { OutcomeResponse as OutcomeRequest } from '../response/OutcomeResponse'
18 changes: 18 additions & 0 deletions back/src/money/presentation/http/response/IncomeResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ApiModelProperty, ApiModelPropertyOptional } from '@nestjs/swagger'

import { Currency } from '@shared/enum/Currency'
import { IncomeModel } from '@shared/models/money/IncomeModel'

export class IncomeResponse implements IncomeModel {
@ApiModelProperty({ example: 1000 })
public readonly amount: number

@ApiModelProperty({ example: Currency.RUB })
public readonly currency: Currency

@ApiModelProperty({ example: 'NASA' })
public readonly source: string

@ApiModelPropertyOptional({ example: '2019-02-10' })
public readonly date?: string
}
18 changes: 18 additions & 0 deletions back/src/money/presentation/http/response/OutcomeResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ApiModelProperty, ApiModelPropertyOptional } from '@nestjs/swagger'

import { Currency } from '@shared/enum/Currency'
import { OutcomeModel } from '@shared/models/money/OutcomeModel'

export class OutcomeResponse implements OutcomeModel {
@ApiModelProperty({ example: 1000 })
public readonly amount: number

@ApiModelProperty({ example: Currency.RUB })
public readonly currency: Currency

@ApiModelProperty({ example: 'Restaurants' })
public readonly category: string

@ApiModelPropertyOptional({ example: '2019-02-10' })
public readonly date?: string
}
3 changes: 3 additions & 0 deletions shared/enum/Currency.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export enum Currency {
RUB,
}
8 changes: 8 additions & 0 deletions shared/models/money/IncomeModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Currency } from '@shared/enum/Currency'

export interface IncomeModel {
readonly amount: number // penny!
readonly currency: Currency
readonly source: string
readonly date?: string
}
8 changes: 8 additions & 0 deletions shared/models/money/OutcomeModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Currency } from '@shared/enum/Currency'

export interface OutcomeModel {
readonly amount: number // penny!
readonly currency: Currency
readonly category: string
readonly date?: string
}

0 comments on commit 7e63148

Please sign in to comment.