feat: added seeder for UI modules auth permissions
This commit is contained in:
@@ -65,11 +65,29 @@ const ItemTransactionTypes = [
|
||||
"RESERVE",
|
||||
"CHECK-IN",
|
||||
"CHECK-OUT",
|
||||
"RESERVE"
|
||||
"REPORT",
|
||||
"ADJUST",
|
||||
];
|
||||
|
||||
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 = {
|
||||
UserActions,
|
||||
InventoryScopes,
|
||||
@@ -88,4 +106,5 @@ module.exports = {
|
||||
AUTHORIZATION_FAILURE_ERROR_MESSAGE,
|
||||
ItemTransactionTypes,
|
||||
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);
|
||||
})();
|
||||
Reference in New Issue
Block a user