create logs page

This commit is contained in:
mahyargdz
2024-11-18 18:56:14 +03:30
parent 7583fe1cb9
commit f75f890fa5
8 changed files with 688 additions and 371 deletions
+50 -48
View File
@@ -1,77 +1,79 @@
const mongoose = require('mongoose');
const mongoose = require("mongoose");
function autoPopulateSubs(next) {
this.populate({
path: 'childs',
select: 'title childs navIndex url modelType treeCat parent defaultPageType',
options:{
sort : 'navIndex'
}
path: "childs",
select:
"title childs navIndex url modelType treeCat parent defaultPageType",
options: {
sort: "navIndex",
},
// sort: {navIndex: -1},
});
next();
}
function file(file) {
return '/uploads/files/terms/' + file
return "/uploads/files/terms/" + file;
}
function image(img) {
if (img) return '/uploads/images/category/' + img
else return '/img/no-cover.jpg'
if (img) return "/uploads/images/category/" + img;
else return "/img/no-cover.jpg";
}
const CategoryTermsFile = mongoose.Schema({
file: {type: String, get: file},
title: String
})
file: { type: String, get: file },
title: String,
});
const CategorySchema = mongoose.Schema({
title: String,
parent: {type: mongoose.Schema.Types.ObjectId, ref: 'Category', default: null},
childs: [{type: mongoose.Schema.Types.ObjectId, ref: 'Category'}],
treeCat: [{type: mongoose.Schema.Types.ObjectId, ref: 'Category'}],
rootParent: {type: mongoose.Schema.Types.ObjectId, ref: 'Category'},
priority: {type: Number, default: 0},
parent: {
type: mongoose.Schema.Types.ObjectId,
ref: "Category",
default: null,
},
childs: [{ type: mongoose.Schema.Types.ObjectId, ref: "Category" }],
treeCat: [{ type: mongoose.Schema.Types.ObjectId, ref: "Category" }],
rootParent: { type: mongoose.Schema.Types.ObjectId, ref: "Category" },
priority: { type: Number, default: 0 },
showInMenu: Boolean,
navIndex: {type: Number, default: null},
news: {type: Boolean, default: true},
child: {type: Boolean, default: true},
special: {type: Boolean, default: false},
allowComment: {type: Boolean, default: false},
level: {type: Number, default: 1},
siteMap: {type: Boolean, default: true},
navIndex: { type: Number, default: null },
news: { type: Boolean, default: true },
child: { type: Boolean, default: true },
special: { type: Boolean, default: false },
allowComment: { type: Boolean, default: false },
level: { type: Number, default: 1 },
siteMap: { type: Boolean, default: true },
modelType: String,
_creator: {type: mongoose.Schema.Types.ObjectId, ref: 'User'},
_updatedBy: {type: mongoose.Schema.Types.ObjectId, ref: 'User'},
haveNews: {type: Boolean, default: false},
_creator: { type: mongoose.Schema.Types.ObjectId, ref: "User" },
_updatedBy: { type: mongoose.Schema.Types.ObjectId, ref: "User" },
haveNews: { type: Boolean, default: false },
///// for client
hasNewsTab: {type: Boolean, default: true},
hasContentTab: {type: Boolean, default: true},
hasMediaTab: {type: Boolean, default: true},
hasSubMenusTab: {type: Boolean, default: true},
hasTermsTab: {type: Boolean, default: true},
hasNotificationsTab: {type: Boolean, default: true},
hasSpecNewsTab: {type: Boolean, default: true},
hasNazarTab: {type: Boolean, default: true},
hasNewsFileTab: {type: Boolean, default: true},
defaultPageType: {type: String, default: 'news'},
hasNewsTab: { type: Boolean, default: true },
hasContentTab: { type: Boolean, default: true },
hasMediaTab: { type: Boolean, default: true },
hasSubMenusTab: { type: Boolean, default: true },
hasTermsTab: { type: Boolean, default: true },
hasNotificationsTab: { type: Boolean, default: true },
hasSpecNewsTab: { type: Boolean, default: true },
hasNazarTab: { type: Boolean, default: true },
hasNewsFileTab: { type: Boolean, default: true },
defaultPageType: { type: String, default: "news" },
/** page */
showInFooter: {type: Number, enum: [0, 1, 2, 3], default: 0},
url: {type: String, default: null},
showInFooter: { type: Number, enum: [0, 1, 2, 3], default: 0 },
url: { type: String, default: null },
pageContent: String,
terms: [CategoryTermsFile],
hasManagerInfo: {type: Boolean, default: true},
managerCover: {type: String, get: image},
hasManagerInfo: { type: Boolean, default: true },
managerCover: { type: String, get: image },
managerName: String,
managerDescription: String
managerDescription: String,
});
CategorySchema.index({parent: 1, childs: 1});
CategorySchema.index({ parent: 1, childs: 1 });
CategorySchema
.pre('findOne', autoPopulateSubs)
.pre('find', autoPopulateSubs);
CategorySchema.pre("findOne", autoPopulateSubs).pre("find", autoPopulateSubs);
module.exports = mongoose.model('Category', CategorySchema);
module.exports = mongoose.model("Category", CategorySchema);