Files
Verso/services/web/test/acceptance/src/helpers/Institution.mjs
T
Andrew Rumble 394c60f2cf Merge pull request #29659 from overleaf/revert-29656-revert-29521-ar-models-es-conversion
Revert "Revert "[web] Convert models and self-referential test files to ESM ""

GitOrigin-RevId: f64000ae31d298b075a8722dfc51f294c71bc021
2025-11-18 09:04:56 +00:00

38 lines
884 B
JavaScript

import mongodb from 'mongodb-legacy'
import { Institution as InstitutionModel } from '../../../../app/src/models/Institution.mjs'
const { ObjectId } = mongodb
let count = parseInt(Math.random() * 999999)
class Institution {
constructor(options = {}) {
this.v1Id = options.v1Id || count
this.managerIds = []
count += 1
}
async ensureExists() {
const filter = { v1Id: this.v1Id }
const options = { upsert: true, new: true, setDefaultsOnInsert: true }
const institution = await InstitutionModel.findOneAndUpdate(
filter,
{},
options
)
this._id = institution._id
}
setManagerIds(managerIds, callback) {
return InstitutionModel.findOneAndUpdate(
{ _id: new ObjectId(this._id) },
{ managerIds }
)
.then((...args) => callback(null, ...args))
.catch(callback)
}
}
export default Institution