++GasOrdini

This commit is contained in:
Surya Paolo
2023-12-21 02:23:52 +01:00
parent 2ab4bd4e2a
commit 000e900f48
6 changed files with 128 additions and 0 deletions

72
src/server/models/gasordine.js Executable file
View File

@@ -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;
});

View File

@@ -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',

View File

@@ -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) {

View File

@@ -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');

View File

@@ -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;

View File

@@ -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')