-
Notifications
You must be signed in to change notification settings - Fork 24
Shershnev Pavel #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Shershnev Pavel #20
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| /* eslint-disable no-mixed-spaces-and-tabs */ | ||
| /** Задача 1 - BankOffice | ||
| * Имеется класс BankOffice. Который должен хранить пользователей и банковские карты. | ||
| * Пользователи банка могу иметь карту, а могут не иметь. | ||
|
|
@@ -32,23 +33,34 @@ export interface IBankUser { | |
| } | ||
|
|
||
| export class BankOffice { | ||
| private _users: any; | ||
| private _cards: any; | ||
| private _users: IBankUser[]; | ||
| private _cards: ICard[]; | ||
|
|
||
| constructor(users: any, cards: any) { | ||
| this._users = users; | ||
| this._cards = cards; | ||
| constructor(users: IBankUser[], cards: ICard[]) { | ||
| this._users = users; | ||
| this._cards = cards; | ||
| } | ||
|
|
||
| public authorize(userId: any, cardId: any, cardPin: any): any { | ||
| public authorize(userId: string, cardId: string, cardPin: string): boolean { | ||
| const user: IBankUser = this._users.find(user => user.id === userId); | ||
| const card: ICard = user.cards.find(card => card.id === cardId); | ||
|
|
||
| return user.cards.indexOf(card) !== -1 && card.pin === cardPin; | ||
| } | ||
|
|
||
| public getCardById(cardId: any): any { | ||
| public getCardById(cardId: string): ICard { | ||
| const notCard: ICard = this._cards.find(card => card.id === cardId); | ||
| if (notCard === undefined) { | ||
| const userCard: IBankUser = this._users.find(user => user.cards.find(card => card.id === cardId)); | ||
|
|
||
| } | ||
| return userCard === undefined ? undefined : userCard.cards.find(card => card.id === cardId); | ||
| } | ||
|
|
||
| public isCardTiedToUser(cardId: any): any { | ||
| return notCard; | ||
| } | ||
|
|
||
| public isCardTiedToUser(cardId: string): boolean { | ||
| return this._users.find(user => user.cards.find( | ||
| card => card.id === cardId)) !== undefined; | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Зачёт. 2 бала |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| /* eslint-disable no-mixed-spaces-and-tabs */ | ||
| /** Задача 4 - CurrencyConverterModule | ||
| * Имеется класс CurrencyConverterModule. Который должен отвечать за | ||
| * конвертацию валют. | ||
|
|
@@ -16,15 +17,23 @@ | |
| */ | ||
|
|
||
| import { Currency } from '../enums'; | ||
| import { IMoneyUnit, MoneyRepository } from '../task_1'; | ||
|
|
||
| export class CurrencyConverterModule { | ||
| private _moneyRepository: any; | ||
| private _moneyRepository: MoneyRepository; | ||
|
|
||
| constructor(initialMoneyRepository: any) { | ||
| this._moneyRepository = initialMoneyRepository; | ||
| constructor(initialMoneyRepository: MoneyRepository) { | ||
| this._moneyRepository = initialMoneyRepository; | ||
| } | ||
|
|
||
| public convertMoneyUnits(fromCurrency: Currency, toCurrency: Currency, moneyUnits: any): any { | ||
|
|
||
| public convertMoneyUnits(fromCurrency: Currency, toCurrency: Currency, moneyUnits: IMoneyUnit): number { | ||
| switch (fromCurrency) { | ||
| case toCurrency: | ||
| return 0; | ||
| case Currency.USD: | ||
| return Number(moneyUnits.moneyInfo.denomination) * moneyUnits.count * 70; | ||
| case Currency.RUB: | ||
| return Number(moneyUnits.moneyInfo.denomination) * moneyUnits.count / 70; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Зачёт. 2 бала |
||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| /* eslint-disable no-mixed-spaces-and-tabs */ | ||
| /** Задача 5 - BankTerminal | ||
| * Имеется класс BankTerminal. Класс представляет банковский терминал. | ||
| * Требуется: | ||
|
|
@@ -16,8 +17,8 @@ | |
| */ | ||
|
|
||
| import { Currency, UserSettingOptions } from '../enums'; | ||
| import { MoneyRepository } from '../task_1'; | ||
| import { BankOffice, IBankUser } from '../task_2'; | ||
| import { IMoneyUnit, MoneyRepository } from '../task_1'; | ||
| import { BankOffice, IBankUser, ICard } from '../task_2'; | ||
| import { UserSettingsModule } from '../task_3'; | ||
| import { CurrencyConverterModule } from '../task_4'; | ||
|
|
||
|
|
@@ -28,30 +29,37 @@ export class BankTerminal { | |
| private _currencyConverterModule: CurrencyConverterModule; | ||
| private _authorizedUser: IBankUser; | ||
|
|
||
| constructor(initBankOffice: any, initMoneyRepository: any) { | ||
| this._moneyRepository = initMoneyRepository; | ||
| this._bankOffice = initBankOffice; | ||
| this._userSettingsModule = new UserSettingsModule(initBankOffice); | ||
| this._currencyConverterModule = new CurrencyConverterModule(initMoneyRepository); | ||
| constructor(initBankOffice: BankOffice, initMoneyRepository: MoneyRepository) { | ||
| this._moneyRepository = initMoneyRepository; | ||
| this._bankOffice = initBankOffice; | ||
| this._userSettingsModule = new UserSettingsModule(initBankOffice); | ||
| this._currencyConverterModule = new CurrencyConverterModule(initMoneyRepository); | ||
| } | ||
|
|
||
| public authorizeUser(user: any, card: any, cardPin: any): any { | ||
| public authorizeUser(user: IBankUser, card: ICard, cardPin: string): boolean { | ||
| if (this._bankOffice.authorize(user.id, card.id, cardPin)) { | ||
| this._userSettingsModule.user = user; | ||
| this._authorizedUser = user; | ||
|
|
||
| } | ||
|
|
||
| public takeUsersMoney(moneyUnits: any): any { | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| public giveOutUsersMoney(count: any): any { | ||
|
|
||
| public takeUsersMoney(moneyUnits: IMoneyUnit[]): boolean { | ||
| return this._moneyRepository.takeMoney(moneyUnits); | ||
| } | ||
|
|
||
| public changeAuthorizedUserSettings(option: UserSettingOptions, argsForChangeFunction: any): any { | ||
| public giveOutUsersMoney(count: number): boolean { | ||
| return this._moneyRepository.giveOutMoney(count, Currency.RUB); | ||
| } | ||
|
|
||
| public convertMoneyUnits(fromCurrency: Currency, toCurrency: Currency, moneyUnits: any): any { | ||
| public changeAuthorizedUserSettings(option: UserSettingOptions, argsForChangeFunction: string): boolean { | ||
| return this._userSettingsModule.changeUserSettings(option, argsForChangeFunction); | ||
| } | ||
|
|
||
| public convertMoneyUnits(fromCurrency: Currency, toCurrency: Currency, moneyUnits: IMoneyUnit): number { | ||
| return this._currencyConverterModule.convertMoneyUnits(fromCurrency, toCurrency, moneyUnits); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Зачёт. 2 бала |
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
лучше всего использовать
find