UNPKG

ecommerce-express-utils

Version:

A collection of handy express utilities for ecommerce

43 lines (34 loc) 1.59 kB
import asyncHandler from 'express-async-handler'; import { getSingleDocument, createDocument, updateDocument, archiveDocument, getDocumentsWithQuery } from 'express-ninja-utils/services/index.js' const getAllProductCollections = ({ model }) => asyncHandler(async (req, res) => { const productCollections = await model.find().populate(['product', 'colectionId']); res.status(200).json(productCollections); }); const getAllProductCollectionsByCollection = ({ model }) => asyncHandler(async (req, res) => { const productCollections = await model.find({colectionId : req.params.colectionId}).populate(['product', 'colectionId']); res.status(200).json(productCollections); }); const getSingleProductCollection = ({ model }) => asyncHandler(async (req, res) => { await getSingleDocument({ model, req, res }); }); const setProductCollection = ({ model }) => asyncHandler(async (req, res) => { await createDocument({ model, req, res }); }); const updateProductCollection = ({ model }) => asyncHandler(async (req, res) => { await updateDocument({ model, req, res }); }); const archiveProductCollection = ({ model }) => asyncHandler(async (req, res) => { await archiveDocument({ model, req, res }); }); const getProductCollectionsWithQuery = ({ model }) => asyncHandler(async (req, res) => { await getDocumentsWithQuery({ model, req, res }); }); export { getAllProductCollections, setProductCollection, updateProductCollection, getSingleProductCollection, archiveProductCollection, getProductCollectionsWithQuery, getAllProductCollectionsByCollection };