-
Notifications
You must be signed in to change notification settings - Fork 14
Михалев Кирилл #14
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?
Михалев Кирилл #14
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 |
|---|---|---|
|
|
@@ -31,16 +31,31 @@ export interface IMoneyUnit { | |
| } | ||
|
|
||
| export class MoneyRepository { | ||
| private _repository: any; | ||
| constructor(initialRepository: any) { | ||
| private _repository: Array<IMoneyUnit>; | ||
| constructor(initialRepository: Array<IMoneyUnit>) { | ||
| this._repository = initialRepository; | ||
| } | ||
|
|
||
| public giveOutMoney(count: any, currency: any): any { | ||
| public giveOutMoney(count: number, currency: Currency): boolean { | ||
| const US = [1, 2, 5, 10, 20, 50, 100]; | ||
| const RU = [10, 50, 100, 500, 1000, 5000]; | ||
| let countCopy = count; | ||
|
|
||
| for (let banknote of this._repository) { | ||
|
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. Это не жадный алгоритм |
||
| if (banknote['moneyInfo']['currency'] === currency && countCopy >= banknote['count'] | ||
| && (RU.includes(banknote['count']) || US.includes(banknote['count']))) { | ||
| countCopy -= banknote['count']; | ||
| banknote['count'] = 0; | ||
| } | ||
| } | ||
|
|
||
| if (countCopy === 0) | ||
| return true; | ||
| return false; | ||
|
|
||
| } | ||
|
|
||
| public takeMoney(moneyUnits: any): any { | ||
|
|
||
| public takeMoney(moneyUnits: IMoneyUnit): void { | ||
| this._repository.push(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 балов |
||
| } | ||
| } | ||
| 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,37 @@ 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 { | ||
| 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 { | ||
| for (let card of this._cards) | ||
| if (card.id === cardId) | ||
| return card | ||
| } | ||
|
|
||
| public isCardTiedToUser(cardId: any): any { | ||
|
|
||
| public isCardTiedToUser(cardId: string): boolean { | ||
| for (let user of this._users){ | ||
| for (let card of user.cards) | ||
| if (card.id === cardId) | ||
| return true; | ||
| } | ||
| 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. 3 бала |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,32 +18,52 @@ | |
| */ | ||
|
|
||
| import { UserSettingOptions } from '../enums'; | ||
| import { BankOffice, IBankUser } 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 { | ||
| let lastname = this._user.name; | ||
| this._user.name = newName; | ||
| if (lastname != newName) | ||
| return true; | ||
| return false; | ||
| } | ||
|
|
||
| private changeUserSurname(newSurname: any): any { | ||
|
|
||
| private changeUserSurname(newSurname: string): boolean { | ||
| let lastSurname = this._user.surname; | ||
| this._user.surname = newSurname; | ||
| if (lastSurname != newSurname) | ||
| return true; | ||
| return false; | ||
| } | ||
|
|
||
| private registerForUserNewCard(newCardId: any): any { | ||
|
|
||
| private registerForUserNewCard(newCardId:string): boolean { | ||
| if (!this._bankOffice.isCardTiedToUser(newCardId)) { | ||
| this._user.cards.push(this._bankOffice.getCardById(newCardId)); | ||
| 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); | ||
| } | ||
|
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,27 @@ | |
| */ | ||
|
|
||
| import { Currency } from '../enums'; | ||
| import { MoneyRepository, IMoneyUnit } from '../task_1/index'; | ||
|
|
||
| export class CurrencyConverterModule { | ||
| private _moneyRepository: any; | ||
| private _moneyRepository: MoneyRepository; | ||
|
|
||
| constructor(initialMoneyRepository: any) { | ||
| 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 moneyUnits.count; | ||
|
|
||
| let denomination = parseInt(moneyUnits.moneyInfo.denomination); | ||
|
|
||
| if (fromCurrency === Currency.RUB) | ||
| if (this._moneyRepository.giveOutMoney(moneyUnits.count * denomination / 70, toCurrency)) | ||
| return moneyUnits.count * denomination / 70; | ||
| else | ||
| if (this._moneyRepository.giveOutMoney(moneyUnits.count * denomination, 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. 3 бала |
||
| } | ||
| 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,34 @@ class BankTerminal { | |
| private _userSettingsModule: UserSettingsModule; | ||
| private _currencyConverterModule: CurrencyConverterModule; | ||
| private _authorizedUser: IBankUser; | ||
| private _currentCard: 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): void { | ||
| if (this._bankOffice.authorize(user.id, card.id, cardPin)) { | ||
| this._authorizedUser = user; | ||
| } | ||
| } | ||
|
|
||
| public takeUsersMoney(moneyUnits: any): any { | ||
|
|
||
| public takeUsersMoney(moneyUnits: IMoneyUnit): void { | ||
| this._moneyRepository.takeMoney(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. нет проверки на авторизацию |
||
| } | ||
|
|
||
| public giveOutUsersMoney(count: any): any { | ||
|
|
||
| public giveOutUsersMoney(count: number): void { | ||
| this._moneyRepository.giveOutMoney(count, this._authorizedUser.cards[0]['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): void { | ||
| this._userSettingsModule.changeUserSettings(option, 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. нет проверки на авторизацию |
||
| } | ||
|
|
||
| public convertMoneyUnits(fromCurrency: Currency, toCurrency: Currency, moneyUnits: any): any { | ||
|
|
||
| public convertMoneyUnits(fromCurrency: Currency, toCurrency: Currency, moneyUnits: IMoneyUnit): void { | ||
| 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. нет проверки на авторизацию |
||
| } | ||
| } | ||
|
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. надо добавить проверку |
||
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.
Эти купюры находятся в массиве private _repository: Array;