Refactored filament recalculation logic to utilize filament SKUs instead of order items, improving efficiency. Updated allowed filters in the filament SKUs route to include 'costWithTax' and modified population logic in the service for better data retrieval.
All checks were successful
farmcontrol/farmcontrol-api/pipeline/head This commit looks good
All checks were successful
farmcontrol/farmcontrol-api/pipeline/head This commit looks good
This commit is contained in:
parent
74a9139002
commit
efb3fdbcb9
@ -25,19 +25,10 @@ filamentSchema.virtual('id').get(function () {
|
|||||||
filamentSchema.set('toJSON', { virtuals: true });
|
filamentSchema.set('toJSON', { virtuals: true });
|
||||||
|
|
||||||
filamentSchema.statics.recalculate = async function (filament, user) {
|
filamentSchema.statics.recalculate = async function (filament, user) {
|
||||||
const orderItemModel = mongoose.model('orderItem');
|
const filamentSkuModel = mongoose.model('filamentSku');
|
||||||
const itemId = filament._id;
|
const skus = await filamentSkuModel.find({ filament: filament._id }).select('_id').lean();
|
||||||
const draftOrderItems = await orderItemModel
|
for (const sku of skus) {
|
||||||
.find({
|
await filamentSkuModel.recalculate(sku, user);
|
||||||
'state.type': 'draft',
|
|
||||||
itemType: 'filament',
|
|
||||||
item: itemId,
|
|
||||||
})
|
|
||||||
.populate('order')
|
|
||||||
.lean();
|
|
||||||
|
|
||||||
for (const orderItem of draftOrderItems) {
|
|
||||||
await orderItemModel.recalculate(orderItem, user);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,7 @@ 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 = ['_id', 'barcode', 'filament', 'filament._id', 'name', 'color', 'cost'];
|
const allowedFilters = ['_id', 'barcode', 'filament', 'filament._id', 'name', 'color', 'cost', 'costWithTax'];
|
||||||
const filter = getFilter(req.query, allowedFilters);
|
const filter = getFilter(req.query, allowedFilters);
|
||||||
listFilamentSkusRouteHandler(req, res, page, limit, property, filter, search, sort, order);
|
listFilamentSkusRouteHandler(req, res, page, limit, property, filter, search, sort, order);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -35,7 +35,7 @@ export const listFilamentSkusRouteHandler = async (
|
|||||||
search,
|
search,
|
||||||
sort,
|
sort,
|
||||||
order,
|
order,
|
||||||
populate: ['costTaxRate'],
|
populate: [{ path: 'filament', populate: 'costTaxRate' }, 'costTaxRate'],
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result?.error) {
|
if (result?.error) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user