feat: added seeder for UI modules auth permissions
This commit is contained in:
@@ -65,11 +65,29 @@ const ItemTransactionTypes = [
|
|||||||
"RESERVE",
|
"RESERVE",
|
||||||
"CHECK-IN",
|
"CHECK-IN",
|
||||||
"CHECK-OUT",
|
"CHECK-OUT",
|
||||||
"RESERVE"
|
"REPORT",
|
||||||
|
"ADJUST",
|
||||||
];
|
];
|
||||||
|
|
||||||
const ReportItemForTypes = ["LOCATION", "ISSUE", "INCIDENT"];
|
const ReportItemForTypes = ["LOCATION", "ISSUE", "INCIDENT"];
|
||||||
|
|
||||||
|
const AllUIModules = [
|
||||||
|
"Home::Explore Inventory",
|
||||||
|
"Home::Scan",
|
||||||
|
"Home::Receiving",
|
||||||
|
"Home::Shipping",
|
||||||
|
"Setup::Warehouse design",
|
||||||
|
"Setup::Inventory Definition",
|
||||||
|
"Setup::User & Access",
|
||||||
|
"Setup::Labelling",
|
||||||
|
"Report::Warehouse design",
|
||||||
|
"Report::Inventory Definition",
|
||||||
|
"Report::User & Access",
|
||||||
|
"Report::Labelling",
|
||||||
|
"Messages",
|
||||||
|
"Settings",
|
||||||
|
];
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
UserActions,
|
UserActions,
|
||||||
InventoryScopes,
|
InventoryScopes,
|
||||||
@@ -88,4 +106,5 @@ module.exports = {
|
|||||||
AUTHORIZATION_FAILURE_ERROR_MESSAGE,
|
AUTHORIZATION_FAILURE_ERROR_MESSAGE,
|
||||||
ItemTransactionTypes,
|
ItemTransactionTypes,
|
||||||
ReportItemForTypes,
|
ReportItemForTypes,
|
||||||
|
AllUIModules,
|
||||||
};
|
};
|
||||||
|
|||||||
23
src/config/db/connect.js
Normal file
23
src/config/db/connect.js
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
const mongoose = require("mongoose");
|
||||||
|
|
||||||
|
const { MONGODB_URI } = require("../env");
|
||||||
|
|
||||||
|
|
||||||
|
const connect = async () => {
|
||||||
|
console.log("Connecting to MongoDB ...");
|
||||||
|
await mongoose
|
||||||
|
.connect(MONGODB_URI, {
|
||||||
|
useNewUrlParser: true,
|
||||||
|
useUnifiedTopology: true,
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
console.log("Connected to MongoDB at: ", MONGODB_URI);
|
||||||
|
})
|
||||||
|
.catch(console.error);
|
||||||
|
|
||||||
|
mongoose.set("debug", true);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
connect,
|
||||||
|
};
|
||||||
13
src/config/db/seed-auth-data.js
Normal file
13
src/config/db/seed-auth-data.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
const db = require("./connect");
|
||||||
|
const UserPermission = require("../../models/UserPermission");
|
||||||
|
const { AllUIModules } = require("../constants");
|
||||||
|
(async () => {
|
||||||
|
await db.connect();
|
||||||
|
for (const UIModule of AllUIModules) {
|
||||||
|
const modulePermission = await UserPermission.findOne({ name: UIModule, allowedUIModules: [UIModule] });
|
||||||
|
if (!modulePermission) {
|
||||||
|
await UserPermission.create({ name: UIModule, allowedUIModules: [UIModule] });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
process.exit(1);
|
||||||
|
})();
|
||||||
16
src/index.js
16
src/index.js
@@ -4,26 +4,18 @@ const helmet = require("helmet");
|
|||||||
const cors = require("cors");
|
const cors = require("cors");
|
||||||
const morgan = require("morgan");
|
const morgan = require("morgan");
|
||||||
|
|
||||||
const mongoose = require("mongoose");
|
|
||||||
const { router } = require("./controller");
|
const { router } = require("./controller");
|
||||||
const {
|
const {
|
||||||
API_PORT,
|
API_PORT,
|
||||||
MONGODB_URI,
|
|
||||||
} = require("./config/env");
|
} = require("./config/env");
|
||||||
|
|
||||||
|
const db = require("./config/db/connect");
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
console.log("Connecting to MongoDB ...");
|
console.log("Connecting to MongoDB ...");
|
||||||
await mongoose
|
|
||||||
.connect(MONGODB_URI, {
|
|
||||||
useNewUrlParser: true,
|
|
||||||
useUnifiedTopology: true,
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
console.log("Connected to MongoDB at: ", MONGODB_URI);
|
|
||||||
})
|
|
||||||
.catch(console.error);
|
|
||||||
|
|
||||||
mongoose.set("debug", true);
|
await db.connect();
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
const mongoose = require("mongoose");
|
const mongoose = require("mongoose");
|
||||||
const {
|
const { UserActions, WarehouseScopes, InventoryScopes, AllUIModules } = require("./../config/constants");
|
||||||
UserActions,
|
|
||||||
WarehouseScopes,
|
|
||||||
InventoryScopes,
|
|
||||||
} = require("./../config/constants");
|
|
||||||
|
|
||||||
const schema = new mongoose.Schema(
|
const schema = new mongoose.Schema(
|
||||||
{
|
{
|
||||||
@@ -37,6 +33,12 @@ const schema = new mongoose.Schema(
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
allowedUIModules: [
|
||||||
|
{
|
||||||
|
type: String,
|
||||||
|
enum: AllUIModules,
|
||||||
|
},
|
||||||
|
],
|
||||||
actions: [
|
actions: [
|
||||||
{
|
{
|
||||||
type: String,
|
type: String,
|
||||||
|
|||||||
Reference in New Issue
Block a user