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; }
skip += (messageTotal - total); const messageData = await Message.find({roomid: id}).skip(skip).sort({"time": -1}).limit(20).exec(); message.data = messageData.reverse(); res.json({
const gzip = zlib.createGzip(); const chapters = Chapter.find({}, 'slug').sort({ order: 1 }).setOptions({ lean: true });
console.log(typeof msgid); if(!msgid) { const messageData = await Message.find( { roomid }).sort({"_id": -1}).limit(20).exec(); message.data = messageData.reverse(); } else { const messageData = await Message.find({'_id': { '$lt': msgid }, roomid }).sort({"_id": -1}).limit(20).exec(); message.data = messageData.reverse();
contents.find(query) .sort(sort) .limit(limit) .select('category title alias user date reading thumbnail abstract extensions') .populate('category', 'name path') .populate('user', 'nickname email') .populate('thumbnail', 'fileName description date') .exec(function (err, contents) { if (err) { err.type = 'database'; return callback(err); } contents = _.map(contents, function (content) { if (content.thumbnail) var thumbnailSrc = content.thumbnail.src; content = content.toObject(); if (_.get(content, 'category.path')) content.href = content.category.path + '/' + content.alias; if (content.thumbnail) content.thumbnail.src = thumbnailSrc; delete content.alias; delete content.reading.createAt; return content; }); callback(null, contents); });
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; }
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; }
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; }
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; }
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; }
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; }
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; }
skip += (messageTotal - total); const messageData = await Message.find({roomid: id}).skip(skip).sort({"time": -1}).limit(20).exec(); message.data = messageData.reverse(); res.json({
const gzip = zlib.createGzip(); const chapters = Chapter.find({}, 'slug').sort({ order: 1 }).setOptions({ lean: true });