diff --git a/package-lock.json b/package-lock.json index edfc2d812be..aac49df29b7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "apollo-server-express": "^2.25.4", "axios": "^0.21.4", "bcryptjs": "^2.4.3", + "body-parser": "^1.20.2", "cls-bluebird": "^2.1.0", "cls-hooked": "^4.2.2", "copy-paste": "^1.3.0", @@ -61,12 +62,12 @@ "@types/cls-hooked": "^4.3.3", "@types/copy-paste": "^1.1.30", "@types/cors": "^2.8.13", - "@types/express": "^4.17.13", + "@types/express": "^4.17.17", "@types/express-rate-limit": "^5.1.3", "@types/graphql-depth-limit": "^1.1.3", "@types/i18n": "^0.13.3", "@types/jsonwebtoken": "^8.5.8", - "@types/lodash": "^4.14.182", + "@types/lodash": "^4.14.195", "@types/mongoose-paginate-v2": "^1.6.5", "@types/morgan": "^1.9.3", "@types/node": "^18.11.9", diff --git a/package.json b/package.json index e230fe5f63b..5c33a3d3b86 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "apollo-server-express": "^2.25.4", "axios": "^0.21.4", "bcryptjs": "^2.4.3", + "body-parser": "^1.20.2", "cls-bluebird": "^2.1.0", "cls-hooked": "^4.2.2", "copy-paste": "^1.3.0", @@ -92,12 +93,12 @@ "@types/cls-hooked": "^4.3.3", "@types/copy-paste": "^1.1.30", "@types/cors": "^2.8.13", - "@types/express": "^4.17.13", + "@types/express": "^4.17.17", "@types/express-rate-limit": "^5.1.3", "@types/graphql-depth-limit": "^1.1.3", "@types/i18n": "^0.13.3", "@types/jsonwebtoken": "^8.5.8", - "@types/lodash": "^4.14.182", + "@types/lodash": "^4.14.195", "@types/mongoose-paginate-v2": "^1.6.5", "@types/morgan": "^1.9.3", "@types/node": "^18.11.9", diff --git a/src/config/plugins/loadPlugins.ts b/src/config/plugins/loadPlugins.ts new file mode 100644 index 00000000000..1e81516f2b0 --- /dev/null +++ b/src/config/plugins/loadPlugins.ts @@ -0,0 +1,26 @@ +import { Plugin } from "../../models"; +import _ from "lodash"; +import pluginData from "./pluginData.json"; +import { logger } from "../../libraries"; +// Only loads plugin data for the time if it's not currently present in the database +const loadPlugins = async (): Promise => { + const res = await Plugin.find(); + let databaseTitle = process.env.MONGO_DB_URL || ""; + databaseTitle = databaseTitle.split("mongodb.net/")[1].split("?")[0]; + if (_.isEmpty(res)) { + pluginData.forEach(async (plugin: any) => { + await Plugin.create(plugin); + }); + logger.info( + "\x1b[1m\x1b[32m%s\x1b[0m", + `Uploaded Plugins in ${databaseTitle} ` + ); + } else { + logger.info( + "\x1b[1m\x1b[32m%s\x1b[0m", + `Plugin data already present at ${databaseTitle}` + ); + } +}; + +export default loadPlugins; diff --git a/src/config/plugins/pluginData.json b/src/config/plugins/pluginData.json new file mode 100644 index 00000000000..570cc30f2ef --- /dev/null +++ b/src/config/plugins/pluginData.json @@ -0,0 +1,30 @@ +[ + { + "pluginInstallStatus": false, + "pluginName": "Posts", + "pluginCreatedBy": "Talawa Team", + "pluginDesc": "Allow users to create, comment and like and share the content in the form of Pictures and Videos.", + "installedOrgs": ["62ccfccd3eb7fd2a30f41601", "62ccfccd3eb7fd2a30f41601"] + }, + { + "pluginInstallStatus": false, + "pluginName": "Events22222222", + "pluginCreatedBy": "Talawa Team", + "pluginDesc": "Allow users to register and attend for new events with a inbuilt calendar to keep track of daily events.", + "installedOrgs": ["62ccfccd3eb7fd2a30f41601", "62ccfccd3eb7fd2a30f41601"] + }, + { + "pluginInstallStatus": false, + "pluginName": "Donation", + "pluginCreatedBy": "Talawa Team", + "pluginDesc": "Enables members of the organization to do one time or reccurinng donations to an organization", + "installedOrgs": ["62ccfccd3eb7fd2a30f41601", "62ccfccd3eb7fd2a30f41601"] + }, + { + "pluginInstallStatus": false, + "pluginName": "Chats", + "pluginCreatedBy": "Talawa Team", + "pluginDesc": "User can share messages with other users in a chat user interface.", + "installedOrgs": ["62ccfccd3eb7fd2a30f41601", "62ccfccd3eb7fd2a30f41601"] + } +] diff --git a/src/server.ts b/src/server.ts index f587e2a3901..b9f36446fb6 100644 --- a/src/server.ts +++ b/src/server.ts @@ -30,9 +30,8 @@ import { User } from "./models"; import { express as voyagerMiddleware } from "graphql-voyager/middleware"; import { generateErrorMessage } from "zod-error"; import { getEnvIssues } from "./env"; - +import loadPlugins from "./config/plugins/loadPlugins"; const app = express(); - app.use(requestTracing.middleware()); const pubsub = new PubSub(); @@ -249,3 +248,4 @@ const serverStart = async (): Promise => { }; serverStart(); +loadPlugins(); diff --git a/tsconfig.json b/tsconfig.json index 39814b2a3e8..ea514189e2b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,6 +5,7 @@ "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */, "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, "strict": true /* Enable all strict type-checking options. */, - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "skipLibCheck": true /* Skip type checking all .d.ts files. */, + "resolveJsonModule": true /* Allow to import JSON files */ } }