Numerious fixes.
This commit is contained in:
parent
57f057e3aa
commit
92e07c97d7
@ -19,6 +19,7 @@ const filamentStockSchema = new Schema(
|
|||||||
net: { type: Number, required: true },
|
net: { type: Number, required: true },
|
||||||
gross: { type: Number, required: true },
|
gross: { type: Number, required: true },
|
||||||
},
|
},
|
||||||
|
filament: { type: mongoose.Schema.Types.ObjectId, ref: 'filament', required: true },
|
||||||
filamentSku: { type: mongoose.Schema.Types.ObjectId, ref: 'filamentSku', required: true },
|
filamentSku: { type: mongoose.Schema.Types.ObjectId, ref: 'filamentSku', required: true },
|
||||||
stockLocation: {
|
stockLocation: {
|
||||||
type: mongoose.Schema.Types.ObjectId,
|
type: mongoose.Schema.Types.ObjectId,
|
||||||
@ -29,6 +30,13 @@ const filamentStockSchema = new Schema(
|
|||||||
{ timestamps: true }
|
{ timestamps: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
filamentStockSchema.pre('validate', async function () {
|
||||||
|
if (!this.filament && this.filamentSku) {
|
||||||
|
const sku = await mongoose.model('filamentSku').findById(this.filamentSku).select('filament').lean();
|
||||||
|
if (sku?.filament) this.filament = sku.filament;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const rollupConfigs = [
|
const rollupConfigs = [
|
||||||
{
|
{
|
||||||
name: 'totalCurrentWeight',
|
name: 'totalCurrentWeight',
|
||||||
|
|||||||
@ -14,6 +14,7 @@ const gcodeFileSchema = new mongoose.Schema(
|
|||||||
name: { required: true, type: String },
|
name: { required: true, type: String },
|
||||||
gcodeFileName: { required: false, type: String },
|
gcodeFileName: { required: false, type: String },
|
||||||
size: { type: Number, required: false },
|
size: { type: Number, required: false },
|
||||||
|
filament: { type: Schema.Types.ObjectId, ref: 'filament', required: true },
|
||||||
filamentSku: { type: Schema.Types.ObjectId, ref: 'filamentSku', required: true },
|
filamentSku: { type: Schema.Types.ObjectId, ref: 'filamentSku', required: true },
|
||||||
parts: [partSchema],
|
parts: [partSchema],
|
||||||
file: { type: mongoose.SchemaTypes.ObjectId, ref: 'file', required: false },
|
file: { type: mongoose.SchemaTypes.ObjectId, ref: 'file', required: false },
|
||||||
@ -22,6 +23,13 @@ const gcodeFileSchema = new mongoose.Schema(
|
|||||||
{ timestamps: true }
|
{ timestamps: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
gcodeFileSchema.pre('validate', async function () {
|
||||||
|
if (!this.filament && this.filamentSku) {
|
||||||
|
const sku = await mongoose.model('filamentSku').findById(this.filamentSku).select('filament').lean();
|
||||||
|
if (sku?.filament) this.filament = sku.filament;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
gcodeFileSchema.index({ name: 'text', brand: 'text' });
|
gcodeFileSchema.index({ name: 'text', brand: 'text' });
|
||||||
|
|
||||||
gcodeFileSchema.virtual('id').get(function () {
|
gcodeFileSchema.virtual('id').get(function () {
|
||||||
|
|||||||
@ -19,6 +19,8 @@ import {
|
|||||||
router.get('/', isAuthenticated, (req, res) => {
|
router.get('/', isAuthenticated, (req, res) => {
|
||||||
const { page, limit, property, search, sort, order } = req.query;
|
const { page, limit, property, search, sort, order } = req.query;
|
||||||
const allowedFilters = [
|
const allowedFilters = [
|
||||||
|
'filament',
|
||||||
|
'filament._id',
|
||||||
'filamentSku',
|
'filamentSku',
|
||||||
'state',
|
'state',
|
||||||
'startingWeight',
|
'startingWeight',
|
||||||
@ -33,7 +35,7 @@ router.get('/', isAuthenticated, (req, res) => {
|
|||||||
|
|
||||||
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 = ['filamentSku', 'state.type'];
|
const allowedFilters = ['filament', 'filament._id', 'filamentSku', 'state.type'];
|
||||||
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) {
|
||||||
|
|||||||
@ -16,14 +16,14 @@ import { convertPropertiesString, getFilter } from '../../utils.js';
|
|||||||
// list of gcodeFiles
|
// list of gcodeFiles
|
||||||
router.get('/', isAuthenticated, (req, res) => {
|
router.get('/', isAuthenticated, (req, res) => {
|
||||||
const { page, limit, property, search, sort, order } = req.query;
|
const { page, limit, property, search, sort, order } = req.query;
|
||||||
const allowedFilters = ['_id', 'name', 'filament._id'];
|
const allowedFilters = ['_id', 'name', 'filament', 'filament._id', 'filamentSku', 'filamentSku._id'];
|
||||||
const filter = getFilter(req.query, allowedFilters);
|
const filter = getFilter(req.query, allowedFilters);
|
||||||
listGCodeFilesRouteHandler(req, res, page, limit, property, filter, search, sort, order);
|
listGCodeFilesRouteHandler(req, res, page, limit, property, filter, search, 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 = ['filament'];
|
const allowedFilters = ['filament', 'filament._id', 'filamentSku', 'filamentSku._id'];
|
||||||
const filter = getFilter(req.query, allowedFilters, false);
|
const filter = getFilter(req.query, allowedFilters, false);
|
||||||
listGCodeFilesByPropertiesRouteHandler(req, res, properties, filter);
|
listGCodeFilesByPropertiesRouteHandler(req, res, properties, filter);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -36,7 +36,11 @@ export const listFilamentStocksRouteHandler = async (
|
|||||||
search,
|
search,
|
||||||
sort,
|
sort,
|
||||||
order,
|
order,
|
||||||
populate: [{ path: 'filamentSku' }, { path: 'stockLocation' }],
|
populate: [
|
||||||
|
{ path: 'filament' },
|
||||||
|
{ path: 'filamentSku', populate: 'filament' },
|
||||||
|
{ path: 'stockLocation' },
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result?.error) {
|
if (result?.error) {
|
||||||
@ -60,7 +64,7 @@ export const listFilamentStocksByPropertiesRouteHandler = async (
|
|||||||
model: filamentStockModel,
|
model: filamentStockModel,
|
||||||
properties,
|
properties,
|
||||||
filter,
|
filter,
|
||||||
populate: ['filamentSku', 'stockLocation'],
|
populate: ['filament', { path: 'filamentSku', populate: 'filament' }, 'stockLocation'],
|
||||||
masterFilter,
|
masterFilter,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -79,7 +83,11 @@ export const getFilamentStockRouteHandler = async (req, res) => {
|
|||||||
const result = await getObject({
|
const result = await getObject({
|
||||||
model: filamentStockModel,
|
model: filamentStockModel,
|
||||||
id,
|
id,
|
||||||
populate: [{ path: 'filamentSku' }, { path: 'stockLocation' }],
|
populate: [
|
||||||
|
{ path: 'filament' },
|
||||||
|
{ path: 'filamentSku', populate: 'filament' },
|
||||||
|
{ path: 'stockLocation' },
|
||||||
|
],
|
||||||
});
|
});
|
||||||
if (result?.error) {
|
if (result?.error) {
|
||||||
logger.warn(`Filament Stock not found with supplied id.`);
|
logger.warn(`Filament Stock not found with supplied id.`);
|
||||||
@ -147,6 +155,7 @@ export const newFilamentStockRouteHandler = async (req, res) => {
|
|||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
startingWeight: req.body.startingWeight,
|
startingWeight: req.body.startingWeight,
|
||||||
currentWeight: req.body.currentWeight,
|
currentWeight: req.body.currentWeight,
|
||||||
|
filament: req.body.filament,
|
||||||
filamentSku: req.body.filamentSku,
|
filamentSku: req.body.filamentSku,
|
||||||
state: req.body.state,
|
state: req.body.state,
|
||||||
stockLocation: req.body.stockLocation,
|
stockLocation: req.body.stockLocation,
|
||||||
|
|||||||
@ -88,6 +88,7 @@ async function executePostedLine(transferId, line) {
|
|||||||
state: src.state,
|
state: src.state,
|
||||||
startingWeight: destWeight,
|
startingWeight: destWeight,
|
||||||
currentWeight: destWeight,
|
currentWeight: destWeight,
|
||||||
|
filament: src.filament,
|
||||||
filamentSku: src.filamentSku,
|
filamentSku: src.filamentSku,
|
||||||
stockLocation: toLocId,
|
stockLocation: toLocId,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -11,7 +11,8 @@ export const EXPORT_FILTER_BY_TYPE = {
|
|||||||
printer: ['host'],
|
printer: ['host'],
|
||||||
job: ['printer', 'gcodeFile'],
|
job: ['printer', 'gcodeFile'],
|
||||||
subJob: ['job'],
|
subJob: ['job'],
|
||||||
filamentStock: ['filamentSku'],
|
filamentStock: ['filament', 'filament._id', 'filamentSku'],
|
||||||
|
gcodeFile: ['filament', 'filament._id', 'filamentSku'],
|
||||||
filament: ['material', 'material._id', 'name', 'diameter', 'cost'],
|
filament: ['material', 'material._id', 'name', 'diameter', 'cost'],
|
||||||
filamentSku: ['filament', 'vendor', 'costTaxRate'],
|
filamentSku: ['filament', 'vendor', 'costTaxRate'],
|
||||||
material: ['name', 'tags'],
|
material: ['name', 'tags'],
|
||||||
|
|||||||
@ -35,7 +35,7 @@ export const listGCodeFilesRouteHandler = async (
|
|||||||
search,
|
search,
|
||||||
sort,
|
sort,
|
||||||
order,
|
order,
|
||||||
populate: ['filamentSku'],
|
populate: ['filament', { path: 'filamentSku', populate: 'filament' }],
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result?.error) {
|
if (result?.error) {
|
||||||
@ -58,7 +58,7 @@ export const listGCodeFilesByPropertiesRouteHandler = async (
|
|||||||
model: gcodeFileModel,
|
model: gcodeFileModel,
|
||||||
properties,
|
properties,
|
||||||
filter,
|
filter,
|
||||||
populate: 'filamentSku',
|
populate: ['filament', { path: 'filamentSku', populate: 'filament' }],
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result?.error) {
|
if (result?.error) {
|
||||||
@ -76,7 +76,7 @@ export const getGCodeFileRouteHandler = async (req, res) => {
|
|||||||
const result = await getObject({
|
const result = await getObject({
|
||||||
model: gcodeFileModel,
|
model: gcodeFileModel,
|
||||||
id,
|
id,
|
||||||
populate: ['filamentSku', 'parts.partSku'],
|
populate: ['filament', { path: 'filamentSku', populate: 'filament' }, 'parts.partSku'],
|
||||||
});
|
});
|
||||||
if (result?.error) {
|
if (result?.error) {
|
||||||
logger.warn(`GCodeFile not found with supplied id.`);
|
logger.warn(`GCodeFile not found with supplied id.`);
|
||||||
@ -113,6 +113,7 @@ export const editGCodeFileRouteHandler = async (req, res) => {
|
|||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
name: req.body.name,
|
name: req.body.name,
|
||||||
file: req.body.file,
|
file: req.body.file,
|
||||||
|
filament: req.body.filament,
|
||||||
filamentSku: req.body.filamentSku,
|
filamentSku: req.body.filamentSku,
|
||||||
parts: req.body.parts,
|
parts: req.body.parts,
|
||||||
};
|
};
|
||||||
@ -140,6 +141,7 @@ export const newGCodeFileRouteHandler = async (req, res) => {
|
|||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
name: req.body.name,
|
name: req.body.name,
|
||||||
file: req.body.file,
|
file: req.body.file,
|
||||||
|
filament: req.body.filament,
|
||||||
filamentSku: req.body.filamentSku,
|
filamentSku: req.body.filamentSku,
|
||||||
parts: req.body.parts,
|
parts: req.body.parts,
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user