feat: added roles and permissions models
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
const mongoose = require("mongoose");
|
||||
const { isEmail } = require("validator");
|
||||
const { UserActions, WarehouseScopes } = require("./../config/constants");
|
||||
const bcrypt = require("bcrypt");
|
||||
|
||||
const schema = new mongoose.Schema(
|
||||
@@ -37,28 +36,16 @@ const schema = new mongoose.Schema(
|
||||
passwordResetToken: {
|
||||
type: String,
|
||||
},
|
||||
authPolicies: [
|
||||
roles: [
|
||||
{
|
||||
inventory: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: "Inventory",
|
||||
},
|
||||
warehouseScope: {
|
||||
on: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
refPath: "onModel",
|
||||
},
|
||||
onModel: {
|
||||
type: String,
|
||||
required: true,
|
||||
enum: WarehouseScopes,
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
type: String,
|
||||
required: true,
|
||||
enum: UserActions,
|
||||
},
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: "UserRole",
|
||||
},
|
||||
],
|
||||
permissions: [
|
||||
{
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: "UserPermission",
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
39
src/models/UserPermission.js
Normal file
39
src/models/UserPermission.js
Normal file
@@ -0,0 +1,39 @@
|
||||
const mongoose = require("mongoose");
|
||||
const { UserActions, WarehouseScopes } = require("./../config/constants");
|
||||
|
||||
const schema = new mongoose.Schema(
|
||||
{
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
trim: true,
|
||||
},
|
||||
inventory: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: "Inventory",
|
||||
},
|
||||
warehouseScope: {
|
||||
on: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
refPath: "onModel",
|
||||
},
|
||||
onModel: {
|
||||
type: String,
|
||||
required: true,
|
||||
enum: WarehouseScopes,
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
type: String,
|
||||
required: true,
|
||||
enum: UserActions,
|
||||
},
|
||||
},
|
||||
{
|
||||
timestamps: true,
|
||||
}
|
||||
);
|
||||
|
||||
const UserPermission = mongoose.model("UserPermission", schema);
|
||||
|
||||
module.exports = UserPermission;
|
||||
24
src/models/UserRole.js
Normal file
24
src/models/UserRole.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
const schema = new mongoose.Schema(
|
||||
{
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
trim: true,
|
||||
},
|
||||
permissions: [
|
||||
{
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: "UserPermission",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
timestamps: true,
|
||||
}
|
||||
);
|
||||
|
||||
const UserRole = mongoose.model("UserRole", schema);
|
||||
|
||||
module.exports = UserRole;
|
||||
Reference in New Issue
Block a user