UNPKG

hrms-shared

Version:

HRMS shared code: models, middleware, utils

29 lines (25 loc) 711 B
const mongoose = require("mongoose"); module.exports = (connection) => { const { Schema } = mongoose; const departmentSchema = new Schema({ departmentName: { type: String, required: true, unique: true }, isActive: { type: Boolean, default: true }, }, { timestamps: true, collection: "Department" }); departmentSchema.pre("save", function (next) { if (this.departmentName) { this.departmentName = this.departmentName.toLowerCase(); } next(); }) return connection.models.Department || connection.model("Department", departmentSchema); };