mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-24 21:12:38 -04:00
11a81007f5
Reducing timeout for v1 calls for endpoints GitOrigin-RevId: 0f28569a1401e2fad7434df2a68a230ceb0f4aca
45 lines
1.5 KiB
JavaScript
45 lines
1.5 KiB
JavaScript
const mongoose = require('../infrastructure/Mongoose')
|
|
const { Schema } = mongoose
|
|
const { ObjectId } = Schema
|
|
const settings = require('@overleaf/settings')
|
|
const logger = require('@overleaf/logger')
|
|
const request = require('request')
|
|
|
|
const InstitutionSchema = new Schema({
|
|
v1Id: { type: Number, required: true },
|
|
managerIds: [{ type: ObjectId, ref: 'User' }],
|
|
metricsEmail: {
|
|
optedOutUserIds: [{ type: ObjectId, ref: 'User' }],
|
|
lastSent: { type: Date },
|
|
},
|
|
})
|
|
|
|
// fetch institution's data from v1 API. Errors are ignored
|
|
InstitutionSchema.method('fetchV1Data', function (callback) {
|
|
const url = `${settings.apis.v1.url}/universities/list/${this.v1Id}`
|
|
request.get(
|
|
{ url, timeout: settings.apis.v1.timeout },
|
|
(error, response, body) => {
|
|
let parsedBody
|
|
try {
|
|
parsedBody = JSON.parse(body)
|
|
} catch (error1) {
|
|
// log error and carry on without v1 data
|
|
error = error1
|
|
logger.err(
|
|
{ model: 'Institution', v1Id: this.v1Id, error },
|
|
'[fetchV1DataError]'
|
|
)
|
|
}
|
|
this.name = parsedBody != null ? parsedBody.name : undefined
|
|
this.countryCode =
|
|
parsedBody != null ? parsedBody.country_code : undefined
|
|
this.departments = parsedBody != null ? parsedBody.departments : undefined
|
|
this.portalSlug = parsedBody != null ? parsedBody.portal_slug : undefined
|
|
callback(null, this)
|
|
}
|
|
)
|
|
})
|
|
|
|
exports.Institution = mongoose.model('Institution', InstitutionSchema)
|
|
exports.InstitutionSchema = InstitutionSchema
|