feat: added seeder for UI modules auth permissions

This commit is contained in:
Sathishkumar Krishnan
2022-01-10 05:07:44 +05:30
parent a748fdf4d3
commit 08802c6820
5 changed files with 67 additions and 18 deletions

View File

@@ -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
View 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,
};

View 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);
})();