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
    
  
  
    
  | const env = Deno.env.toObject() | |
| const PORT = env.PORT || 3000; | |
| const HOST = env.HOST || 'localhost'; | 
  
    
      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 { Application } from "./deps.ts"; | |
| import router from "./routes.ts"; | 
  
    
      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 { Application, Router } from "https://deno.land/x/oak/mod.ts"; | |
| export { Router, Application }; | 
  
    
      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 { Context } from "../deps.ts"; | |
| const errorHandler = async (ctx: Context, next: any) => { | |
| try { | |
| await next(); | |
| } catch (err) { | |
| ctx.response.status = 500; | |
| ctx.response.body = { msg: err.message }; | |
| } | |
| }; | 
  
    
      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 { Context } from "../deps.ts"; | |
| const fourZeroFour = async (ctx: Context) => { | |
| ctx.response.status = 404; | |
| ctx.response.body = { msg: "Not Found !!" }; | |
| }; | |
| export default fourZeroFour; | 
  
    
      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 { Router } from "./deps.ts"; | |
| import { | |
| addAdvertisement, | |
| deleteAdvertisement, | |
| getAdvertisement, | |
| getAdvertisements, | |
| publishAdvertisement, | |
| updateAdvertisement, | |
| } from "./controllers/advertisement-controller.ts"; | 
  
    
      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
    
  
  
    
  | export const deleteAdvertisement = ( | |
| { params, response }: { params: { id: string }; response: any }, | |
| ) => { | |
| const advertisement = AdvertisementService.deleteAdvertisement( | |
| params.id, | |
| ); | |
| response.body = { | |
| success: true, | |
| msg: "Advertisement removed", | |
| data: advertisement, | 
  
    
      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
    
  
  
    
  | export const updateAdvertisement = async ( | |
| { params, request, response }: { | |
| params: { id: string }; | |
| request: any; | |
| response: any; | |
| }, | |
| ) => { | |
| const advertisement = AdvertisementService.fetchAdvertisement( | |
| params.id, | |
| ); | 
  
    
      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
    
  
  
    
  | export const addAdvertisement = async ( | |
| { request, response }: { request: any; response: any }, | |
| ) => { | |
| if (!request.body()) { | |
| response.status = 400; | |
| response.body = { | |
| success: false, | |
| msg: "The request must have a body", | |
| }; | |
| return; | 
  
    
      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
    
  
  
    
  | export const getAdvertisement = ( | |
| { params, response }: { params: { id: string }; response: any }, | |
| ) => { | |
| const advertisement = AdvertisementService.fetchAdvertisement( | |
| params.id, | |
| ); | |
| if (advertisement === null) { | |
| response.status = 400; | |
| response.body = { msg: `Advertisement with id: ${params.id} not found` }; | 
NewerOlder