diff --git a/graph/src/mongodb.js b/graph/src/mongodb.js index 4e8f7d4..fa3d09b 100644 --- a/graph/src/mongodb.js +++ b/graph/src/mongodb.js @@ -1,8 +1,9 @@ const { MongoClient, ObjectId } = require('mongodb'); -const { MONGO_DSN } = require('./env'); +const { MONGO_DSN, B4GRAPH_TENANT_KEY } = require('./env'); const client = new MongoClient(MONGO_DSN); const promise = client.connect(); +const tenant = B4GRAPH_TENANT_KEY; // eslint-disable-next-line no-console promise.then(() => process.stdout.write(`\n💾 MongoDB connected to ${MONGO_DSN}\n`)); @@ -10,9 +11,9 @@ promise.catch((e) => { throw e; }); module.exports = { connect: () => promise, - retrieve: id => client.db().collection('submission').findOne({ _id: new ObjectId(id) }), - insert: payload => client.db().collection('submission').insertOne(payload), - complete: id => client.db().collection('submission').updateOne({ _id: new ObjectId(id) }, { $set: { reviewed: true } }), - submissions: ({ reviewed = false } = { reviewed: false }) => client.db().collection('submission').find({ reviewed }).toArray(), - submissionCount: () => client.db().collection('submission').countDocuments({ reviewed: false }), + retrieve: id => client.db().collection('submission').findOne({ tenant, _id: new ObjectId(id) }), + insert: payload => client.db().collection('submission').insertOne({ tenant, ...payload }), + complete: id => client.db().collection('submission').updateOne({ tenant, _id: new ObjectId(id) }, { $set: { reviewed: true } }), + submissions: ({ reviewed = false } = { reviewed: false }) => client.db().collection('submission').find({ tenant, reviewed }).toArray(), + submissionCount: () => client.db().collection('submission').countDocuments({ tenant, reviewed: false }), };