7fife-backend/models/subcategories.model.js

42 lines
1.0 KiB
JavaScript
Raw Normal View History

2024-03-07 13:01:44 +00:00
const mongoose = require('mongoose');
// Define the schema for the 'subcategories' collection
const subCategoriesSchema = new mongoose.Schema({
CategoriesId: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Category',
required: true
},
categoryName:{
type: String,
},
SubCategoriesName: {
type: String,
required: true
},
image: {
fileName: String,
fileAddress: String,
imageUrl: String
},
status: {
type: String,
enum: ['activate', 'deactivate'],
default: 'activate'
}
}, {
timestamps: true // Add createdAt and updatedAt fields
});
// Create a model based on the schema
const SubCategories = mongoose.model('SubCategories', subCategoriesSchema);
module.exports = SubCategories;
2024-03-11 12:29:54 +00:00
// categorySchema.pre('remove', async function(next) {
// const category = this;
// await SubCategory.deleteMany({ CategoriesId: category._id });
// next();
// });