Skip to content

Commit 0017abe

Browse files
1 parent 8c64399 commit 0017abe

File tree

6 files changed

+66
-7
lines changed

6 files changed

+66
-7
lines changed

package-lock.json

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"apollo-server-express": "^2.25.4",
4848
"axios": "^0.21.4",
4949
"bcryptjs": "^2.4.3",
50+
"body-parser": "^1.20.2",
5051
"cls-bluebird": "^2.1.0",
5152
"cls-hooked": "^4.2.2",
5253
"copy-paste": "^1.3.0",
@@ -92,12 +93,12 @@
9293
"@types/cls-hooked": "^4.3.3",
9394
"@types/copy-paste": "^1.1.30",
9495
"@types/cors": "^2.8.13",
95-
"@types/express": "^4.17.13",
96+
"@types/express": "^4.17.17",
9697
"@types/express-rate-limit": "^5.1.3",
9798
"@types/graphql-depth-limit": "^1.1.3",
9899
"@types/i18n": "^0.13.3",
99100
"@types/jsonwebtoken": "^8.5.8",
100-
"@types/lodash": "^4.14.182",
101+
"@types/lodash": "^4.14.195",
101102
"@types/mongoose-paginate-v2": "^1.6.5",
102103
"@types/morgan": "^1.9.3",
103104
"@types/node": "^18.11.9",

src/config/plugins/loadPlugins.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Plugin } from "../../models";
2+
import _ from "lodash";
3+
import pluginData from "./pluginData.json";
4+
import { logger } from "../../libraries";
5+
// Only loads plugin data for the time if it's not currently present in the database
6+
const loadPlugins = async (): Promise<void> => {
7+
const res = await Plugin.find();
8+
let databaseTitle = process.env.MONGO_DB_URL || "";
9+
databaseTitle = databaseTitle.split("mongodb.net/")[1].split("?")[0];
10+
if (_.isEmpty(res)) {
11+
pluginData.forEach(async (plugin: any) => {
12+
await Plugin.create(plugin);
13+
});
14+
logger.info(
15+
"\x1b[1m\x1b[32m%s\x1b[0m",
16+
`Uploaded Plugins in ${databaseTitle} `
17+
);
18+
} else {
19+
logger.info(
20+
"\x1b[1m\x1b[32m%s\x1b[0m",
21+
`Plugin data already present at ${databaseTitle}`
22+
);
23+
}
24+
};
25+
26+
export default loadPlugins;

src/config/plugins/pluginData.json

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[
2+
{
3+
"pluginInstallStatus": false,
4+
"pluginName": "Posts",
5+
"pluginCreatedBy": "Talawa Team",
6+
"pluginDesc": "Allow users to create, comment and like and share the content in the form of Pictures and Videos.",
7+
"installedOrgs": ["62ccfccd3eb7fd2a30f41601", "62ccfccd3eb7fd2a30f41601"]
8+
},
9+
{
10+
"pluginInstallStatus": false,
11+
"pluginName": "Events22222222",
12+
"pluginCreatedBy": "Talawa Team",
13+
"pluginDesc": "Allow users to register and attend for new events with a inbuilt calendar to keep track of daily events.",
14+
"installedOrgs": ["62ccfccd3eb7fd2a30f41601", "62ccfccd3eb7fd2a30f41601"]
15+
},
16+
{
17+
"pluginInstallStatus": false,
18+
"pluginName": "Donation",
19+
"pluginCreatedBy": "Talawa Team",
20+
"pluginDesc": "Enables members of the organization to do one time or reccurinng donations to an organization",
21+
"installedOrgs": ["62ccfccd3eb7fd2a30f41601", "62ccfccd3eb7fd2a30f41601"]
22+
},
23+
{
24+
"pluginInstallStatus": false,
25+
"pluginName": "Chats",
26+
"pluginCreatedBy": "Talawa Team",
27+
"pluginDesc": "User can share messages with other users in a chat user interface.",
28+
"installedOrgs": ["62ccfccd3eb7fd2a30f41601", "62ccfccd3eb7fd2a30f41601"]
29+
}
30+
]

src/server.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ import { User } from "./models";
3030
import { express as voyagerMiddleware } from "graphql-voyager/middleware";
3131
import { generateErrorMessage } from "zod-error";
3232
import { getEnvIssues } from "./env";
33-
33+
import loadPlugins from "./config/plugins/loadPlugins";
3434
const app = express();
35-
3635
app.use(requestTracing.middleware());
3736

3837
const pubsub = new PubSub();
@@ -249,3 +248,4 @@ const serverStart = async (): Promise<void> => {
249248
};
250249

251250
serverStart();
251+
loadPlugins();

tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
66
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
77
"strict": true /* Enable all strict type-checking options. */,
8-
"skipLibCheck": true /* Skip type checking all .d.ts files. */
8+
"skipLibCheck": true /* Skip type checking all .d.ts files. */,
9+
"resolveJsonModule": true /* Allow to import JSON files */
910
}
1011
}

0 commit comments

Comments
 (0)