/** * Update a publicize connection belonging to the current user. * * @param {object} [query] - query object parameter * @param {object} body - body object parameter * @param {Function} fn - callback function * @returns {Function} request handler */ update( query, body, fn ) { return this.wpcom.req.put( root + this._id, query, body, fn ); }
/** * Return recent comments * * @param {object} [query] - query object parameter * @param {Function} fn - callback function * @returns {Function} request handler */ comments( query, fn ) { var comment = new Comment( null, this._id, this._sid, this.wpcom ); return comment.replies( query, fn ); }
static async getBySlug({ slug }) { const bookDoc = await this.findOne({ slug }); if (!bookDoc) { throw new Error('Book not found'); } const book = bookDoc.toObject(); book.chapters = (await Chapter.find({ bookId: book._id }, 'title slug').sort({ order: 1 })).map( (chapter) => chapter.toObject(), ); return book; }
const destroyUserServices = user => { const userId = user._id; allServiceMaps.forEach(serviceMap => { const userService = serviceMap.get(userId); if (userService != null) { userService.destroy(); serviceMap.delete(userId); } }); }
async findEntry(pollyRequest) { const { id, order, recordingId } = pollyRequest; const recording = await this.find(recordingId); return ( (recording && recording.log.entries.find( entry => entry._id === id && entry._order === order )) || null ); }
static async getInitialProps(ctx) { const isFromServer = !!ctx.req; const user = ctx.req ? ctx.req.user && ctx.req.user.toObject() : globalUser; if (isFromServer && user) { user._id = user._id.toString(); } const props = { user, isFromServer }; if (Page.getInitialProps) { Object.assign(props, (await Page.getInitialProps(ctx)) || {}); } return props; }
/** * Add a new media from url * * @param {object} [query] - query object parameter * @param {Array|string} files - media files to add * @param {Function} fn - callback function * @returns {Function} request handler */ addMediaUrls( query, files, fn ) { const media = new Media( null, this._id, this.wpcom ); return media.addUrls( query, files, fn ); }
constructor(user, services, ...eventEmitterConfig) { super(...eventEmitterConfig); if (!user || !user._id) throw new Error('Missing user ID'); this.user = user; this.services = services; }
/** * Create a `SitePlugin` instance * * @param {string} slug - plugin identifier * @returns {SitePlugin} SitePlugin instance */ plugin( slug ) { return new SitePlugin( slug, this._id, this.wpcom ); }
/** * Create a `Reblog` instance * * @returns {Reblog} Reblog instance */ reblog() { return new Reblog( this._id, this._sid, this.wpcom ); }
const updateUserServices = user => { const userId = user._id; allServiceMaps.forEach(serviceMap => { const service = serviceMap.get(userId); if (service != null) { service.updateUser(user); serviceMap.delete(userId); } }); }
/** * Create a `SiteWPComPlugin` instance * * @param {string} slug - plugin identifier * @returns {SiteWPComPlugin} SiteWPComPlugin instance */ wpcomPlugin( slug ) { return new SiteWPComPlugin( slug, this._id, this.wpcom ); }
/** * Create a `SiteSettings` instance * * @returns {SiteSettings} SiteSettings instance */ settings() { return new SiteSettings( this._id, this.wpcom ); }
/** * Create a `SiteDomain` instance * * @returns {SiteDomain} SiteDomain instance */ domain() { return new SiteDomain( this._id, this.wpcom ); }
static async getBySlug({ slug }) { const bookDoc = await this.findOne({ slug }); if (!bookDoc) { throw new Error('Book not found'); } const book = bookDoc.toObject(); book.chapters = (await Chapter.find({ bookId: book._id }, 'title slug').sort({ order: 1 })).map( (chapter) => chapter.toObject(), ); return book; }