overleaf/services/web/test/acceptance/src/helpers/Institution.js
Alf Eaton 50df230846 [web] Upgrade Prettier to match version in monorepo root (#6231)
GitOrigin-RevId: 02f97af1b9704782eee77a0b7dfc477ada23e34d
2022-01-11 09:03:23 +00:00

38 lines
851 B
JavaScript

const { ObjectId } = require('mongodb')
const InstitutionModel =
require('../../../../app/src/models/Institution').Institution
let count = parseInt(Math.random() * 999999)
class Institution {
constructor(options = {}) {
this.v1Id = options.v1Id || count
this.managerIds = []
count += 1
}
ensureExists(callback) {
const filter = { v1Id: this.v1Id }
const options = { upsert: true, new: true, setDefaultsOnInsert: true }
InstitutionModel.findOneAndUpdate(
filter,
{},
options,
(error, institution) => {
this._id = institution._id
callback(error)
}
)
}
setManagerIds(managerIds, callback) {
return InstitutionModel.findOneAndUpdate(
{ _id: ObjectId(this._id) },
{ managerIds: managerIds },
callback
)
}
}
module.exports = Institution