Files
freeplanet_serverside/src/server/models/msg_template.js
Paolo Arena c939be279e - Nuovo Sistema di Flotte per Tutor.
X - Mettere anche la email del sognatore, per chi è abituato ad inviarla in quel modo...
X - Controllare che sul sito compaiano le informazioni del Sognatore...
2020-10-17 22:12:37 +02:00

103 lines
1.9 KiB
JavaScript
Executable File

const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const tools = require('../tools/general');
mongoose.Promise = global.Promise;
mongoose.level = "F";
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
schema.options.usePushEach = true
});
const MsgTemplateSchema = new Schema({
idapp: {
type: String,
},
typemsg: {
type: Number,
},
title: {
type: String,
},
title_it: {
type: String,
},
msg_it: {
type: String,
},
title_enUs: {
type: String,
},
msg_enUs: {
type: String,
},
title_si: {
type: String,
},
msg_si: {
type: String,
},
title_fr: {
type: String,
},
msg_fr: {
type: String,
},
title_es: {
type: String,
},
msg_es: {
type: String,
},
title_pt: {
type: String,
},
msg_pt: {
type: String,
},
});
MsgTemplateSchema.statics.getFieldsForSearch = function () {
return [{ field: 'title', type: tools.FieldType.string },
]
};
MsgTemplateSchema.statics.executeQueryTable = function (idapp, params) {
params.fieldsearch = this.getFieldsForSearch();
return tools.executeQueryTable(this, idapp, params);
};
MsgTemplateSchema.statics.getMsgByLang = async function (idapp, typemsg, lang) {
const MsgTemplate = this;
try {
const mymsg = await MsgTemplate.findOne({ idapp, typemsg });
if (!!mymsg) {
if ((!!mymsg["msg_" + lang]) && (!!mymsg["title_" + lang])) {
return { body: mymsg["msg_" + lang], title: mymsg["title_" + lang] }
}
}
} catch (e) {
return { body: '', title: '' };
}
return { body: '', title: '' };
};
MsgTemplateSchema.statics.findAllIdApp = async function (idapp) {
const MsgTemplate = this;
const myfind = { idapp };
return await MsgTemplate.find(myfind, (err, arrrec) => {
return arrrec
});
};
const MsgTemplate = mongoose.model('MsgTemplate', MsgTemplateSchema);
module.exports = { MsgTemplate };