2024-04-29 14:58:45 +02:00
|
|
|
mongoose = require('mongoose').set('debug', false)
|
|
|
|
|
const Schema = mongoose.Schema;
|
|
|
|
|
|
|
|
|
|
const tools = require('../tools/general');
|
|
|
|
|
|
|
|
|
|
const shared_consts = require('../tools/shared_nodejs');
|
|
|
|
|
|
2024-12-17 17:55:47 +01:00
|
|
|
const { ObjectId } = require('mongodb');
|
2024-04-29 14:58:45 +02:00
|
|
|
|
|
|
|
|
mongoose.Promise = global.Promise;
|
|
|
|
|
mongoose.level = "F";
|
|
|
|
|
|
|
|
|
|
// A1P
|
|
|
|
|
|
|
|
|
|
// Resolving error Unknown modifier: $pushAll
|
|
|
|
|
mongoose.plugin(schema => {
|
|
|
|
|
schema.options.usePushEach = true
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const ImportaMacroSchema = new Schema({
|
|
|
|
|
idapp: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
_id: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var ImportaMacro = module.exports = mongoose.model('ImportaMacro', ImportaMacroSchema);
|
|
|
|
|
|
|
|
|
|
ImportaMacroSchema.index({ idapp: 1 });
|
|
|
|
|
|
|
|
|
|
module.exports.getFieldsForSearch = function () {
|
|
|
|
|
return [
|
|
|
|
|
{ field: 'name', type: tools.FieldType.string },
|
|
|
|
|
{ field: 'description', type: tools.FieldType.string },
|
|
|
|
|
]
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports.executeQueryTable = function (idapp, params) {
|
|
|
|
|
params.fieldsearch = this.getFieldsForSearch();
|
|
|
|
|
return tools.executeQueryTable(this, idapp, params);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports.getImportaMacroByCode = function (idapp, code) {
|
|
|
|
|
return ImportaMacro.findAllIdApp(idapp, code);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports.getImportaMacroById = async function (id) {
|
|
|
|
|
const arrris = await ImportaMacro.findAllIdApp('', '', id);
|
|
|
|
|
return arrris && arrris.length > 0 ? arrris[0] : null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports.findAllIdApp = async function (idapp) {
|
|
|
|
|
const ImportaMacro = this;
|
|
|
|
|
|
|
|
|
|
const myfind = { idapp, deleted: false };
|
|
|
|
|
|
2025-03-03 00:46:08 +01:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
return await ImportaMacro.find(myfind).lean();
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error("Errore in ImportaMacro:", err);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-29 14:58:45 +02:00
|
|
|
};
|