AITools prime cose

This commit is contained in:
Surya Paolo
2024-01-30 14:00:37 +01:00
parent aeabf96efe
commit 0c2a8ecef5
15 changed files with 372 additions and 4 deletions

61
src/server/models/catai.js Executable file
View File

@@ -0,0 +1,61 @@
const mongoose = require('mongoose').set('debug', false)
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
mongoose.level = "F";
const tools = require('../tools/general');
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
schema.options.usePushEach = true
});
const CatAISchema = new Schema({
_id: {
type: Number,
},
name: {
type: String,
},
img: {
type: String,
},
icon: {
type: String,
},
color: {
type: String,
},
});
CatAISchema.statics.getAllCategories = function (callback) {
CatAI.find(callback)
}
CatAISchema.statics.getCatAIById = function (id, callback) {
CatAI.findById(id, callback);
}
CatAISchema.statics.getFieldsForSearch = function () {
return [{ field: 'name', type: tools.FieldType.string }]
};
CatAISchema.statics.executeQueryTable = function (idapp, params) {
return tools.executeQueryTable(this, idapp, params);
};
CatAISchema.statics.findAllIdApp = async function (idapp) {
const myfind = {};
return await CatAI.find(myfind).sort({ name: 1 });
};
const CatAI = mongoose.model('CatAI', CatAISchema);
CatAI.createIndexes((err) => {
if (err) throw err;
});
module.exports = CatAI;

View File

@@ -0,0 +1,59 @@
mongoose = require('mongoose').set('debug', false)
const Schema = mongoose.Schema;
const tools = require('../tools/general');
const shared_consts = require('../tools/shared_nodejs');
const { ObjectID } = require('mongodb');
mongoose.Promise = global.Promise;
mongoose.level = "F";
// A1P
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
schema.options.usePushEach = true
});
const inventariogmSchema = new Schema({
idapp: {
type: String,
},
});
var Inventariogm = module.exports = mongoose.model('Inventariogm', inventariogmSchema);
inventariogmSchema.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.getInventariogmByCode = function (idapp, code) {
return Inventariogm.findAllIdApp(idapp, code);
}
module.exports.getInventariogmById = async function (id) {
const arrris = await Inventariogm.findAllIdApp('', '', id);
return arrris && arrris.length > 0 ? arrris[0] : null
}
module.exports.findAllIdApp = async function (idapp) {
const Inventariogm = this;
const myfind = { idapp, deleted: false };
return await Inventariogm.find(myfind, (err, arrrec) => {
return arrrec;
});
};

86
src/server/models/queryai.js Executable file
View File

@@ -0,0 +1,86 @@
const mongoose = require('mongoose').set('debug', false)
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
mongoose.level = "F";
const tools = require('../tools/general');
// const CatAI = require('./catai');
const { ObjectID } = require('mongodb');
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
schema.options.usePushEach = true
});
const QueryAISchema = new Schema({
idapp: {
type: String,
},
descr: {
type: String,
},
catAI: { type: Schema.Types.ObjectId, ref: 'CatAI' },
query: {
type: String,
},
ask: [
{
descr: {
type: String,
},
value: {
type: Number,
},
}
],
buttons: [
{
type: String, //ButtonCodeAction
},
],
output_type: {
type: String,
},
icon: {
type: String,
},
img: {
type: String,
},
});
QueryAISchema.statics.findAllIdApp = async function (idapp) {
const QueryAI = this;
const query = [
{ $sort: { descr: 1 } }
];
return await QueryAI
.aggregate(query)
.then((arrrec) => {
return arrrec
})
};
QueryAISchema.statics.getFieldsForSearch = function () {
return [{ field: 'descr', type: tools.FieldType.string }]
};
QueryAISchema.statics.executeQueryTable = function (idapp, params) {
params.fieldsearch = this.getFieldsForSearch();
return tools.executeQueryTable(this, 0, params);
};
const QueryAI = mongoose.model('QueryAI', QueryAISchema);
QueryAI.createIndexes((err) => {
if (err) throw err;
});
module.exports = { QueryAI };

View File

@@ -132,6 +132,7 @@ const SiteSchema = new Schema({
showConnected: { type: Boolean, default: false },
bookingEvents: { type: Boolean, default: false },
enableEcommerce: { type: Boolean, default: false },
enableAI: { type: Boolean, default: false },
enableGroups: { type: Boolean, default: false },
enableCircuits: { type: Boolean, default: false },
enableProj: { type: Boolean, default: false },