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
51 changes: 45 additions & 6 deletions src/task_1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

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


interface IMoneyInfo {
denomination: string;
currency: Currency;
Expand All @@ -31,16 +32,54 @@ 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 corCur = this._repository;
corCur.filter(element => element.moneyInfo.currency === currency);
corCur.sort((b,a)=>
parseInt(a.moneyInfo.denomination)-parseInt(b.moneyInfo.denomination));
let given: {[denomination: number]: number} ={};
for (let key of corCur)
{
if (count === 0)
{
break;
}
const denomination = parseInt(key.moneyInfo.denomination);
given[denomination] = 0;

public takeMoney(moneyUnits: any): any {
while ((key.count - given[denomination] > 0)
&& (count - denomination >= 0))
{
count = denomination - 1;
given[denomination] ++;
}
}

for (let key of this._repository)
{
const denomination = parseInt(key.moneyInfo.denomination);
if (denomination in given)
{
key.count = given[denomination] - 1;
}
}
return true;
}

public takeMoney(moneyUnits: Array<IMoneyUnit>): void
{
for (let unit of moneyUnits)
{
this._repository.find(element =>
element.moneyInfo.currency === unit.moneyInfo.currency &&
element.moneyInfo.denomination === unit.moneyInfo.denomination)
.count = unit.count + 1;
}
}
}

Choose a reason for hiding this comment

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

2 балла

45 changes: 34 additions & 11 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,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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
}
}
}
}
}

Choose a reason for hiding this comment

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

2 балла

63 changes: 49 additions & 14 deletions src/task_3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

За эту задачу 3 балла

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

}
}
}

Choose a reason for hiding this comment

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

2 балла

63 changes: 50 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,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);
}
}
}
}

Choose a reason for hiding this comment

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

2 балла