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
12 changes: 6 additions & 6 deletions src/task_1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ 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 {
return true;
}

public takeMoney(moneyUnits: any): any {

public takeMoney(moneyUnits: Array<IMoneyUnit>) {
this._repository = this._repository.concat(moneyUnits);
}

Choose a reason for hiding this comment

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

Нет реализации
0 балов

}
39 changes: 29 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,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 {

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

Этот метод будет работать не корректно

})
})
return false;
}

Choose a reason for hiding this comment

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

0 балов

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

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

3 бала

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

Choose a reason for hiding this comment

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

Нет решения
0 балов

}
43 changes: 30 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 { IMoneyUnit, MoneyRepository } 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,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);
}
}

Choose a reason for hiding this comment

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

3 бала

}