-
Notifications
You must be signed in to change notification settings - Fork 14
Сулейманов Эмиль #13
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?
Сулейманов Эмиль #13
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,42 @@ export interface IBankUser { | |
| } | ||
|
|
||
| export class BankOffice { | ||
| 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 { | ||
|
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. Этот метод будет работать не корректно |
||
| this._users.forEach(user => { | ||
| if (userId === user.id) | ||
| { | ||
| user.cards.forEach(card => { | ||
| if (card.id === cardId && card.pin === cardPin) | ||
| return true; | ||
| }) | ||
| } | ||
| }); | ||
| return false; | ||
| } | ||
|
|
||
| public getCardById(cardId: any): any { | ||
|
|
||
| public getCardById(cardId: string): ICard { | ||
| this._cards.forEach(card => { | ||
| if (card.id === cardId) | ||
| return card; | ||
|
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. Этот return завершит цикл, но не вернёт значение функции getCardById |
||
| }) | ||
| return null; | ||
| } | ||
|
|
||
| public isCardTiedToUser(cardId: any): any { | ||
|
|
||
| public isCardTiedToUser(cardId: string): boolean { | ||
| this._users.forEach(user => { | ||
| user.cards.forEach(card => { | ||
| if (card.id === cardId) | ||
| return true; | ||
|
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. Этот метод будет работать не корректно |
||
| }) | ||
| }) | ||
| return false; | ||
| } | ||
|
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 балов |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,32 +18,53 @@ | |
| */ | ||
|
|
||
| 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; | ||
|
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 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,24 @@ | |
| */ | ||
|
|
||
| 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: Array<IMoneyUnit>): Array<IMoneyUnit> { | ||
| let sum: number = 0; | ||
| moneyUnits.forEach(unit => { | ||
| sum += unit.count * parseInt(unit.moneyInfo.denomination ) | ||
| }); | ||
| if (sum % 70 === 0 && toCurrency === Currency.USD && fromCurrency === Currency.RUB) | ||
| { | ||
| this._moneyRepository.giveOutMoney(sum, toCurrency); | ||
| } | ||
| return null; | ||
| } | ||
|
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. Нет решения |
||
| } | ||
| 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, card: any, cardPin: 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); | ||
| } | ||
| } | ||
|
|
||
| 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. 3 бала |
||
| } | ||
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 балов