overleaf/services/web/app/coffee/models/Institution.coffee
Hugh O'Brien b3a957b8d8 Merge pull request #1141 from sharelatex/hb-v2-institutional-hub
v2 Institutional Hub

GitOrigin-RevId: ff01ccf659a2369284a22deb79ca45433ca1a2e8
2018-11-16 09:19:06 +00:00

24 lines
893 B
CoffeeScript

mongoose = require 'mongoose'
Schema = mongoose.Schema
ObjectId = Schema.ObjectId
settings = require 'settings-sharelatex'
request = require 'request'
InstitutionSchema = new Schema
v1Id: { type: Number, required: true }
managerIds: [ type:ObjectId, ref:'User' ]
# fetch institution's data from v1 API. Errors are ignored
InstitutionSchema.method 'fetchV1Data', (callback = (error, institution)->) ->
url = "#{settings.apis.v1.url}/universities/list/#{this.v1Id}"
request.get url, (error, response, body) =>
try parsedBody = JSON.parse(body) catch e
this.name = parsedBody?.name
this.countryCode = parsedBody?.country_code
this.departments = parsedBody?.departments
this.portalSlug = parsedBody?.portal_slug
callback(null, this)
mongoose.model 'Institution', InstitutionSchema
exports.Institution = mongoose.model 'Institution'
exports.InstitutionSchema = InstitutionSchema