overleaf/services/web/app/coffee/models/Institution.coffee
James Allen 49e19cad64 Merge pull request #1162 from sharelatex/ja-show-group-management
Add group and institution membership and management info to subscription dashboard

GitOrigin-RevId: 1aba5d5a20cd00ff5090811d0f66dc9c4944dd60
2018-11-20 11:03:56 +00:00

29 lines
1 KiB
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)
conn = mongoose.createConnection(settings.mongo.url, {
server: {poolSize: settings.mongo.poolSize || 10},
config: {autoIndex: false}
})
Institution = conn.model 'Institution', InstitutionSchema
exports.Institution = Institution
exports.InstitutionSchema = InstitutionSchema