Compare commits
No commits in common. "82d47e08a2033d9482ff0694671496def25a6655" and "36151f35bd874790368f82c68d4d595f21051c9a" have entirely different histories.
82d47e08a2
...
36151f35bd
@ -225,23 +225,16 @@ function nestGroups(groups, props, filter, idx = 0) {
|
|||||||
// Build a map of key -> groups for this property
|
// Build a map of key -> groups for this property
|
||||||
const keyToGroups = {};
|
const keyToGroups = {};
|
||||||
for (const group of groups) {
|
for (const group of groups) {
|
||||||
const val = group._id[prop];
|
const { key } = getKeyAndFilterVals(group._id[prop]);
|
||||||
const { key } = getKeyAndFilterVals(val);
|
if (!keyToGroups[key]) keyToGroups[key] = [];
|
||||||
if (!keyToGroups[key]) {
|
keyToGroups[key].push(group);
|
||||||
keyToGroups[key] = {
|
|
||||||
groups: [],
|
|
||||||
value: val,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
keyToGroups[key].groups.push(group);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = [];
|
let map = {};
|
||||||
|
|
||||||
if (filterPresent) {
|
if (filterPresent) {
|
||||||
const filterValue = filter[prop]?.toString?.() ?? filter[prop];
|
const filterValue = filter[prop]?.toString?.() ?? filter[prop];
|
||||||
for (const [key, data] of Object.entries(keyToGroups)) {
|
for (const [key, groupList] of Object.entries(keyToGroups)) {
|
||||||
const { groups: groupList, value } = data;
|
|
||||||
// Check if any group in this key matches the filter (by _id or name)
|
// Check if any group in this key matches the filter (by _id or name)
|
||||||
const matches = groupList.filter((group) => {
|
const matches = groupList.filter((group) => {
|
||||||
const { filterVals } = getKeyAndFilterVals(group._id[prop]);
|
const { filterVals } = getKeyAndFilterVals(group._id[prop]);
|
||||||
@ -249,36 +242,28 @@ function nestGroups(groups, props, filter, idx = 0) {
|
|||||||
console.log('filterValue', filterValue);
|
console.log('filterValue', filterValue);
|
||||||
return filterVals.some((val) => val?.toString() === filterValue);
|
return filterVals.some((val) => val?.toString() === filterValue);
|
||||||
});
|
});
|
||||||
|
|
||||||
let children = [];
|
|
||||||
if (matches.length > 0) {
|
if (matches.length > 0) {
|
||||||
if (idx === props.length - 1) {
|
if (idx === props.length - 1) {
|
||||||
// Last property in filter, return items
|
// Last property in filter, return items
|
||||||
|
let items = [];
|
||||||
for (const group of matches) {
|
for (const group of matches) {
|
||||||
children = children.concat(group.objects.map(expandObjectIds));
|
items = items.concat(group.objects.map(expandObjectIds));
|
||||||
|
}
|
||||||
|
map[key] = items;
|
||||||
|
} else {
|
||||||
|
map[key] = nestGroups(matches, props, filter, idx + 1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
children = nestGroups(matches, props, filter, idx + 1);
|
map[key] = {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result.push({
|
|
||||||
property: prop,
|
|
||||||
value: expandObjectIds(value),
|
|
||||||
children: children,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// No filter for this property, just show all keys at this level with empty objects
|
// No filter for this property, just show all keys at this level with empty objects
|
||||||
for (const [key, data] of Object.entries(keyToGroups)) {
|
for (const key of Object.keys(keyToGroups)) {
|
||||||
result.push({
|
map[key] = {};
|
||||||
property: prop,
|
|
||||||
value: expandObjectIds(data.value),
|
|
||||||
children: [],
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Group objects by multiple properties and return nested groupings
|
// Group objects by multiple properties and return nested groupings
|
||||||
|
|||||||
@ -15,14 +15,14 @@ import {
|
|||||||
// list of stock events
|
// list of stock events
|
||||||
router.get('/', isAuthenticated, (req, res) => {
|
router.get('/', isAuthenticated, (req, res) => {
|
||||||
const { page, limit, sort, order } = req.query;
|
const { page, limit, sort, order } = req.query;
|
||||||
const allowedFilters = ['owner._id', 'parent._id'];
|
const allowedFilters = ['owner_.id', 'parent._id'];
|
||||||
const filter = getFilter(req.query, allowedFilters);
|
const filter = getFilter(req.query, allowedFilters);
|
||||||
listStockEventsRouteHandler(req, res, page, limit, filter, sort, order);
|
listStockEventsRouteHandler(req, res, page, limit, filter, sort, order);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/properties', isAuthenticated, (req, res) => {
|
router.get('/properties', isAuthenticated, (req, res) => {
|
||||||
let properties = convertPropertiesString(req.query.properties);
|
let properties = convertPropertiesString(req.query.properties);
|
||||||
const allowedFilters = ['owner._id', 'parent._id'];
|
const allowedFilters = ['owner_.id', 'parent._id'];
|
||||||
const filter = getFilter(req.query, allowedFilters, false);
|
const filter = getFilter(req.query, allowedFilters, false);
|
||||||
var masterFilter = {};
|
var masterFilter = {};
|
||||||
if (req.query.masterFilter) {
|
if (req.query.masterFilter) {
|
||||||
|
|||||||
@ -1,44 +0,0 @@
|
|||||||
import mongoose from 'mongoose';
|
|
||||||
import { generateId } from '../../utils.js';
|
|
||||||
const { Schema } = mongoose;
|
|
||||||
|
|
||||||
const purchaseOrderSchema = new Schema(
|
|
||||||
{
|
|
||||||
_reference: { type: String, default: () => generateId()() },
|
|
||||||
value: { type: Number, required: true },
|
|
||||||
unit: { type: String, required: true },
|
|
||||||
parent: {
|
|
||||||
type: Schema.Types.ObjectId,
|
|
||||||
refPath: 'parentType',
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
parentType: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
enum: ['filamentStock', 'partStock', 'productStock'], // Add other models as needed
|
|
||||||
},
|
|
||||||
owner: {
|
|
||||||
type: Schema.Types.ObjectId,
|
|
||||||
refPath: 'ownerType',
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
ownerType: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
enum: ['user', 'subJob', 'stockAudit'],
|
|
||||||
},
|
|
||||||
timestamp: { type: Date, default: Date.now },
|
|
||||||
},
|
|
||||||
{ timestamps: true }
|
|
||||||
);
|
|
||||||
|
|
||||||
// Add virtual id getter
|
|
||||||
purchaseOrderSchema.virtual('id').get(function () {
|
|
||||||
return this._id;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Configure JSON serialization to include virtuals
|
|
||||||
purchaseOrderSchema.set('toJSON', { virtuals: true });
|
|
||||||
|
|
||||||
// Create and export the model
|
|
||||||
export const purchaseOrderModel = mongoose.model('purchaseOrder', purchaseOrderSchema);
|
|
||||||
@ -32,7 +32,6 @@ const documentPrinterSchema = new Schema(
|
|||||||
},
|
},
|
||||||
connectedAt: { type: Date, default: null },
|
connectedAt: { type: Date, default: null },
|
||||||
host: { type: Schema.Types.ObjectId, ref: 'host', required: true },
|
host: { type: Schema.Types.ObjectId, ref: 'host', required: true },
|
||||||
vendor: { type: Schema.Types.ObjectId, ref: 'vendor', required: false },
|
|
||||||
queue: [{ type: Schema.Types.ObjectId, ref: 'documentJob', required: false }],
|
queue: [{ type: Schema.Types.ObjectId, ref: 'documentJob', required: false }],
|
||||||
},
|
},
|
||||||
{ timestamps: true }
|
{ timestamps: true }
|
||||||
|
|||||||
@ -12,8 +12,8 @@ const jobSchema = new mongoose.Schema(
|
|||||||
printers: [{ type: Schema.Types.ObjectId, ref: 'printer', required: false }],
|
printers: [{ type: Schema.Types.ObjectId, ref: 'printer', required: false }],
|
||||||
createdAt: { required: true, type: Date },
|
createdAt: { required: true, type: Date },
|
||||||
updatedAt: { required: true, type: Date },
|
updatedAt: { required: true, type: Date },
|
||||||
startedAt: { required: false, type: Date, default: null },
|
startedAt: { required: false, type: Date },
|
||||||
finishedAt: { required: false, type: Date, default: null },
|
finishedAt: { required: false, type: Date },
|
||||||
gcodeFile: {
|
gcodeFile: {
|
||||||
type: Schema.Types.ObjectId,
|
type: Schema.Types.ObjectId,
|
||||||
ref: 'gcodeFile',
|
ref: 'gcodeFile',
|
||||||
|
|||||||
@ -39,8 +39,8 @@ const subJobSchema = new mongoose.Schema({
|
|||||||
type: Date,
|
type: Date,
|
||||||
default: Date.now,
|
default: Date.now,
|
||||||
},
|
},
|
||||||
startedAt: { required: false, type: Date, default: null },
|
startedAt: { required: false, type: Date },
|
||||||
finishedAt: { required: false, type: Date, default: null },
|
finishedAt: { required: false, type: Date },
|
||||||
});
|
});
|
||||||
|
|
||||||
subJobSchema.virtual('id').get(function () {
|
subJobSchema.virtual('id').get(function () {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user