mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-02 13:49:00 +02:00
b027ef95e5
[misc] upgrade eslint packages to the latest version everywhere GitOrigin-RevId: f1480d4a171acef82fb26c4aa54be3a6088b0ab3
33 lines
803 B
JavaScript
33 lines
803 B
JavaScript
const { ObjectId } = require('mongodb')
|
|
const PublisherModel = require('../../../../app/src/models/Publisher').Publisher
|
|
|
|
let count = parseInt(Math.random() * 999999)
|
|
|
|
class Publisher {
|
|
constructor(options = {}) {
|
|
this.slug = options.slug || `publisher-slug-${count}`
|
|
this.managerIds = []
|
|
|
|
count += 1
|
|
}
|
|
|
|
ensureExists(callback) {
|
|
const filter = { slug: this.slug }
|
|
const options = { upsert: true, new: true, setDefaultsOnInsert: true }
|
|
PublisherModel.findOneAndUpdate(filter, {}, options, (error, publisher) => {
|
|
this._id = publisher._id
|
|
callback(error)
|
|
})
|
|
}
|
|
|
|
setManagerIds(managerIds, callback) {
|
|
return PublisherModel.findOneAndUpdate(
|
|
{ _id: ObjectId(this._id) },
|
|
{ managerIds },
|
|
callback
|
|
)
|
|
}
|
|
}
|
|
|
|
module.exports = Publisher
|