This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Powerful { | |
calculateFightPower(): number; | |
} | |
abstract class Character { | |
protected _power: number; | |
protected _name: string; | |
constructor(name:string, power: number = 0 ){ | |
this._name = name; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class Character { | |
protected _power: number; | |
private _name: string; | |
constructor(name:string, power: number = 0 ){ | |
this._name = name; | |
this._power = power; | |
} | |
calculateFightPower(): number { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Character { | |
private _power: number; | |
private _name: string; | |
private _type: string; // Heroe, Villain or Human | |
constructor(name:string, power: number = 0, type: string ){ | |
this._name = name; | |
this._power = power; | |
this._type = type; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Character { | |
_name!: string; | |
constructor(name: string){ | |
this._name = name; | |
} | |
get name(): string { | |
return this._name; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Character { | |
_name!: string; | |
constructor(name: string){ | |
this._name = name; | |
} | |
get name(): string { | |
return this._name; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const USERS = { | |
ADMIN: { | |
email: "admin@example.com", | |
password: "admin", | |
}, | |
USER: { | |
email: "user@example.com", | |
password: "user", | |
}, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
Middleware, | |
RoleMiddleware, | |
ThrottlingMiddleware, | |
UserExistsMiddleware, | |
} from "./middlewares"; | |
import { REQUEST_PER_MINUTE, USERS } from "./app.constants"; | |
import { Server } from "./server"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Middleware } from "./middlewares"; | |
import { User } from "./interfaces"; | |
export class Server { | |
private users: Map<string, User> = new Map<string, User>(); | |
private middleware: Middleware; | |
public setMiddleware(middleware: Middleware): void { | |
this.middleware = middleware; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class RoleMiddleware extends Middleware { | |
public execute({ email, password }: User): boolean { | |
if (email === USERS.ADMIN.email) { | |
console.log("Hello, admin!"); | |
return true; | |
} | |
console.log("Hello, user!"); | |
return this.checkNext({ email, password }); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Middleware } from "./middleware"; | |
import { User } from "../interfaces"; | |
import { WAIT_TIME } from "../app.constants"; | |
export class ThrottlingMiddleware extends Middleware { | |
private request: number = 0; | |
private currentTime: number = new Date().getTime(); | |
private requestPerMinute: number; | |
constructor(requestPerMinute: number) { |
NewerOlder