-
Notifications
You must be signed in to change notification settings - Fork 14
Катюшкина Настя #10
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?
Катюшкина Настя #10
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,46 @@ 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 | ||
|
Contributor
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. Этот метод всегда возвращает false |
||
| { | ||
| for (let user of this._users) | ||
| { | ||
| if (user.id === userId) | ||
| { | ||
| for (let card of user.cards) | ||
| { | ||
| if ((card.id === cardId) && (card.pin === cardPin)) | ||
| { | ||
| return true | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public getCardById(cardId: any): any { | ||
|
|
||
| public getCardById(cardId: string): ICard | ||
| { | ||
| return this._cards[cardId]; | ||
| } | ||
|
|
||
| public isCardTiedToUser(cardId: any): any { | ||
|
|
||
| public isCardTiedToUser(cardId: string): boolean | ||
| { | ||
| for (let UI in this._users) | ||
| { | ||
| for (let UC of this._users[UI]["cards"]) | ||
| { | ||
| if (UC.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. 2 балла |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,32 +18,67 @@ | |
| */ | ||
|
|
||
| import { UserSettingOptions } from '../enums'; | ||
| import { BankOffice, IBankUser } from '../task_2'; | ||
|
|
||
| export class UserSettingsModule { | ||
| private _bankOffice: any; | ||
| private _user: any; | ||
| export class UserSettingsModule | ||
| { | ||
| 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 (this._user) | ||
| { | ||
| this._user.name = newName; | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| private changeUserSurname(newSurname: any): any { | ||
|
|
||
| private changeUserSurname(newSurname: string): boolean | ||
| { | ||
| if (this._user) | ||
| { | ||
| this._user.surname = newSurname; | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| private registerForUserNewCard(newCardId: any): any { | ||
|
|
||
| private registerForUserNewCard(newCardId: string): boolean | ||
| { | ||
| const newCard = this._bankOffice.getCardById(newCardId); | ||
| if (this._user && newCard && !this._bankOffice.isCardTiedToUser(newCardId)) | ||
| { | ||
| this._user.cards.push(newCard); | ||
| return true; | ||
| } | ||
| 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 | ||
| { | ||
| return this.registerForUserNewCard(argsForChangeFunction); | ||
| } | ||
| } | ||
|
Contributor
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,39 @@ | |
| */ | ||
|
|
||
| import { Currency } from '../enums'; | ||
| import { IMoneyUnit, MoneyRepository } from '../task_1'; | ||
|
|
||
| export class CurrencyConverterModule { | ||
| private _moneyRepository: any; | ||
| export class CurrencyConverterModule | ||
| { | ||
| 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): number { | ||
| if (fromCurrency === toCurrency) | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| let denomination = parseInt(moneyUnits.moneyInfo.denomination); | ||
|
|
||
| if (fromCurrency === Currency.RUB) | ||
| { | ||
| if (this._moneyRepository.giveOutMoney(moneyUnits.count * denomination / 70, toCurrency)) | ||
| { | ||
| return moneyUnits.count * denomination / 70; | ||
| } | ||
| } | ||
| if (fromCurrency === Currency.USD) | ||
| { | ||
| if (this._moneyRepository.giveOutMoney(moneyUnits.count * denomination * 70, toCurrency)) | ||
| { | ||
| return moneyUnits.count * denomination * 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 |
|---|---|---|
|
|
@@ -16,8 +16,8 @@ | |
| */ | ||
|
|
||
| import { Currency, UserSettingOptions } from '../enums'; | ||
| import { MoneyRepository } from '../task_1'; | ||
| import { BankOffice, IBankUser } from '../task_2'; | ||
| import { MoneyRepository, IMoneyUnit } from '../task_1'; | ||
| import { BankOffice, IBankUser, ICard } from '../task_2'; | ||
| import { UserSettingsModule } from '../task_3'; | ||
| import { CurrencyConverterModule } from '../task_4'; | ||
|
|
||
|
|
@@ -27,31 +27,68 @@ 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): boolean { | ||
| if (this._bankOffice.authorize(user.id, card.id, cardPin)) | ||
| { | ||
| this._authorizedUser = user; | ||
| this._Card = card; | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public takeUsersMoney(moneyUnits: any): any { | ||
| public takeUsersMoney(moneyUnits: IMoneyUnit[]): boolean | ||
| { | ||
| if (this._authorizedUser != undefined) | ||
| { | ||
| this._moneyRepository.takeMoney(moneyUnits); | ||
|
|
||
| for(let unit of moneyUnits) | ||
| { | ||
| const i = this._Card.currency === unit.moneyInfo.currency ? 1 : | ||
| (this._Card.currency === Currency.RUB ? 70 : (1/70)) | ||
| this._Card.balance += unit.count * parseInt(unit.moneyInfo.denomination) * i; | ||
| } | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public giveOutUsersMoney(count: any): any { | ||
|
|
||
| public giveOutUsersMoney(count: number): boolean | ||
| { | ||
| if (this._authorizedUser != undefined) | ||
| { | ||
| if (this._moneyRepository.giveOutMoney(count, this._Card.currency)) | ||
| { | ||
| this._Card.balance = count -1; | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public changeAuthorizedUserSettings(option: UserSettingOptions, argsForChangeFunction: any): any { | ||
|
|
||
| public changeAuthorizedUserSettings(option: UserSettingOptions, argsForChangeFunction: string) | ||
| { | ||
| if (this._authorizedUser != undefined) | ||
| { | ||
| this._userSettingsModule.changeUserSettings(option, argsForChangeFunction); | ||
| } | ||
| } | ||
|
|
||
| public convertMoneyUnits(fromCurrency: Currency, toCurrency: Currency, moneyUnits: any): any { | ||
|
|
||
| public convertMoneyUnits(fromCurrency: Currency, toCurrency: Currency, moneyUnits: IMoneyUnit) | ||
| { | ||
| if (this._authorizedUser != undefined) | ||
| { | ||
| 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.
2 балла