This repository has been archived by the owner on May 11, 2021. It is now read-only.
-
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(money): add history api declaration
- Loading branch information
1 parent
7e63148
commit e1800b0
Showing
7 changed files
with
106 additions
and
1 deletion.
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
35 changes: 35 additions & 0 deletions
35
back/src/money/presentation/http/controller/HistoryController.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,35 @@ | ||
import { Controller, Get, Query } from '@nestjs/common' | ||
import { | ||
ApiBearerAuth, | ||
ApiImplicitQuery, | ||
ApiOkResponse, | ||
ApiOperation, | ||
ApiUseTags, | ||
} from '@nestjs/swagger' | ||
|
||
import { GroupBy } from '@shared/enum/GroupBy' | ||
|
||
import { ParseDatePipe } from '@back/utils/http/ParseDatePipe' | ||
|
||
import { HistoryGroupResponse } from '../response/HistoryGroupResponse' | ||
|
||
@Controller('money/history') | ||
@ApiUseTags('money') | ||
@ApiBearerAuth() | ||
export class HistoryController { | ||
@Get('grouped') | ||
@ApiOperation({ title: 'Fetch grouped history' }) | ||
@ApiOkResponse({ | ||
description: 'Fetching history success', | ||
type: HistoryGroupResponse, | ||
isArray: true, | ||
}) | ||
@ApiImplicitQuery({ name: 'by', required: false }) | ||
public async showGrouped( | ||
@Query('from', ParseDatePipe) from: Date, | ||
@Query('to', ParseDatePipe) to: Date, | ||
@Query('by') by: GroupBy = GroupBy.Month, | ||
): Promise<HistoryGroupResponse[]> { | ||
return [] | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
back/src/money/presentation/http/response/HistoryGroupResponse.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,36 @@ | ||
import { ApiModelProperty } from '@nestjs/swagger' | ||
|
||
import { Currency } from '@shared/enum/Currency' | ||
import { HistoryGroupModel } from '@shared/models/money/HistoryGroupModel' | ||
|
||
import { IncomeResponse } from './IncomeResponse' | ||
import { OutcomeResponse } from './OutcomeResponse' | ||
|
||
const incomesExample: IncomeResponse[] = [ | ||
{ | ||
amount: 1200, | ||
currency: Currency.RUB, | ||
source: 'NASA', | ||
date: '2019-03-22', | ||
}, | ||
] | ||
|
||
const outcomeExample: OutcomeResponse[] = [ | ||
{ | ||
amount: 1200, | ||
currency: Currency.RUB, | ||
category: 'Cafes', | ||
date: '2019-03-22', | ||
}, | ||
] | ||
|
||
export class HistoryGroupResponse implements HistoryGroupModel { | ||
@ApiModelProperty({ example: 'Jan' }) | ||
public readonly title: string | ||
|
||
@ApiModelProperty({ example: incomesExample }) | ||
public readonly incomes: IncomeResponse[] | ||
|
||
@ApiModelProperty({ example: outcomeExample }) | ||
public readonly outcomes: OutcomeResponse[] | ||
} |
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,18 @@ | ||
import { Injectable, PipeTransform } from '@nestjs/common' | ||
|
||
@Injectable() | ||
export class ParseDatePipe implements PipeTransform<string, Date> { | ||
public transform(value: string): Date { | ||
const date = new Date(value) | ||
|
||
if (!this.dateIsValid(date)) { | ||
throw Error() | ||
} | ||
|
||
return date | ||
} | ||
|
||
private dateIsValid(date: Date): boolean { | ||
return !isNaN(date.getTime()) | ||
} | ||
} |
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,5 @@ | ||
export enum GroupBy { | ||
Week = 'week', | ||
Month = 'month', | ||
Year = 'year', | ||
} |
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,8 @@ | ||
import { IncomeModel } from './IncomeModel' | ||
import { OutcomeModel } from './OutcomeModel' | ||
|
||
export interface HistoryGroupModel { | ||
title: string | ||
incomes: IncomeModel[] | ||
outcomes: OutcomeModel[] | ||
} |