AITools prime cose

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

BIN
.DS_Store vendored

Binary file not shown.

View File

@@ -1,4 +1,4 @@
DATABASE=test_PiuCheBuono
DATABASE=test_FreePlanet
UDB=paofreeplanet
PDB=mypassword@1A
SEND_EMAIL=0

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 },

View File

@@ -0,0 +1,12 @@
module.exports = {
list: [
{
_id: 1,
descr: 'Pubblicare',
},
{
_id: 2,
descr: 'Matematica',
},
],
};

View File

@@ -0,0 +1,65 @@
const { ObjectID } = require('mongodb');
module.exports = {
list: [
{
_id: ObjectID("115a353c002c298f44900010"),
idapp: 18,
ask: [
{ descr: 'Scegli quanti punti', value: 'numpunti' },
],
descr: 'Scrivimi {numpunti} punti per {testo}',
query: 'Scrivimi {numpunti} punti per {testo}',
output_type: 'ELENCO',
},
{
_id: ObjectID("115a353c002c298f44900020"),
idapp: 18,
ask: [
{ descr: 'Numeri di righe', value: 'numrighe', min: 1, max: 100 },
],
descr: 'Riassumi ogni punto dell\'elenco in {numrighe} righe',
query: 'Riassumi ogni punto dell\'elenco in massimo {numrighe} righe',
output_type: 'ELENCO',
},
{
_id: ObjectID("115a353c002c829f44900030"),
idapp: 18,
ask: [],
descr: 'Estrai le cose importanti dell\'articolo',
query: 'Quali sono le cose importanti che sono state dette in questo articolo? {testo}',
output_type: '',
},
{
_id: ObjectID("115a353c002c8298f4900040"),
idapp: 18,
ask: [],
descr: 'Dammi degli Emoji',
query: 'Dammi 10 ideee per degli Emoji che puoi utilizzare per la frase {testo}',
buttons: ['NEXT_10'],
output_type: '',
},
{
_id: ObjectID("115a353c002c298f44900050"),
idapp: 18,
ask: [
{ descr: 'Scegli quanti Punti', value: 'numpunti' },
],
descr: '{numpunti} punti per un webinar su come utilizzare ChatGPT',
query: 'Scrivimi {numpunti} punti per un webinar su come utilizzare ChatGPT nel proprio lavoro',
output_type: 'ELENCO',
},
{
_id: ObjectID("115a353c002c898f44900060"),
idapp: 18,
descr: 'Scaletta punti',
query: 'Mi fai una scaletta di punti che potrei affrontare durante il webinar.',
},
{
_id: ObjectID("115a353c002c829f44900070"),
idapp: 18,
descr: 'Elenchi Puntati',
query: 'Mi trasformi questo testo in elenchi puntati? {testo}',
},
],
};

View File

@@ -9,6 +9,7 @@ const tools = require('../tools/general');
const { City } = require('../models/city');
const Product = require('../models/product');
const Inventariogm = require('../models/inventariogm');
const ProductInfo = require('../models/productInfo');
const CatProd = require('../models/catprod');
const SubCatProd = require('../models/subcatprod');
@@ -50,6 +51,23 @@ router.post('/import', authenticate, async (req, res) => {
return await City.insertMany(liste.Comuni).then((ris) => {
return res.status(200).send(true);
});
} else if (cmd === shared_consts.Cmd.INVENTARIO) {
let dataObjects = JSON.parse(`[${data.arrdata}]`);
let updated = 0;
let imported = 0;
let errors = 0;
for (const recinv of dataObjects) {
let isnuovo = false
let setta = false
let inventario = recinv;
inventario.idapp = idapp;
let risrec = await Inventariogm.findOneAndUpdate(queryprod, { $set: inventario }, { new: true, upsert: true });
}
} else if (cmd === shared_consts.Cmd.PRODUCTS) {
let dataObjects = JSON.parse(`[${data.arrdata}]`);

View File

@@ -0,0 +1,46 @@
const shared_consts = require('../tools/shared_nodejs');
const express = require('express');
const router = express.Router();
const tools = require('../tools/general');
var server_constants = require('../tools/server_constants');
var { authenticate, authenticate_noerror, auth_default } = require('../middleware/authenticate');
var mongoose = require('mongoose').set('debug', false);
const Subscription = require('../models/subscribers');
const _ = require('lodash');
const { QueryAI } = require('../models/queryai');
var { User } = require('../models/user');
const { Reaction } = require('../models/reaction');
const globalTables = require('../tools/globalTables');
const { ObjectID } = require('mongodb');
router.post('/getlist', authenticate_noerror, async function (req, res, next) {
try {
let idapp = req.body.idapp;
let queryAIList = await QueryAI.findAllIdApp(idapp);
return res.send({
code: server_constants.RIS_CODE_OK,
queryAIList
});
} catch (e) {
console.error('/getlist', e);
}
return null;
});
module.exports = router;

View File

@@ -67,6 +67,7 @@ const OrdersCart = require('../models/orderscart');
const Storehouse = require('../models/storehouse');
const Provider = require('../models/provider');
const CatProd = require('../models/catprod');
const CatAI = require('../models/catai');
const SubCatProd = require('../models/subcatprod');
const Gasordine = require('../models/gasordine');
const Product = require('../models/product');
@@ -1444,6 +1445,7 @@ function load(req, res, version) {
let catprods_gas = Product.getArrCatProds(idapp, shared_consts.PROD.GAS);
let subcatprods = SubCatProd.findAllIdApp(idapp);
let gasordines = Gasordine.findAllIdApp(idapp);
let catAI = CatAI.findAllIdApp(idapp);
let ismanager = false;
try {
if (req.user)
@@ -1548,6 +1550,7 @@ function load(req, res, version) {
catprods,
subcatprods,
catprods_gas,
catAI,
]).then((arrdata) => {
// console.table(arrdata);
let myuser = req.user;
@@ -1638,6 +1641,7 @@ function load(req, res, version) {
catprods: arrdata[45],
subcatprods: arrdata[46],
catprods_gas: arrdata[47],
catAI: arrdata[48],
});
const prova = 1;

View File

@@ -129,6 +129,7 @@ myLoad().then(ris => {
const myskills_router = require('./router/myskills_router');
const mygoods_router = require('./router/mygoods_router');
const mygen_router = require('./router/mygen_router');
const aitools_router = require('./router/aitools_router');
const { MyEvent } = require('./models/myevent');
@@ -196,6 +197,7 @@ myLoad().then(ris => {
app.use('/myskills', myskills_router);
app.use('/mygoods', mygoods_router);
app.use('/mygen', mygen_router);
app.use('/aitools', aitools_router);
// catch 404 and forward to error handler
// app.use(function (req, res, next) {

View File

@@ -3,8 +3,8 @@ const tools = require('../tools/general');
const appTelegram = [tools.FREEPLANET, tools.RISO];
const appTelegram_TEST = [tools.FREEPLANET, tools.RISO];
//const appTelegram_DEVELOP = [tools.RISO];
const appTelegram_DEVELOP = [tools.PIUCHEBUONO];
const appTelegram_DEVELOP = [tools.RISO];
//const appTelegram_DEVELOP = [tools.PIUCHEBUONO];
const appTelegramFinti = ['2', tools.CNM];
const appTelegramDest = [tools.FREEPLANET, tools.FREEPLANET];

View File

@@ -66,6 +66,8 @@ const Gasordine = require('../models/gasordine');
const Scontistica = require('../models/scontistica');
const Department = require('../models/department');
const CatProd = require('../models/catprod');
const CatAI = require('../models/catai');
const QueryAI = require('../models/queryai');
const SubCatProd = require('../models/subcatprod');
const { Category } = require('../models/category');
const ShareWithUs = require('../models/sharewithus');
@@ -124,6 +126,10 @@ module.exports = {
mytable = Category;
else if (tablename === 'catprods')
mytable = CatProd;
else if (tablename === 'catais')
mytable = CatAI;
else if (tablename === 'queryais')
mytable = QueryAI;
else if (tablename === 'subcatprods')
mytable = SubCatProd;
else if (tablename === 'sharewithus')

View File

@@ -246,6 +246,8 @@ module.exports = {
{ table: 'sectors', key: 'descr' },
{ table: 'skills', key: 'descr' },
{ table: 'statusSkills', key: 'descr' },
// { table: 'catais', key: 'descr' },
// { table: 'queryais', key: 'descr' },
],
@@ -291,6 +293,7 @@ module.exports = {
CAT_NO_SPAZI: 5,
CAT_GOODS_TXT: 10,
PRODUCTS: 20,
INVENTARIO: 30,
},
WalletFinalStatusType: {
@@ -443,7 +446,7 @@ module.exports = {
RECEIVED: { label: 'Ricevuti', value: 7, icon: '', color: 'text-blue' }, //RECEIVED
COMPLETATI: { label: 'Completati', value: 8, icon: 'fas fa-check', color: 'text-blue' }, //COMPLETED
CANCELLATI: { label: 'Cancellati', value: 10, icon: 'delete', color: 'text-red' }, //CANCELED
PREPARED: { label: 'Preparati', value: 15, icon: 'fas fa-archive', color: 'text-blue' },
PREPARED: { label: 'Preparati', value: 15, icon: 'fas fa-archive', color: 'text-blue' },
},
OrderStatusStr: [
@@ -947,4 +950,9 @@ module.exports = {
return (trovatorec) ? trovatorec.label : ''
},
ButtonCodeAction: {
NONE: 0,
NEXT_10: 1,
},
};