UNPKG

hrms-shared

Version:

HRMS shared code: models, middleware, utils

37 lines (34 loc) 898 B
const mongoose = require("mongoose"); module.exports = (connection) => { const { Schema } = mongoose; const RoleSchema = new Schema({ name: { type: String, required: true, }, type: { type: String, enum: ["global", "company"], default: "company" }, companyId: { type: mongoose.Schema.ObjectId, ref: "Company", required: function () { return this.type === "company" } }, permissions: [{ type: mongoose.Schema.ObjectId, ref: "Permission" }], isActive: { type: Boolean, defaultValue: true }, }, { timestamps: true, collection: "Role" }); return connection.models.Role || connection.model("Role", RoleSchema); };