Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/task_1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Эти купюры находятся в массиве private _repository: Array;

const RU = [10, 50, 100, 500, 1000, 5000];
let countCopy = count;

for (let banknote of this._repository) {

Choose a reason for hiding this comment

The 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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 балов

}
}
34 changes: 24 additions & 10 deletions src/task_2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import { Currency } from '../enums';

interface ICard {
export interface ICard {
id: string;
balance: number;
currency: Currency,
Expand All @@ -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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 бала

}
}
44 changes: 32 additions & 12 deletions src/task_3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 бала

}
16 changes: 14 additions & 2 deletions src/task_4/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 бала

}
29 changes: 16 additions & 13 deletions src/task_5/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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);

Choose a reason for hiding this comment

The 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']);

Choose a reason for hiding this comment

The 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);

Choose a reason for hiding this comment

The 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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нет проверки на авторизацию

}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

надо добавить проверку