Files
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

54 lines
1.4 KiB
JavaScript

const Feature = require('./featureModel')
const AppError = require('../../globalErrorHandler/AppError')
const categoryService = require('../category/categoryService')
exports.getAllCategoryFeatures = async () => {
const groups = JSON.parse(JSON.stringify(await categoryService.getAllCategories()))
for (let group of groups) {
group.features = await Feature.find({ category: category._id })
}
return groups
}
module.exports.getFeatureByCategory = async (categoryId) => {
return Feature.find({category: categoryId}, null, null)
}
module.exports.getAllFeatures = async (query) => {
return Feature.find(query, null, null)
}
module.exports.createFeatures = async (data) => {
return Feature.create(data, null)
}
module.exports.getFeatures = async (featureId) => {
const group = await Feature.findById(featureId)
if (!group) {
throw new AppError('NoGroupFound', 404, {})
}
return group
}
module.exports.updateFeatures = async (featureId, data) => {
const group = await Feature.findOneAndUpdate({ _id: featureId }, data)
if (!group) {
throw new AppError('NoGroupFound', 404, {})
}
return group
}
module.exports.deleteFeatures = async (featureId) => {
const group = await Feature.findOneAndUpdate({ _id: featureId }, { isActive: false })
if (!group) {
throw new AppError('NoGroupFound', 404, {})
}
return null
}