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 }