async function getEmailTemplate(name, params) { const source = await EmailTemplate.findOne({ name }); if (!source) { throw new Error(`No EmailTemplates found. Please check that at least one is generated at server startup, restart your server and try again.`); } return { message: _.template(source.message)(params), subject: _.template(source.subject)(params), }; }
function findOne(query) { return new Promise((resv, rej) => { Count.findOne(query, (err, res) => { if(err) { rej(err); return; } resv(res); }) }) }
var findOne = function (data, callback){ roomModel.findOne(data, callback); }
static async getBySlug({ bookSlug, chapterSlug, userId, isAdmin }) { const book = await Book.getBySlug({ slug: bookSlug }); if (!book) { throw new Error('Book not found'); } const chapter = await this.findOne({ bookId: book._id, slug: chapterSlug }); if (!chapter) { throw new Error('Chapter not found'); } const chapterObj = chapter.toObject(); chapterObj.book = book; if (userId) { const purchase = await Purchase.findOne({ userId, bookId: book._id }); chapterObj.isPurchased = !!purchase || isAdmin; } const isFreeOrPurchased = chapter.isFree || chapterObj.isPurchased; if (!isFreeOrPurchased) { delete chapterObj.htmlContent; } return chapterObj; }
async function getEmailTemplate(name, params) { const source = await EmailTemplate.findOne({ name }); if (!source) { throw new Error(`No EmailTemplates found. Please check that at least one is generated at server startup, restart your server and try again.`); } return { message: _.template(source.message)(params), subject: _.template(source.subject)(params), }; }
async function getEmailTemplate(name, params) { const source = await EmailTemplate.findOne({ name }); if (!source) { throw new Error(`No EmailTemplates found. Please check that at least one is generated at server startup, restart your server and try again.`); } return { message: _.template(source.message)(params), subject: _.template(source.subject)(params), }; }
async function getEmailTemplate(name, params) { const source = await EmailTemplate.findOne({ name }); if (!source) { throw new Error(`No EmailTemplates found. Please check that at least one is generated at server startup, restart your server and try again.`); } return { message: _.template(source.message)(params), subject: _.template(source.subject)(params), }; }
async function getEmailTemplate(name, params) { const source = await EmailTemplate.findOne({ name }); if (!source) { throw new Error(`No EmailTemplates found. Please check that at least one is generated at server startup, restart your server and try again.`); } return { message: _.template(source.message)(params), subject: _.template(source.subject)(params), }; }
async function getEmailTemplate(name, params) { const source = await EmailTemplate.findOne({ name }); if (!source) { throw new Error(`No EmailTemplates found. Please check that at least one is generated at server startup, restart your server and try again.`); } return { message: _.template(source.message)(params), subject: _.template(source.subject)(params), }; }
async function getEmailTemplate(name, params) { const source = await EmailTemplate.findOne({ name }); if (!source) { throw new Error(`No EmailTemplates found. Please check that at least one is generated at server startup, restart your server and try again.`); } return { message: _.template(source.message)(params), subject: _.template(source.subject)(params), }; }
async function getEmailTemplate(name, params) { const source = await EmailTemplate.findOne({ name }); if (!source) { throw new Error(`No EmailTemplates found. Please check that at least one is generated at server startup, restart your server and try again.`); } return { message: _.template(source.message)(params), subject: _.template(source.subject)(params), }; }
async function getEmailTemplate(name, params) { const source = await EmailTemplate.findOne({ name }); if (!source) { throw new Error(`No EmailTemplates found. Please check that at least one is generated at server startup, restart your server and try again.`); } return { message: _.template(source.message)(params), subject: _.template(source.subject)(params), }; }
async function getEmailTemplate(name, params) { const source = await EmailTemplate.findOne({ name }); if (!source) { throw new Error(`No EmailTemplates found. Please check that at least one is generated at server startup, restart your server and try again.`); } return { message: _.template(source.message)(params), subject: _.template(source.subject)(params), }; }
var findOne = function (data, callback){ userModel.findOne(data, callback); }
static async getBySlug({ bookSlug, chapterSlug, userId, isAdmin }) { const book = await Book.getBySlug({ slug: bookSlug }); if (!book) { throw new Error('Book not found'); } const chapter = await this.findOne({ bookId: book._id, slug: chapterSlug }); if (!chapter) { throw new Error('Chapter not found'); } const chapterObj = chapter.toObject(); chapterObj.book = book; if (userId) { const purchase = await Purchase.findOne({ userId, bookId: book._id }); chapterObj.isPurchased = !!purchase || isAdmin; } const isFreeOrPurchased = chapter.isFree || chapterObj.isPurchased; if (!isFreeOrPurchased) { delete chapterObj.htmlContent; } return chapterObj; }