From ab3a31d4fb64341c23a06ec20c413c8f974de136 Mon Sep 17 00:00:00 2001 From: Surya Paolo Date: Sat, 16 Dec 2023 00:51:03 +0100 Subject: [PATCH] Scontistica- Parte 1 --- src/server/models/order.js | 28 ++++++++++++++ src/server/models/product.js | 32 +++++++++++++++- src/server/models/scontistica.js | 59 ++++++++++++++++++++++++++++++ src/server/router/index_router.js | 4 ++ src/server/telegram/telegrambot.js | 4 +- src/server/tools/general.js | 1 + src/server/tools/globalTables.js | 3 ++ 7 files changed, 127 insertions(+), 4 deletions(-) create mode 100755 src/server/models/scontistica.js diff --git a/src/server/models/order.js b/src/server/models/order.js index 3cd0f82..b4d9c75 100755 --- a/src/server/models/order.js +++ b/src/server/models/order.js @@ -157,6 +157,20 @@ module.exports.findAllIdApp = async function (idapp) { as: 'provider' } }, + { + $lookup: { + from: 'scontisticas', + localField: 'idScontisticas', + foreignField: '_id', + as: 'scontistica' + } + }, + { + $unwind: { + path: '$scontistica', + preserveNullAndEmptyArrays: true, + }, + }, { $unwind: '$product' }, { $unwind: '$producer' }, { $unwind: '$provider' }, @@ -244,6 +258,20 @@ module.exports.getTotalOrderById = async function (id) { as: 'provider' } }, + { + $lookup: { + from: 'scontisticas', + localField: 'idScontisticas', + foreignField: '_id', + as: 'scontistica' + } + }, + { + $unwind: { + path: '$scontistica', + preserveNullAndEmptyArrays: true, + }, + }, { $unwind: '$product' }, { $unwind: '$producer' }, { $unwind: '$storehouse' }, diff --git a/src/server/models/product.js b/src/server/models/product.js index 64b22df..ccf7aca 100755 --- a/src/server/models/product.js +++ b/src/server/models/product.js @@ -6,6 +6,7 @@ const tools = require('../tools/general'); const Producer = require('../models/producer'); const Storehouse = require('../models/storehouse'); const Provider = require('../models/provider'); +const Scontistica = require('../models/scontistica'); const shared_consts = require('../tools/shared_nodejs'); @@ -33,6 +34,9 @@ const productSchema = new Schema({ idStorehouses: [ { type: Schema.Types.ObjectId, ref: 'Storehouse' } ], + idScontisticas: [ + { type: Schema.Types.ObjectId, ref: 'Scontistica' } + ], idProvider: { type: Schema.Types.ObjectId, ref: 'Provider' }, code: { type: String, @@ -214,7 +218,12 @@ module.exports.findAllIdApp = async function (idapp, code, id) { as: 'producer' } }, - { $unwind: '$producer' }, + { + $unwind: { + path: '$producer', + preserveNullAndEmptyArrays: true, + }, + }, { $lookup: { from: 'providers', @@ -223,7 +232,26 @@ module.exports.findAllIdApp = async function (idapp, code, id) { as: 'provider' } }, - { $unwind: '$provider' }, + { + $unwind: { + path: '$provider', + preserveNullAndEmptyArrays: true, + }, + }, + { + $lookup: { + from: 'scontisticas', + localField: 'idScontisticas', + foreignField: '_id', + as: 'scontistica' + } + }, + { + $unwind: { + path: '$scontistica', + preserveNullAndEmptyArrays: true, + }, + }, { $lookup: { from: 'storehouses', diff --git a/src/server/models/scontistica.js b/src/server/models/scontistica.js new file mode 100755 index 0000000..2a3a74a --- /dev/null +++ b/src/server/models/scontistica.js @@ -0,0 +1,59 @@ +mongoose = require('mongoose').set('debug', false) +const Schema = mongoose.Schema; + +const tools = require('../tools/general'); + +mongoose.Promise = global.Promise; +mongoose.level = "F"; + + +// Resolving error Unknown modifier: $pushAll +mongoose.plugin(schema => { + schema.options.usePushEach = true +}); + +const scontisticaSchema = new Schema({ + idapp: { + type: String, + }, + code: { + type: String, + }, + description: { + type: String, + }, + qta: { + type: Number, + }, + perc_sconto: { + type: Number, + }, + price: { + type: Number, + }, + comulativo: { + type: Boolean, + default: false, + }, +}); + +var Scontistica = module.exports = mongoose.model('Scontistica', scontisticaSchema); + +module.exports.getFieldsForSearch = function () { + return [{ field: 'name', type: tools.FieldType.string }] +}; + +module.exports.executeQueryTable = function (idapp, params) { + params.fieldsearch = this.getFieldsForSearch(); + return tools.executeQueryTable(this, idapp, params); +}; + +module.exports.findAllIdApp = async function (idapp) { + const myfind = { idapp }; + + return await Scontistica.find(myfind); +}; + +module.exports.createIndexes((err) => { + if (err) throw err; +}); diff --git a/src/server/router/index_router.js b/src/server/router/index_router.js index 85db907..f8fd6ce 100755 --- a/src/server/router/index_router.js +++ b/src/server/router/index_router.js @@ -66,6 +66,7 @@ const Cart = require('../models/cart'); const OrdersCart = require('../models/orderscart'); const Storehouse = require('../models/storehouse'); const Provider = require('../models/provider'); +const Scontistica = require('../models/scontistica'); const Department = require('../models/department'); const { Category } = require('../models/category'); const Group = require('../models/group'); @@ -1433,6 +1434,7 @@ function load(req, res, version) { let workers = User.getusersWorkersList(idapp); let storehouses = Storehouse.findAllIdApp(idapp); let providers = Provider.findAllIdApp(idapp); + let scontistica = Scontistica.findAllIdApp(idapp); let departments = Department.findAllIdApp(idapp); let categories = Category.findAllIdApp(idapp); @@ -1520,6 +1522,7 @@ function load(req, res, version) { myelems, // 38 categories, // 39 providers, + scontistica, ]).then((arrdata) => { // console.table(arrdata); let myuser = req.user; @@ -1603,6 +1606,7 @@ function load(req, res, version) { myelems: arrdata[38], categories: arrdata[39], providers: arrdata[40], + scontistica: arrdata[41], }); const prova = 1; diff --git a/src/server/telegram/telegrambot.js b/src/server/telegram/telegrambot.js index cf48f94..2b2ecf3 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.FIOREDELLAVITA]; +//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/general.js b/src/server/tools/general.js index 30668cf..51897ef 100755 --- a/src/server/tools/general.js +++ b/src/server/tools/general.js @@ -416,6 +416,7 @@ module.exports = { CNM: '10', RISO: '13', FIOREDELLAVITA: '15', + PIUCHEBUONO: '17', HELP_CHAT: '', TYPECONF_ZOOM: 'zoom', diff --git a/src/server/tools/globalTables.js b/src/server/tools/globalTables.js index ee9ffc6..98674f1 100755 --- a/src/server/tools/globalTables.js +++ b/src/server/tools/globalTables.js @@ -61,6 +61,7 @@ const Cart = require('../models/cart'); const OrdersCart = require('../models/orderscart'); const Storehouse = require('../models/storehouse'); const Provider = require('../models/provider'); +const Scontistica = require('../models/scontistica'); const Department = require('../models/department'); const { Category } = require('../models/category'); const ShareWithUs = require('../models/sharewithus'); @@ -107,6 +108,8 @@ module.exports = { mytable = Storehouse; else if (tablename === 'providers') mytable = Provider; + else if (tablename === 'scontisticas') + mytable = Scontistica; else if (tablename === 'departments') mytable = Department; else if (tablename === 'categorys')