diff --git a/src/controllers/installationController.js b/src/controllers/installationController.js index ba3f1d40..549d6081 100644 --- a/src/controllers/installationController.js +++ b/src/controllers/installationController.js @@ -1969,7 +1969,7 @@ exports.addMediaToInsensor = async (req, reply) => { // const { hardwareId, customerId, type } = req.params; // const { video, material, workStatus, product_status } = req.body; const { customerId } = req.params; - const { hardwareId, type, video, material, workStatus, product_status } = req.body; + const { hardwareId, type, video, material, workStatus, product_status,description } = req.body; if (!hardwareId || !customerId || !type) { @@ -2001,6 +2001,9 @@ exports.addMediaToInsensor = async (req, reply) => { if (product_status && ['pending', 'complete'].includes(product_status)) { insensor.product_status = product_status; } + if (description) { + insensor.description = description; + } await insensor.save(); diff --git a/src/controllers/userController.js b/src/controllers/userController.js index 18c9422f..2fda58fa 100644 --- a/src/controllers/userController.js +++ b/src/controllers/userController.js @@ -1997,3 +1997,58 @@ exports.updateQuotedAmountForSupplier = async (req, reply) => { } }; +exports.updatestatusForSupplier = async (req, reply) => { + try { + const { _id } = req.params; + const { supplierId, status } = req.body; + + if (!_id) { + return reply.code(400).send({ status_code: 400, message: '_id (param) is required' }); + } + if (!supplierId) { + return reply.code(400).send({ status_code: 400, message: 'supplierId (body) is required' }); + } + if (typeof status === 'undefined' || status === null || String(status).trim() === '') { + return reply.code(400).send({ status_code: 400, message: 'status (body) is required' }); + } + + // Map short keywords to the stored values + let statusToSave = String(status).trim().toLowerCase(); + if (statusToSave === 'accept') statusToSave = 'accepted_by_user'; + else if (statusToSave === 'reject') statusToSave = 'rejected_by_user'; + // otherwise keep the original (but normalized) value + + // Atomic update using positional $ operator + const filter = { _id, 'requested_suppliers.supplierId': supplierId }; + const update = { $set: { 'requested_suppliers.$.status': statusToSave } }; + + const updated = await RequestedBooking.findOneAndUpdate(filter, update, { + new: true, + runValidators: true, + }).lean(); + + if (!updated) { + // either booking _id not found OR supplierId not found inside requested_suppliers + const bookingExists = await RequestedBooking.findById(_id).lean(); + if (!bookingExists) { + return reply.code(404).send({ status_code: 404, message: `Booking with _id ${_id} not found` }); + } + + // booking exists but supplier entry missing + return reply.code(404).send({ + status_code: 404, + message: `Supplier ${supplierId} not found in requested_suppliers for booking ${_id}`, + }); + } + + return reply.code(200).send({ + status_code: 200, + message: `status updated for supplier ${supplierId}`, + data: updated, + }); + } catch (err) { + console.error('updatestatusForSupplier error:', err); + throw boom.boomify(err); + } +}; + diff --git a/src/models/store.js b/src/models/store.js index ab242eba..2650e7d4 100644 --- a/src/models/store.js +++ b/src/models/store.js @@ -792,6 +792,8 @@ workStatusPictures: [ enum: ['pending', 'complete'], default: 'pending' }, + description: { type: String }, + }); diff --git a/src/routes/installationRoute.js b/src/routes/installationRoute.js index 9c06e1bd..7ab00c44 100644 --- a/src/routes/installationRoute.js +++ b/src/routes/installationRoute.js @@ -629,7 +629,9 @@ fastify.post( type: 'string', enum: ['pending', 'complete'], description: 'Optional: update product_status' - } + }, + description: { type: 'string' }, + }, // at least one of video, material, workStatus required diff --git a/src/routes/usersRoute.js b/src/routes/usersRoute.js index 84039bb8..ea6165d1 100644 --- a/src/routes/usersRoute.js +++ b/src/routes/usersRoute.js @@ -1412,5 +1412,45 @@ fastify.route({ handler: userController.updateQuotedAmountForSupplier, }); + fastify.route({ + method: 'PUT', + url: '/api/request-booking-status/:_id/supplier/quotestatus', + schema: { + description: + 'Update status for a supplier inside requested_suppliers for a requested booking', + tags: ['User'], + summary: 'Update tanker booking of pearticular supplier status by User', + params: { + type: 'object', + properties: { + _id: { type: 'string', description: 'Booking _id' }, + }, + required: ['_id'], + }, + body: { + type: 'object', + properties: { + supplierId: { type: 'string' }, + status: { type:'string'}, + }, + + }, + response: { + 200: { + type: 'object', + }, + 400: { type: 'object' }, + 404: { type: 'object' }, + }, + security: [ + { + basicAuth: [], + }, + ], + }, + // preHandler: fastify.auth([fastify.authenticate]), // enable if needed + handler: userController.updatestatusForSupplier, + }); + next(); };