diff --git a/src/controllers/storeController.js b/src/controllers/storeController.js index 8de37e5d..59ab9fa6 100644 --- a/src/controllers/storeController.js +++ b/src/controllers/storeController.js @@ -1317,14 +1317,14 @@ exports.updateSensorQC = async (req, reply) => { // Ensure qccheck is handled properly if (filteredUpdateData.qccheck) { const qccheckLower = filteredUpdateData.qccheck.toLowerCase(); - filteredUpdateData.status = qccheckLower === 'ok' ? 'available' : 'qcfailed'; + filteredUpdateData.status = qccheckLower === 'Pass' ? 'available' : 'qcfailed'; } // Update qccheckdate with the current date in "DD-MMM-YYYY - HH:MM" format filteredUpdateData.qccheckdate = moment().format('DD-MMM-YYYY - HH:mm'); // Find the sensor by ID - const updatedSensor = await Insensors.findByIdAndUpdate( + const updatedSensor = await Insensors.findOneAndUpdate( hardwareId, filteredUpdateData, { new: true } @@ -2319,6 +2319,7 @@ exports.acceptQuotation = async (req, reply) => { status: "blocked", customerId, connected_to: masterHardwareId, + tankhardwareId: `tank-${j + 1}`, hardwareId: slave.hardwareId, tankName: tank.tankName || "", tankLocation: tank.tankLocation || "", diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 9daca387..e0ca8921 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -2880,7 +2880,34 @@ exports.motoractiontest = async (req, reply) => { } }; +exports.motoractiontestbeforeqc = async (req, reply) => { + try { + + + const { motor_id, action } = req.body; + + + + + + if (action === "start") { + await this.publishMotorStopStatus(motor_id, "2"); + } else if (action === "stop") { + await this.publishMotorStopStatus(motor_id, "1"); + } else { + return reply.status(400).send({ success: false, message: "Invalid action" }); + } + + return reply.send({ success: true, message: `Motor ${action} command sent.` }); + + + + } catch (error) { + console.error("Error fetching data:", error); + return reply.status(500).send({ success: false, message: "Internal Server Error" }); + } +}; const motorIntervals = {}; diff --git a/src/index.js b/src/index.js index b2fd6a0f..d464523d 100644 --- a/src/index.js +++ b/src/index.js @@ -27,7 +27,7 @@ const fastify = require("fastify")({ // const Fastify = require("fastify"); fastify.register(cors, { - origin: 'http://localhost:3001', // Allow only your frontend URL + origin: 'http://armintaaqua.com:3000', // Allow only your frontend URL methods: ['GET', 'POST', 'PUT', 'DELETE'], // Allowed HTTP methods }); diff --git a/src/models/store.js b/src/models/store.js index 57551f8f..b5a2291a 100644 --- a/src/models/store.js +++ b/src/models/store.js @@ -469,6 +469,9 @@ lora_last_disconnect_time : { type: String, default: null }, power_check: { result: String }, master_connecting_gsm: { result: String }, slave_connecting: { result: String }, + motor_start: { result: String }, + motor_stop: { result: String }, + motor_starting: { result: String, steps: [ @@ -602,10 +605,11 @@ const orderSchema = new mongoose.Schema({ datetime: { type: String, default: null }, updated_at: { type: String, default: null }, assignedTeamMembers: [{ type: String }], + tankhardwareId: [{ type: String,default: null }], master_connections: [ { master_name: { type: String, default: null }, - + hardwareId: { type: String, default: null }, slaves: { type: String, default: null }, location: { type: String, default: null }, googleLocation: { type: String, default: null }, diff --git a/src/routes/storeRoute.js b/src/routes/storeRoute.js index 5038c582..59881457 100644 --- a/src/routes/storeRoute.js +++ b/src/routes/storeRoute.js @@ -1220,7 +1220,7 @@ fastify.post('/api/updateSensorQC/:hardwareId', { tags: ['Store-Data'], summary: 'Update QC fields of a sensor', params: { - required: ['_ihardwareIdd'], + required: ['hardwareId'], type: 'object', properties: { hardwareId: { type: 'string', description: 'Sensor ID' }, @@ -1243,6 +1243,8 @@ fastify.post('/api/updateSensorQC/:hardwareId', { power_check: { type: 'string' }, master_connecting_gsm: { type: 'string' }, slave_connecting: { type: 'string' }, + motor_start: { type: 'string' }, + motor_stop: { type: 'string' }, motor_starting: { type: 'object', properties: { diff --git a/src/routes/tanksRoute.js b/src/routes/tanksRoute.js index 3f098f0b..78e0951a 100644 --- a/src/routes/tanksRoute.js +++ b/src/routes/tanksRoute.js @@ -415,6 +415,41 @@ module.exports = function (fastify, opts, next) { }); + + fastify.route({ + method: "PUT", + url: "/api/motoractiontestbeforeqc", + schema: { + tags: ["Install"], + summary: "This is for start and stop test before qc", + + + + body: { + type: "object", + // required: ['phone'], + properties: { + + motor_id:{type:"string"}, + action:{type:"string"}, + + }, + }, + security: [ + { + basicAuth: [], + }, + ], + }, + // preHandler: [ + // fastify.auth([fastify.operatorAuthenticate]), + // validationHandler.validatePhoneFormat, + // ], + //preHandler: fastify.auth([fastify.authenticate]), + handler: tanksController.motoractiontestbeforeqc, + }); + + // fastify.route({ // method: "PUT", // url: "/api/consumption/:customerId",