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 { Server } from "../server"; | |
import { User } from "../interfaces"; | |
export class UserExistsMiddleware extends Middleware { | |
public constructor(private server: Server) { | |
super(); | |
} | |
public execute({ email, password }: User): boolean { |
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 { Handler, User } from "../interfaces"; | |
export abstract class Middleware implements Handler { | |
private next: Handler; | |
public setNextMiddleware(next: Handler): Handler { | |
this.next = next; | |
return next; | |
} | |
public abstract execute(user: User): boolean; |
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 interface User { | |
email: string; | |
password: string; | |
} |
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 { User } from "./user.interface"; | |
export interface Handler { | |
setNextMiddleware(handler: Handler): void; | |
execute(user: User): boolean; | |
} |
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 { Handler } from "./handler"; | |
import { HandlerA } from "./handlerA"; | |
import { HandlerB } from "./handlerB"; | |
import { HandlerC } from "./handlerC"; | |
function clientCode(handler: Handler) { | |
const options = ["optionA", "optionB", "optionC"]; | |
for (const option of options) { | |
console.log(`Client: Who does ${option}?`); |
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 { AbstractHandler } from "./abstract-handler"; | |
export class HandlerA extends AbstractHandler { | |
public handle(request: string): string { | |
if (request === "optionA") { | |
return `A: I'll do the operation -> ${request}.`; | |
} | |
return super.handle(request); | |
} | |
} |
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 { Handler } from "./handler"; | |
export abstract class AbstractHandler implements Handler { | |
private nextHandler: Handler; | |
public setNext(handler: Handler): Handler { | |
this.nextHandler = handler; | |
return handler; | |
} |
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 interface Handler { | |
setNext(handler: Handler): Handler; | |
handle(request: string): string; | |
} |
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 { ConcreteAgent } from "./concrete-agent"; | |
import { ConcreteAuctioneerA } from "./concrete-auctioneerA"; | |
import { ConcreteAuctioneerB } from "./concrete-auctioneerB"; | |
import { ConcreteAuctioneerC } from "./concrete-auctioneerC"; | |
import { ConcreteAuctioneerD } from "./concrete-auctioneerD"; | |
import { Product } from "./product.model"; | |
const concreteAgent = new ConcreteAgent(); | |
const auctioneerA = new ConcreteAuctioneerA(); |
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 { Agent } from "./agent.interface"; | |
import { Auctioneer } from "./auctioneer.interface"; | |
import { ConcreteAgent } from "./concrete-agent"; | |
export class ConcreteAuctioneerD implements Auctioneer { | |
name = "ConcreteAuctioneerD"; | |
MAX_LIMIT = 1000; | |
public update(agent: Agent): void { | |
if (!(agent instanceof ConcreteAgent)) { |