From 0c2a8ecef54070420c045cb36876d6045bc23e9d Mon Sep 17 00:00:00 2001 From: Surya Paolo Date: Tue, 30 Jan 2024 14:00:37 +0100 Subject: [PATCH] AITools prime cose --- .DS_Store | Bin 10244 -> 10244 bytes .env.development | 2 +- src/server/models/catai.js | 61 ++++++++++++++++++++ src/server/models/inventariogm.js | 59 +++++++++++++++++++ src/server/models/queryai.js | 86 ++++++++++++++++++++++++++++ src/server/models/site.js | 1 + src/server/populate/catais.js | 12 ++++ src/server/populate/queryais.js | 65 +++++++++++++++++++++ src/server/router/admin_router.js | 18 ++++++ src/server/router/aitools_router.js | 46 +++++++++++++++ src/server/router/index_router.js | 4 ++ src/server/server.js | 2 + src/server/telegram/telegrambot.js | 4 +- src/server/tools/globalTables.js | 6 ++ src/server/tools/shared_nodejs.js | 10 +++- 15 files changed, 372 insertions(+), 4 deletions(-) create mode 100755 src/server/models/catai.js create mode 100755 src/server/models/inventariogm.js create mode 100755 src/server/models/queryai.js create mode 100644 src/server/populate/catais.js create mode 100644 src/server/populate/queryais.js create mode 100755 src/server/router/aitools_router.js diff --git a/.DS_Store b/.DS_Store index 9c1a8bb970c04f359b20dc168404b755cfebf365..b0aa06d719c5a965e62612f79808beb075e54a94 100644 GIT binary patch delta 68 zcmZn(XbIR*F2%Tga)nf(ns{}!sj;b!fk&%vqxv_a|EhmSlvc7dte0EN5 YUVi6f0cm;0uFVG0*I72RDg0vx0L{-7qyPW_ delta 69 zcmZn(XbIR*F2%TGa)nf(x7Z7nB { + 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; diff --git a/src/server/models/inventariogm.js b/src/server/models/inventariogm.js new file mode 100755 index 0000000..5ea4dbd --- /dev/null +++ b/src/server/models/inventariogm.js @@ -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; + }); +}; \ No newline at end of file diff --git a/src/server/models/queryai.js b/src/server/models/queryai.js new file mode 100755 index 0000000..db38a7c --- /dev/null +++ b/src/server/models/queryai.js @@ -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 }; diff --git a/src/server/models/site.js b/src/server/models/site.js index bd6b9d5..80d42b6 100755 --- a/src/server/models/site.js +++ b/src/server/models/site.js @@ -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 }, diff --git a/src/server/populate/catais.js b/src/server/populate/catais.js new file mode 100644 index 0000000..c51906f --- /dev/null +++ b/src/server/populate/catais.js @@ -0,0 +1,12 @@ +module.exports = { + list: [ + { + _id: 1, + descr: 'Pubblicare', + }, + { + _id: 2, + descr: 'Matematica', + }, + ], +}; diff --git a/src/server/populate/queryais.js b/src/server/populate/queryais.js new file mode 100644 index 0000000..b65251e --- /dev/null +++ b/src/server/populate/queryais.js @@ -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}', + }, + ], +}; diff --git a/src/server/router/admin_router.js b/src/server/router/admin_router.js index 217c3d6..457ce09 100755 --- a/src/server/router/admin_router.js +++ b/src/server/router/admin_router.js @@ -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}]`); diff --git a/src/server/router/aitools_router.js b/src/server/router/aitools_router.js new file mode 100755 index 0000000..4830600 --- /dev/null +++ b/src/server/router/aitools_router.js @@ -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; diff --git a/src/server/router/index_router.js b/src/server/router/index_router.js index 403e444..8fbdf69 100755 --- a/src/server/router/index_router.js +++ b/src/server/router/index_router.js @@ -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; diff --git a/src/server/server.js b/src/server/server.js index ae87210..1fc8539 100755 --- a/src/server/server.js +++ b/src/server/server.js @@ -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) { diff --git a/src/server/telegram/telegrambot.js b/src/server/telegram/telegrambot.js index 89561b5..6dd0687 100755 --- a/src/server/telegram/telegrambot.js +++ b/src/server/telegram/telegrambot.js @@ -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]; diff --git a/src/server/tools/globalTables.js b/src/server/tools/globalTables.js index 142863f..74fd6a8 100755 --- a/src/server/tools/globalTables.js +++ b/src/server/tools/globalTables.js @@ -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') diff --git a/src/server/tools/shared_nodejs.js b/src/server/tools/shared_nodejs.js index 81285fa..0db9edd 100755 --- a/src/server/tools/shared_nodejs.js +++ b/src/server/tools/shared_nodejs.js @@ -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, + }, + };