This file contains hidden or 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
| """ | |
| A review is any feedback about products | |
| """ | |
| type Review @key (fields: "id") { | |
| id: ID! | |
| "The plain text version of the review" | |
| body: String | |
| "The user who authored the review. @provides directive refers back to " | |
| author: User @provides (fields: "username") |
This file contains hidden or 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
| """ | |
| The Base User from `Account` service | |
| """ | |
| "The key directive is the field we're going to use to identify the user" | |
| type User @key(fields: "id") { | |
| "A globally unique id for the user" | |
| id: ID! | |
| "The user's full name as provided" | |
| name: String |
This file contains hidden or 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
| """ | |
| The Base User from `Account` service | |
| """ | |
| "The key directive is the field we're going to use to identify the user" | |
| type User @key(fields: "id") { | |
| "A globally unique id for the user" | |
| id: ID! | |
| "The user's full name as provided" | |
| name: String |
This file contains hidden or 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
| /* | |
| * By designing the Customer as an Aggregate Root and including a reference all of the | |
| * movies that it rented, we can place the validation logic for renting movies | |
| * directly on the customer entity. | |
| * | |
| * Advantages: More declarative-reading code. The operation is a lot closer to the | |
| * entity itself, which improves the discoverability and understanding what a customer | |
| * can do. | |
| * | |
| * Disadvantages: Additional overhead. Having to pull the ids of rented movie everytime we |
This file contains hidden or 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 CreateUserController extends BaseController { | |
| private userRepo: IUserRepo; | |
| constructor (userRepo: IUserRepo) { | |
| this.userRepo = userRepo; | |
| } | |
| public execute (req: express.Request, res: express.Response): void { | |
| try { | |
| const { username, password, email } = req.body; |
This file contains hidden or 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 CreateUserController extends BaseController { | |
| public execute (req: express.Request, res: express.Response): void { | |
| try { | |
| const { username, password, email } = req.body; | |
| const usernameOrError: Result<Username> = Username.create(username); | |
| const passwordOrError: Result<Password> = Password.create(password); | |
| const emailOrError: Result<Email> = Email.create(email); | |
| const result = Result.combine([ | |
| usernameOrError, passwordOrError, emailOrError |
This file contains hidden or 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 method from the CreateUserController | |
| abstract execute (req: express.Request, res: express.Response): void; |
This file contains hidden or 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 CreateUserController extends BaseController { | |
| public execute (req: express.Request, res: express.Response): void { | |
| try { | |
| // ... Handle request by creating objects | |
| } catch (err) { | |
| return this.fail(res, err.toString()) | |
| } | |
| } | |
| } |
This file contains hidden or 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 * as express from 'express' | |
| export abstract class BaseController { | |
| abstract execute (req: express.Request, res: express.Response): void; | |
| public static jsonResponse (res: express.Response, code: number, message: string) { | |
| return res.status(code).json({ message }) | |
| } | |
| public ok<T> (res: express.Response, dto?: T) { |
This file contains hidden or 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 { CharmanderFactory } from 'pokemon/charmander/factory' | |
| import { BulbasaurFactory } from 'pokemon/bulbasaur/factory' | |
| import { PorygonFactory } from 'pokemon/porygon/factory' | |
| enum PokemonType { | |
| CHARMANDER = 'charmander', | |
| BULBASAUR = 'bulbasaur', | |
| PORYGON = 'porygon' | |
| } |