Abilitazione del BOT

This commit is contained in:
Surya Paolo
2023-12-17 16:20:44 +01:00
parent 4290895a97
commit c71f4af370
8 changed files with 221 additions and 13 deletions

View File

@@ -50,11 +50,11 @@ const BotSchema = new Schema({
},
});
BotSchema.statics.getFieldsForSearch = function() {
BotSchema.statics.getFieldsForSearch = function () {
return [{ field: 'label', type: tools.FieldType.string }]
};
BotSchema.statics.executeQueryTable = function(idapp, params) {
BotSchema.statics.executeQueryTable = function (idapp, params) {
params.fieldsearch = this.getFieldsForSearch();
return tools.executeQueryTable(this, idapp, params);
};
@@ -66,12 +66,141 @@ BotSchema.statics.DuplicateAllRecords = async function (idapporig, idappdest) {
};
BotSchema.statics.findAllIdApp = async function(idapp) {
BotSchema.statics.generateBotMenuRecords = async function (idapp) {
try {
let arrrec = [
{
"page": 1,
"index": 1,
"riga": 1,
"active": true,
"label": "Vai al Sito",
"type": 3,
"value": "{host}",
"visibility": 0,
idapp,
"lang": "it",
"main": true
},
{
"page": 1,
"index": 1,
"riga": 2,
"active": true,
"label": "Il mio Profilo",
"type": 3,
"value": "{host}/my/{username}",
"visibility": 1,
idapp,
"lang": "it",
"main": true
},
{
"page": 1,
"index": 1,
"riga": 3,
"active": true,
"label": "Link da Condividere",
"type": 2,
"value": "{host}/registrati/{username}",
"visibility": 1,
idapp,
"lang": "it",
"main": true,
},
{
"page": 1,
"index": 2,
"riga": 1,
"active": true,
"label": "🔮 Help",
"type": 4,
"value": "",
"visibility": 0,
idapp,
"lang": "it",
"main": true,
},
{
"page": 1,
"index": 1,
"riga": 3,
"active": true,
"label": "💁‍♀️ Admin",
"type": 4,
"value": "",
"visibility": 5,
idapp,
"lang": "it",
"main": true
},
{
"page": 1,
"index": 2,
"riga": 2,
"active": true,
"label": "Imposta Foto Profilo",
"type": 4,
"value": "🖼 SetPicProfile",
"visibility": 1,
idapp,
"lang": "it",
"main": true
},
{
"page": 1,
"index": 2,
"riga": 3,
"active": true,
"label": "🛠 Strumenti",
"type": 1,
"value": "2",
"visibility": 1,
idapp,
"lang": "it",
"main": true,
},
{
"page": 2,
"index": 1,
"riga": 1,
"active": true,
"label": "🔑 Cambio Password",
"type": 4,
"value": "🔑 SetResetPwd",
"visibility": 1,
idapp,
"lang": "it",
},
{
"page": 2,
"index": 1,
"riga": 2,
"active": true,
"label": "👉🏻 Indietro",
"type": 1,
"value": "1",
"visibility": 1,
idapp,
"lang": "it",
}];
const ris = await MyBot.insertMany(arrrec);
return ris;
} catch (e) {
console.error('Err:', e);
}
}
BotSchema.statics.findAllIdApp = async function (idapp) {
const Bot = this;
const myfind = {idapp};
const myfind = { idapp };
return await Bot.find(myfind).sort({page: 1, lang: 1, riga: 1, index: 1}).lean();
return await Bot.find(myfind).sort({ page: 1, lang: 1, riga: 1, index: 1 }).lean();
};
const MyBot = mongoose.model('Bot', BotSchema);
@@ -80,4 +209,4 @@ MyBot.createIndexes((err) => {
if (err) throw err;
});
module.exports = {MyBot};
module.exports = { MyBot };

View File

@@ -262,6 +262,7 @@ module.exports.getOrdersCartByUserId = async function (uid, idapp, numorder) {
return order;
});
console.log('*** Num myorderscart ', myorderscart.length);
return myorderscart
} catch (e) {
console.error('Err:', e);

View File

@@ -64,6 +64,12 @@ const SiteSchema = new Schema({
telegram_key_test: {
type: String,
},
load_process_telegram: {
type: Boolean,
},
load_process_telegram_test: {
type: String,
},
teleg_cfg: {
type: String,
},

View File

@@ -30,6 +30,7 @@ const i18n = require('i18n');
const shared_consts = require('../tools/shared_nodejs');
mongoose.Promise = global.Promise;
mongoose.level = 'F';
@@ -5387,6 +5388,8 @@ UserSchema.statics.addNewSite = async function (idappPass, body) {
};
if (arrSite && arrSite.length === 1 && numutenti < 2) {
const MyTelegramBot = require('../telegram/telegrambot');
// Nessun Sito Installato e Nessun Utente installato !
let myuser = new User();
myuser._id = new ObjectID();
@@ -5403,11 +5406,19 @@ UserSchema.statics.addNewSite = async function (idappPass, body) {
myuser.perm = '3';
myuser.profile.special_req = true;
myuser.profile.nationality = 'IT';
myuser.profile.manage_telegram = true;
myuser.profile.teleg_id = MyTelegramBot.ADMIN_IDTELEGRAM_SERVER;
myuser.profile.username_telegram = MyTelegramBot.ADMIN_USERNAME_TELEGRAM;
myuser.lasttimeonline = new Date();
myuser.date_reg = new Date();
await myuser.save();
const { MyBot } = require('../models/bot');
// Genera il Menu del BOT:
await MyBot.generateBotMenuRecords(idapp);
return { code: server_constants.RIS_CODE_OK, idapp };
}
}