Files
mbmanager-api/components/category/categoryService.js
T
kavehhn 2d87cc4834 ADD: SignedUrls for documents, mainImage and images
ADD: Bucket and Upload System
ADD: New errors
ADD: Virtuals for categories
ADD: Features system
ADD: File management system
2025-01-04 22:06:43 +03:30

41 lines
1003 B
JavaScript

const Category = require('./categoryModel')
const AppError = require('../../globalErrorHandler/AppError')
module.exports.getAllCategories = async () => {
return Category.find().populate('features')
}
module.exports.createCategory = async (data) => {
return Category.create(data, null)
}
module.exports.getCategory = async (categoryId) => {
const category = await Category.findById(categoryId)
if (!category) {
throw new AppError('NoCategoryFound', 404, {})
}
return category
}
module.exports.updateCategory = async (categoryId, data) => {
const category = await Category.findOneAndUpdate({ _id: categoryId }, data, { new: true })
if (!category) {
throw new AppError('NoCategoryFound', 404, {})
}
return category
}
module.exports.deleteCategory = async (categoryId) => {
const category = await Category.findByIdAndDelete(categoryId)
if (!category) {
throw new AppError('NoCategoryFound', 404, {})
}
return null
}