Skip to content

Instantly share code, notes, and snippets.

@mackignacio
Last active August 25, 2020 19:50

Revisions

  1. mackignacio revised this gist Aug 25, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion mayajs-controller.ts
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,6 @@ import { Controller } from "@mayajs/core";
    route: "/sample", // Name of the route
    })
    export class SampleController {
    constructor() {}
    constructor( // Inject services here ) {}
    }

  2. mackignacio revised this gist Aug 25, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion mayajs-controller.ts
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@ import { Get, Patch, Post, Delete, Put } from "@mayajs/common";
    import { Controller } from "@mayajs/core";

    @Controller({
    model: "./sample.model", // Name of the model
    model: "./sample.model", // Name of the model for this route
    route: "/sample", // Name of the route
    })
    export class SampleController {
  3. mackignacio revised this gist Aug 25, 2020. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions mayajs-controller.ts
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,6 @@ import { Controller } from "@mayajs/core";
    route: "/sample", // Name of the route
    })
    export class SampleController {

    constructor() {}
    }
    }

  4. mackignacio revised this gist Aug 25, 2020. 1 changed file with 5 additions and 51 deletions.
    56 changes: 5 additions & 51 deletions mayajs-controller.ts
    Original file line number Diff line number Diff line change
    @@ -1,58 +1,12 @@
    import { Get, Patch, Post, Delete, Put } from "@mayajs/common";
    import { Request, Response, NextFunction } from "express";
    import { SampleServices } from "./sample.service";
    import { Controller } from "@mayajs/core";

    @Controller({
    model: "./sample.model",
    route: "/sample",
    model: "./sample.model", // Name of the model
    route: "/sample", // Name of the route
    })
    export class SampleController {
    // Inject SampleServices
    constructor(private services: SampleServices) {}

    // This is a GET request equal to "/sample"
    @Get({ path: "/", middlewares: [] })
    get(req: Request, res: Response, next: NextFunction): void {
    // Use a function on SampleService
    this.services.getSamples();

    // Do some GET stuff here
    res.send("This is a GET request");
    }

    // This is a GET request equal to "/sample/:id"
    @Get({ path: "/:id", middlewares: [] })
    getId(req: Request, res: Response, next: NextFunction): void {
    // Do some GET stuff here
    res.send("This is a GET with id request");
    }

    // This is a POST request equal to "/sample/:id/:name"
    @Post({ path: "/:id/:name", middlewares: [] })
    post(req: Request, res: Response, next: NextFunction): void {
    // Do some POST stuff here
    res.send("This is a POST request");
    }

    // This is a PATCH request equal to "/sample/:id/custom-path"
    @Patch({ path: "/:id/custom-path", middlewares: [] })
    patch(req: Request, res: Response, next: NextFunction): void {
    // Do some PATCH stuff here
    res.send("This is a PATCH request");
    }

    // This is a PUT request equal to "/sample/:id"
    @Put({ path: "/:id", middlewares: [] })
    put(req: Request, res: Response, next: NextFunction): void {
    // Do some PUT stuff here
    res.send("This is a PUT request");
    }

    // This is a DELETE request equal to "/sample/:id"
    @Delete({ path: "/:id", middlewares: [] })
    delete(req: Request, res: Response, next: NextFunction): void {
    // Do some DELETE stuff here
    res.send("This is a DELETE request");
    }

    constructor() {}

    }
  5. mackignacio renamed this gist Jul 19, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  6. mackignacio created this gist Jul 19, 2020.
    58 changes: 58 additions & 0 deletions mayajs-controller
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    import { Get, Patch, Post, Delete, Put } from "@mayajs/common";
    import { Request, Response, NextFunction } from "express";
    import { SampleServices } from "./sample.service";
    import { Controller } from "@mayajs/core";

    @Controller({
    model: "./sample.model",
    route: "/sample",
    })
    export class SampleController {
    // Inject SampleServices
    constructor(private services: SampleServices) {}

    // This is a GET request equal to "/sample"
    @Get({ path: "/", middlewares: [] })
    get(req: Request, res: Response, next: NextFunction): void {
    // Use a function on SampleService
    this.services.getSamples();

    // Do some GET stuff here
    res.send("This is a GET request");
    }

    // This is a GET request equal to "/sample/:id"
    @Get({ path: "/:id", middlewares: [] })
    getId(req: Request, res: Response, next: NextFunction): void {
    // Do some GET stuff here
    res.send("This is a GET with id request");
    }

    // This is a POST request equal to "/sample/:id/:name"
    @Post({ path: "/:id/:name", middlewares: [] })
    post(req: Request, res: Response, next: NextFunction): void {
    // Do some POST stuff here
    res.send("This is a POST request");
    }

    // This is a PATCH request equal to "/sample/:id/custom-path"
    @Patch({ path: "/:id/custom-path", middlewares: [] })
    patch(req: Request, res: Response, next: NextFunction): void {
    // Do some PATCH stuff here
    res.send("This is a PATCH request");
    }

    // This is a PUT request equal to "/sample/:id"
    @Put({ path: "/:id", middlewares: [] })
    put(req: Request, res: Response, next: NextFunction): void {
    // Do some PUT stuff here
    res.send("This is a PUT request");
    }

    // This is a DELETE request equal to "/sample/:id"
    @Delete({ path: "/:id", middlewares: [] })
    delete(req: Request, res: Response, next: NextFunction): void {
    // Do some DELETE stuff here
    res.send("This is a DELETE request");
    }
    }