Enhanced filament schema and related service functions to include vendor information. Updated route handlers to support vendor population in filament queries and exports, improving data management and retrieval capabilities.
Some checks failed
farmcontrol/farmcontrol-api/pipeline/head There was a failure building this commit

This commit is contained in:
Tom Butcher 2026-07-26 19:07:41 +01:00
parent fa74c464f9
commit 5ee8f332e2
3 changed files with 9 additions and 5 deletions

View File

@ -6,6 +6,7 @@ const { Schema } = mongoose;
const filamentSchema = new mongoose.Schema({ const filamentSchema = new mongoose.Schema({
_reference: { type: String, default: () => generateId()() }, _reference: { type: String, default: () => generateId()() },
name: { required: true, type: String }, name: { required: true, type: String },
vendor: { type: Schema.Types.ObjectId, ref: 'vendor', required: false },
barcode: { required: false, type: String }, barcode: { required: false, type: String },
url: { required: false, type: String }, url: { required: false, type: String },
image: { required: false, type: Buffer }, image: { required: false, type: Buffer },

View File

@ -39,7 +39,7 @@ export const listFilamentsRouteHandler = async (
search, search,
sort, sort,
order, order,
populate: ['costTaxRate', 'material'], populate: ['costTaxRate', 'material', 'vendor'],
}); });
if (result?.error) { if (result?.error) {
@ -98,7 +98,7 @@ export const getFilamentRouteHandler = async (req, res) => {
const result = await getObject({ const result = await getObject({
model: filamentModel, model: filamentModel,
id, id,
populate: ['costTaxRate', 'material'], populate: ['costTaxRate', 'material', 'vendor'],
}); });
if (result?.error) { if (result?.error) {
logger.warn(`Filament not found with supplied id.`); logger.warn(`Filament not found with supplied id.`);
@ -117,6 +117,7 @@ export const editFilamentRouteHandler = async (req, res) => {
const updateData = { const updateData = {
updatedAt: new Date(), updatedAt: new Date(),
name: req.body.name, name: req.body.name,
vendor: req.body.vendor,
barcode: req.body.barcode, barcode: req.body.barcode,
url: req.body.url, url: req.body.url,
image: req.body.image, image: req.body.image,
@ -133,7 +134,7 @@ export const editFilamentRouteHandler = async (req, res) => {
id, id,
updateData, updateData,
user: req.user, user: req.user,
populate: ['costTaxRate', 'material'], populate: ['costTaxRate', 'material', 'vendor'],
}); });
if (result.error) { if (result.error) {
@ -151,6 +152,7 @@ export const editMultipleFilamentsRouteHandler = async (req, res) => {
const updates = req.body.map((update) => ({ const updates = req.body.map((update) => ({
_id: update._id, _id: update._id,
name: update.name, name: update.name,
vendor: update.vendor,
barcode: update.barcode, barcode: update.barcode,
url: update.url, url: update.url,
image: update.image, image: update.image,
@ -189,6 +191,7 @@ export const newFilamentRouteHandler = async (req, res) => {
createdAt: new Date(), createdAt: new Date(),
updatedAt: new Date(), updatedAt: new Date(),
name: req.body.name, name: req.body.name,
vendor: req.body.vendor,
barcode: req.body.barcode, barcode: req.body.barcode,
url: req.body.url, url: req.body.url,
image: req.body.image, image: req.body.image,

View File

@ -13,8 +13,8 @@ export const EXPORT_FILTER_BY_TYPE = {
subJob: ['job'], subJob: ['job'],
filamentStock: ['filament', 'filament._id', 'filamentSku'], filamentStock: ['filament', 'filament._id', 'filamentSku'],
gcodeFile: ['filament', 'filament._id', 'filamentSku'], gcodeFile: ['filament', 'filament._id', 'filamentSku'],
filament: ['material', 'material._id', 'name', 'diameter', 'cost'], filament: ['material', 'material._id', 'vendor', 'name', 'diameter', 'cost'],
filamentSku: ['filament', 'vendor', 'costTaxRate'], filamentSku: ['filament', 'filament.vendor', 'costTaxRate'],
material: ['name', 'tags'], material: ['name', 'tags'],
partStock: ['partSku'], partStock: ['partSku'],
partSku: ['part', 'vendor', 'priceTaxRate', 'costTaxRate'], partSku: ['part', 'vendor', 'priceTaxRate', 'costTaxRate'],