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(budget tip): add retrieving income and outome for 2 months
- Loading branch information
1 parent
c25bb1c
commit 24d8e35
Showing
4 changed files
with
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"workbench.colorCustomizations": { | ||
"activityBar.background": "#412720", | ||
"titleBar.activeBackground": "#5B372D", | ||
"titleBar.activeForeground": "#FCFAF9" | ||
} | ||
} |
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,45 @@ | ||
import * as md5 from 'md5' | ||
|
||
import { TipModel } from '@shared/models/mind/TipModel' | ||
import { TipAction } from '@shared/enum/TipAction' | ||
|
||
import { Adviser } from '../../infrastructure/adviser/helpers/Adviser' | ||
import { IsAdviser } from '../../infrastructure/adviser/helpers/IsAdviser' | ||
import { Statistician } from '@back/money/application/Statistician' | ||
import { GroupBy } from '@shared/enum/GroupBy' | ||
import { Currency } from '@shared/enum/Currency' | ||
import { addMonths } from 'date-fns' | ||
|
||
@IsAdviser() | ||
export class BudgetAdviser implements Adviser { | ||
public constructor(private readonly statistician: Statistician) {} | ||
|
||
public async giveAdvice(userLogin: string): Promise<TipModel[]> { | ||
const now = new Date() | ||
|
||
const [_, ...result] = await this.statistician.showDateRangeStats( | ||
userLogin, | ||
{ from: new Date(addMonths(new Date(), -2)), to: new Date() }, | ||
GroupBy.Month, | ||
Currency.USD, | ||
) | ||
|
||
return [ | ||
{ | ||
date: now, | ||
action: TipAction.MergeSources, | ||
meta: result, | ||
token: this.createToken([''], TipAction.MergeSources), | ||
}, | ||
] | ||
} | ||
|
||
private createToken(variants: string[], action: TipAction): string { | ||
const payload = { | ||
variants: variants.sort(), | ||
action, | ||
} | ||
|
||
return md5(JSON.stringify(payload)) | ||
} | ||
} |
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