-
Notifications
You must be signed in to change notification settings - Fork 14
Михайловский Евгений #12
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?
The head ref may contain hidden characters: "\u041C\u0438\u0445\u0430\u0439\u043B\u043E\u0432\u0441\u043A\u0438\u0439-\u0415\u0432\u0433\u0435\u043D\u0438\u0439"
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 |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ | |
|
|
||
| import { Currency } from '../enums'; | ||
|
|
||
| interface ICard { | ||
| export interface ICard { | ||
| id: string; | ||
| balance: number; | ||
| currency: Currency, | ||
|
|
@@ -32,23 +32,27 @@ export interface IBankUser { | |
| } | ||
|
|
||
| export class BankOffice { | ||
|
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. Файл не валидный. |
||
| private _users: any; | ||
| private _cards: any; | ||
| private _users: Array<IBankUser>; | ||
| private _cards: Array<ICard>; | ||
|
|
||
| constructor(users: any, cards: any) { | ||
| constructor(users: Array<IBankUser>, cards: Array<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 { | ||
| let user = this._users.find(x => x.id === userId); | ||
| if(!user) return false; | ||
| let card = user.cards.find(x=> x.id === cardId); | ||
| if(!card) return false; | ||
| return card.pin === cardPin; | ||
| } | ||
|
|
||
| public getCardById(cardId: any): any { | ||
|
|
||
| public getCardById(cardId: string): ICard | undefined { | ||
| return this._cards.find(x=> x.id === cardId); | ||
| } | ||
|
|
||
| public isCardTiedToUser(cardId: any): any { | ||
|
|
||
| public isCardTiedToUser(cardId: string): boolean { | ||
| return this._users.filter(x=> x.cards.find(y=> y.id === cardId)).length > 0; | ||
| } | ||
|
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 |
|---|---|---|
|
|
@@ -17,33 +17,54 @@ | |
| * пользуясь уже предоставленными интерфейсами (избавиться от всех any типов) | ||
| */ | ||
|
|
||
| import { UserSettingOptions } from '../enums'; | ||
| import { IBankUser, BankOffice } from '../task_2'; | ||
|
|
||
| export class UserSettingsModule { | ||
| private _bankOffice: any; | ||
| private _user: any; | ||
| private _bankOffice: BankOffice; | ||
| private _user: IBankUser; | ||
|
|
||
| public set user(user: any) { | ||
| public set user(user: IBankUser) { | ||
| this._user = user; | ||
| } | ||
|
|
||
| constructor(initialBankOffice: any) { | ||
| constructor(initialBankOffice: BankOffice) { | ||
| this._bankOffice = initialBankOffice; | ||
| } | ||
|
|
||
| private changeUserName(newName: any): any { | ||
|
|
||
| private changeUserName(newName: string): boolean { | ||
| if (newName) { | ||
| this._user.name = newName; | ||
| return true; | ||
| } else{ | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| private changeUserSurname(newSurname: any): any { | ||
|
|
||
| private changeUserSurname(newSurname: string): boolean { | ||
| if (newSurname) { | ||
| this._user.name = newSurname; | ||
| return true; | ||
| } else | ||
| return false; | ||
| } | ||
|
|
||
| private registerForUserNewCard(newCardId: any): any { | ||
|
|
||
| private registerForUserNewCard(newCardId: string): boolean { | ||
| let card = this._bankOffice.getCardById(newCardId); | ||
| if (card && !this._bankOffice.isCardTiedToUser(newCardId)) | ||
| { | ||
| this._user.cards.push(card); | ||
| return true; | ||
| } | ||
| else | ||
| return false; | ||
| } | ||
|
|
||
| public changeUserSettings(option: UserSettingOptions, argsForChangeFunction: any): any { | ||
|
|
||
| public changeUserSettings(option: UserSettingOptions, argsForChangeFunction: string): boolean { | ||
| if (option === UserSettingOptions.name) | ||
| return this.changeUserName(argsForChangeFunction); | ||
| else if (option === UserSettingOptions.surname) | ||
| return this.changeUserSurname(argsForChangeFunction); | ||
| else if (option === UserSettingOptions.newCard) | ||
| return this.registerForUserNewCard(argsForChangeFunction); | ||
| } | ||
| } | ||
|
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. 3 бала |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,15 +16,28 @@ | |
| */ | ||
|
|
||
| import { Currency } from '../enums'; | ||
| import { IMoneyUnit, MoneyRepository } from '../task_1'; | ||
|
|
||
| export class CurrencyConverterModule { | ||
| private _moneyRepository: any; | ||
| private _moneyRepository: MoneyRepository; | ||
|
|
||
| constructor(initialMoneyRepository: any) { | ||
| constructor(initialMoneyRepository: MoneyRepository) { | ||
| this._moneyRepository = initialMoneyRepository; | ||
| } | ||
|
|
||
| public convertMoneyUnits(fromCurrency: Currency, toCurrency: Currency, moneyUnits: any): any { | ||
|
|
||
| public convertMoneyUnits(fromCurrency: Currency, toCurrency: Currency, moneyUnits: IMoneyUnit[]): IMoneyUnit[] { | ||
|
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. Этот метод не может возвращать массив купюр к выдаче. Потому что купюра не может быть дробной. Этот метод должен возвращать сумму, которая передаётся в _moneyRepository |
||
| const coeff = fromCurrency === Currency.RUB ? 70 : 1/70; | ||
| let result: IMoneyUnit[] = []; | ||
| moneyUnits.forEach(moneyUnit => { | ||
| const tmpObj: IMoneyUnit = { | ||
| moneyInfo: { | ||
| denomination: (+moneyUnit.moneyInfo.denomination * coeff).toString(), | ||
| currency: toCurrency, | ||
| }, | ||
| count: moneyUnit.count, | ||
| } | ||
| result.push(tmpObj); | ||
| }) | ||
| return result; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,8 +16,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'; | ||
|
|
||
|
|
@@ -27,31 +27,48 @@ class BankTerminal { | |
| private _userSettingsModule: UserSettingsModule; | ||
| private _currencyConverterModule: CurrencyConverterModule; | ||
| private _authorizedUser: IBankUser; | ||
| private _card: ICard; | ||
|
|
||
| constructor(initBankOffice: any, initMoneyRepository: any) { | ||
| 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): any { | ||
|
|
||
| public authorizeUser(user: IBankUser, card: ICard, cardPin: string) { | ||
| if (this._bankOffice.authorize(user.id, card.id, cardPin)) | ||
| { | ||
| this._authorizedUser = user; | ||
| this._card = card; | ||
| } | ||
| } | ||
|
|
||
| public takeUsersMoney(moneyUnits: any): any { | ||
|
|
||
| public takeUsersMoney(moneyUnits: Array<IMoneyUnit>) { | ||
| if (this._authorizedUser) | ||
| { | ||
| this._moneyRepository.takeMoney(moneyUnits); | ||
| } | ||
| } | ||
|
|
||
| public giveOutUsersMoney(count: any): any { | ||
|
|
||
| public giveOutUsersMoney(count: number) { | ||
| if (this._authorizedUser) | ||
| { | ||
| this._moneyRepository.giveOutMoney(count, this._card.currency); | ||
|
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. Добавь уменьшение денег на авторизованной карте. Изменение баланса карты |
||
| } | ||
| } | ||
|
|
||
| public changeAuthorizedUserSettings(option: UserSettingOptions, argsForChangeFunction: any): any { | ||
|
|
||
| public changeAuthorizedUserSettings(option: UserSettingOptions, argsForChangeFunction: string) { | ||
| if (this._authorizedUser) | ||
| { | ||
| this._userSettingsModule.changeUserSettings(option, argsForChangeFunction); | ||
| } | ||
| } | ||
|
|
||
| public convertMoneyUnits(fromCurrency: Currency, toCurrency: Currency, moneyUnits: any): any { | ||
|
|
||
| public convertMoneyUnits(fromCurrency: Currency, toCurrency: Currency, moneyUnits: Array<IMoneyUnit>) { | ||
| if (this._authorizedUser) | ||
| { | ||
| 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. 0 балов |
||
| } | ||
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.
0 балов
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.
Посмотрите, я исправил решение
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.
Метод теперь работает верно 2 бала