From 000e900f48fb83e7b8d73cc5932935a7a15cdf21 Mon Sep 17 00:00:00 2001 From: Surya Paolo Date: Thu, 21 Dec 2023 02:23:52 +0100 Subject: [PATCH] ++GasOrdini --- src/server/models/gasordine.js | 72 +++++++++++++++++++++++++++++++ src/server/models/order.js | 29 +++++++++++++ src/server/models/orderscart.js | 19 ++++++++ src/server/models/product.js | 1 + src/server/router/index_router.js | 4 ++ src/server/tools/globalTables.js | 3 ++ 6 files changed, 128 insertions(+) create mode 100755 src/server/models/gasordine.js diff --git a/src/server/models/gasordine.js b/src/server/models/gasordine.js new file mode 100755 index 0000000..3bdd0d8 --- /dev/null +++ b/src/server/models/gasordine.js @@ -0,0 +1,72 @@ + 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 gasordineSchema = new Schema({ + active: { + type: Boolean, + }, + idapp: { + type: String, + }, + name: { + type: String, + }, + description: { + type: String, + }, + referente: { + type: String, + }, + city: { + type: String, + }, + img: { + type: String, + }, + dataora_chiusura: { + type: Date, + }, + dataora_ritiro: { + type: Date, + }, +}); + +var Gasordine = module.exports = mongoose.model('Gasordine', gasordineSchema); + +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.findAllIdApp = async function (idapp) { + const myfind = { idapp }; + + return await Gasordine.find(myfind); +}; + + +module.exports.getGasordineByID = function (id, callback) { + Gasordine.findById(id, callback); +} + +module.exports.createIndexes((err) => { + if (err) throw err; +}); diff --git a/src/server/models/order.js b/src/server/models/order.js index 409a056..7738984 100755 --- a/src/server/models/order.js +++ b/src/server/models/order.js @@ -28,6 +28,7 @@ const orderSchema = new Schema({ idStorehouse: { type: Schema.Types.ObjectId, ref: 'StoreHouse' }, idScontisticas: [{ type: Schema.Types.ObjectId, ref: 'Scontistica' }], idProvider: { type: Schema.Types.ObjectId, ref: 'Provider' }, + idGasordine: { type: Schema.Types.ObjectId, ref: 'Gasordine' }, price: { type: Number, default: 0, @@ -169,6 +170,14 @@ module.exports.findAllIdApp = async function (idapp) { as: 'provider' } }, + { + $lookup: { + from: 'gasordines', + localField: 'idGasordine', + foreignField: '_id', + as: 'gasordine' + } + }, { $lookup: { from: 'scontisticas', @@ -194,6 +203,12 @@ module.exports.findAllIdApp = async function (idapp) { path: '$provider', preserveNullAndEmptyArrays: true, }, + }, + { + $unwind: { + path: '$gasordine', + preserveNullAndEmptyArrays: true, + }, } ]; @@ -346,6 +361,14 @@ module.exports.getTotalOrderById = async function (id) { as: 'provider' } }, + { + $lookup: { + from: 'gasordines', + localField: 'idGasordine', + foreignField: '_id', + as: 'gasordine' + } + }, { $lookup: { from: 'scontisticas', @@ -378,6 +401,12 @@ module.exports.getTotalOrderById = async function (id) { preserveNullAndEmptyArrays: true, }, }, + { + $unwind: { + path: '$gasordine', + preserveNullAndEmptyArrays: true, + }, + }, { $lookup: { from: 'orders', diff --git a/src/server/models/orderscart.js b/src/server/models/orderscart.js index 1da041d..f4258e7 100755 --- a/src/server/models/orderscart.js +++ b/src/server/models/orderscart.js @@ -8,6 +8,7 @@ var { User } = require('../models/user'); const Storehouse = require('../models/storehouse'); const Provider = require('../models/provider'); +const Gasordine = require('../models/gasordine'); const Product = require('../models/product'); const tools = require('../tools/general'); @@ -202,6 +203,13 @@ module.exports.getOLDOrdersCartByQuery = async function (query) { model: 'Provider' }, }) + .populate({ + path: 'items.order', + populate: { + path: 'idGasordine', + model: 'Gasordine' + }, + }) .populate({ path: 'items.order', populate: { @@ -237,6 +245,8 @@ module.exports.getOLDOrdersCartByQuery = async function (query) { item.order.idStorehouse = item.order.storehouse ? item.order.storehouse._id : ''; item.order.provider = item.order.idProvider; item.order.idProvider = item.order.provider ? item.order.provider._id : ''; + item.order.gasordine = item.order.idGasordine; + item.order.idGasordine = item.order.gasordine ? item.order.gasordine._id : ''; item.order.scontisticas = item.order.scontisticas; item.order.idScontisticas = item.order.idScontisticas ? item.order.idScontisticas._id : ''; } catch (e) { @@ -278,6 +288,13 @@ module.exports.getOrdersCartByQuery = async function (query) { model: 'Provider' }, }) + .populate({ + path: 'items.order', + populate: { + path: 'idGasordine', + model: 'Gasordine' + }, + }) .populate({ path: 'items.order', populate: { @@ -313,6 +330,8 @@ module.exports.getOrdersCartByQuery = async function (query) { item.order.idStorehouse = item.order.storehouse ? item.order.storehouse._id : ''; item.order.provider = item.order.idProvider; item.order.idProvider = item.order.provider ? item.order.provider._id : ''; + item.order.gasordine = item.order.idGasordine; + item.order.idGasordine = item.order.gasordine ? item.order.gasordine._id : ''; item.order.scontisticas = item.order.scontisticas; item.order.idScontisticas = item.order.idScontisticas ? item.order.idScontisticas._id : ''; } catch (e) { diff --git a/src/server/models/product.js b/src/server/models/product.js index b5371a2..6e8336d 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 Gasordine = require('../models/gasordine'); const Scontistica = require('../models/scontistica'); const shared_consts = require('../tools/shared_nodejs'); diff --git a/src/server/router/index_router.js b/src/server/router/index_router.js index 8d1f536..7e6bf39 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 Gasordine = require('../models/gasordine'); const Scontistica = require('../models/scontistica'); const Department = require('../models/department'); const { Category } = require('../models/category'); @@ -1434,6 +1435,7 @@ function load(req, res, version) { let workers = User.getusersWorkersList(idapp); let storehouses = Storehouse.findAllIdApp(idapp); let providers = Provider.findAllIdApp(idapp); + let gasordines = Gasordine.findAllIdApp(idapp); let scontisticas = Scontistica.findAllIdApp(idapp); let departments = Department.findAllIdApp(idapp); let categories = Category.findAllIdApp(idapp); @@ -1523,6 +1525,7 @@ function load(req, res, version) { categories, // 39 providers, scontisticas, + gasordines, ]).then((arrdata) => { // console.table(arrdata); let myuser = req.user; @@ -1607,6 +1610,7 @@ function load(req, res, version) { categories: arrdata[39], providers: arrdata[40], scontisticas: arrdata[41], + gasordines: arrdata[42], }); const prova = 1; diff --git a/src/server/tools/globalTables.js b/src/server/tools/globalTables.js index 98674f1..cfa764e 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 Gasordine = require('../models/gasordine'); const Scontistica = require('../models/scontistica'); const Department = require('../models/department'); const { Category } = require('../models/category'); @@ -108,6 +109,8 @@ module.exports = { mytable = Storehouse; else if (tablename === 'providers') mytable = Provider; + else if (tablename === 'gasordines') + mytable = Gasordine; else if (tablename === 'scontisticas') mytable = Scontistica; else if (tablename === 'departments')