create-mock-backend
Version:
This is npx starter package for installing your favourite backend template for mockBee.
37 lines (31 loc) • 821 B
JavaScript
import { Response } from "miragejs";
/**
* All the routes related to Product are present here.
* These are Publicly accessible routes.
* */
/**
* This handler handles gets all products in the db.
* send GET Request at /api/products
* */
export const getAllProductsHandler = function () {
return new Response(200, {}, { products: this.db.products });
};
/**
* This handler handles gets all products in the db.
* send GET Request at /api/user/products/:productId
* */
export const getProductHandler = function (schema, request) {
const productId = request.params.productId;
try {
const product = this.db.products.findBy({ _id: productId });
return new Response(200, {}, { product });
} catch (error) {
return new Response(
500,
{},
{
error,
}
);
}
};