UNPKG

create-mock-backend

Version:

This is npx starter package for installing your favourite backend template for mockBee.

54 lines (46 loc) 1.04 kB
import { Response } from "miragejs"; /** * All the routes related to Videos are present here. * These are Publicly accessible routes. * */ /** * This handler handles gets all videos in the db. * send GET Request at /api/videos * */ export const getAllVideosHandler = function () { try { return new Response(200, {}, { videos: this.db.videos }); } catch (error) { return new Response( 500, {}, { error, } ); } }; /** * This handler handles uploads a new video to the db. * send POST Request at /api/user/videos/ * */ // TODO: postVideoHandler /** * This handler handles gets all videos in the db. * send GET Request at /api/user/videos/:videoId * */ export const getVideoHandler = function (schema, request) { const videoId = request.params.productId; try { const video = this.db.videos.findBy({ _id: videoId }); return new Response(200, {}, { video }); } catch (error) { return new Response( 500, {}, { error, } ); } };