forked from UKSOURCE/cms.hailearning.edu.vn
first commit
This commit is contained in:
32
models/department.js
Normal file
32
models/department.js
Normal file
@@ -0,0 +1,32 @@
|
||||
const mongoose = require('mongoose');
|
||||
|
||||
// Helper function to generate slug
|
||||
function generateSlug(name) {
|
||||
return name
|
||||
.toLowerCase()
|
||||
.trim()
|
||||
.replace(/[^\w\s-]/g, '') // Remove special characters
|
||||
.replace(/\s+/g, '-') // Replace spaces with -
|
||||
.replace(/-+/g, '-'); // Replace multiple - with single -
|
||||
}
|
||||
|
||||
const departmentSchema = new mongoose.Schema({
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
trim: true,
|
||||
unique: true,
|
||||
lowercase: true
|
||||
},
|
||||
slug: {
|
||||
type: String,
|
||||
required: true,
|
||||
unique: true,
|
||||
lowercase: true,
|
||||
index: true
|
||||
}
|
||||
}, {
|
||||
timestamps: false // Thêm timestamps để theo dõi thời gian tạo/cập nhật
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('Department', departmentSchema);
|
||||
Reference in New Issue
Block a user