UNPKG

content-generator

Version:

Easy template generator to manage and save templates by key and languagecode.

27 lines (19 loc) 645 B
'use strict'; const mdbhandler = require('mongodb-handler'); const processenv = require('processenv'); const collection = processenv('CTM_COLLECTION') || 'CM_Templates'; const checkIfTemplateExist = (key, lang, callback) => { mdbhandler.fetch({ collection, doc: { key, lang }}, (err, res) => { if (err) { return callback(err); } if (res.lengt > 1) { return callback('Fatal Error: More than one template found with this language / key combination!'); } if (res.length === 0) { return callback(null, false); } callback(null, true, res[0]._id); }); }; module.exports = checkIfTemplateExist;