overleaf/services/web/app/coffee/models/Publisher.coffee
Timothée Alby dffb6bc7a2 Merge pull request #1187 from sharelatex/ta-publisher-membership
Add Publisher Entity for UserMemberships

GitOrigin-RevId: 862b1e4fe6d33b63ddfdaef47c02809c4558f9cc
2018-11-28 10:17:36 +00:00

34 lines
1 KiB
CoffeeScript

mongoose = require 'mongoose'
Schema = mongoose.Schema
ObjectId = Schema.ObjectId
settings = require 'settings-sharelatex'
request = require 'request'
PublisherSchema = new Schema
slug: { type: String, required: true }
managerIds: [ type:ObjectId, ref:'User' ]
# fetch publisher's (brand on v1) data from v1 API. Errors are ignored
PublisherSchema.method 'fetchV1Data', (callback = (error, publisher)->) ->
request {
baseUrl: settings.apis.v1.url
url: "/api/v2/brands/#{this.slug}"
method: 'GET'
auth:
user: settings.apis.v1.user
pass: settings.apis.v1.pass
sendImmediately: true
}, (error, response, body) =>
try parsedBody = JSON.parse(body) catch e
this.name = parsedBody?.name
this.partner = parsedBody?.partner
callback(null, this)
conn = mongoose.createConnection(settings.mongo.url, {
server: {poolSize: settings.mongo.poolSize || 10},
config: {autoIndex: false}
})
Publisher = conn.model 'Publisher', PublisherSchema
exports.Publisher = Publisher
exports.PublisherSchema = PublisherSchema