diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 012b8422..cd4e828b 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -3878,6 +3878,28 @@ exports.getLatestData = async (req, reply) => { } }; +exports.changesurveystatus = async (req, reply) => { + try { + const customerId = req.params.customerId; + + + const result = await User.findOneAndUpdate( + { customerId: customerId }, + { $set: { survey_status: req.body.survey_status } }, + { new: true } + ); + + + + reply.code(200).send({ result }); + + } catch (err) { + // send an error response + reply.code(500).send({ error: err.message }); + } +}; + + exports.checkStatusofIot = async (req, reply) => { try { @@ -4688,6 +4710,33 @@ client.on('message', async (topic, message) => { +exports.getPendingAndCompletedsurveyOfparticularInstaller = async (request, reply) => { + try { + const { installationId } = request.params; + const survey_status = request.body; + + + const surveydata = await User.find({ + installationId, + survey_status, + + }); + + + // Send the response, including both total consumption and filtered consumption records + reply.send({ + status_code: 200, + surveydata, + + }); + } catch (err) { + throw boom.boomify(err); + } +}; + + + + exports.consumptionofparticulartank = async (request, reply) => { try { diff --git a/src/models/User.js b/src/models/User.js index 9592547a..f25aeb54 100644 --- a/src/models/User.js +++ b/src/models/User.js @@ -56,7 +56,7 @@ const userSchema = new mongoose.Schema( oneTimePasswordSetFlag: { type: Boolean, default: false }, emails: [{ email: String, verified: { type: Boolean, default: false } }], services: { password: { bcrypt: String } }, - + survey_status:{ type:String,default: "pending" }, profile: { role: [{ type: String, default: "user" }], firstName: { type: String, default: null }, diff --git a/src/routes/tanksRoute.js b/src/routes/tanksRoute.js index 83af36b2..0f6acb37 100644 --- a/src/routes/tanksRoute.js +++ b/src/routes/tanksRoute.js @@ -653,6 +653,42 @@ module.exports = function (fastify, opts, next) { handler: tanksController.getLatestData, }); + fastify.route({ + method: "GET", + url: "/api/changesurveystatus/:customerId", + schema: { + tags: ["Install"], + summary: "This is for changing survey status", + params: { + required: ["customerId"], + type: "object", + properties: { + customerId: { + type: "string", + description: "customerId", + }, + }, + }, + // querystring: { + // tankName: {type: 'string'} + // }, + body: { + type: 'object', + properties: { + survey_status: { type: 'string' }, + }, + required: ['survey_status'], + }, + security: [ + { + basicAuth: [], + }, + ], + }, + // preHandler: fastify.auth([fastify.authenticate]), + handler: tanksController.changesurveystatus, + }); + fastify.route({ method: "GET", @@ -1116,6 +1152,40 @@ module.exports = function (fastify, opts, next) { // preHandler: fastify.auth([fastify.authenticate]), handler: tanksController.consumptionofparticulartank, }); + + + fastify.route({ + method: "PUT", + url: "/api/getPendingAndCompletedsurveyOfparticularInstaller/:installationId", + schema: { + tags: ["Install"], + summary: "This is for getting pending and completed surveys users of particular installer", + params: { + required: ["installationId"], + type: "object", + properties: { + installationId: { + type: "string", + description: "InstallationId", + }, + }, + }, + body: { + type: "object", + properties: { + survey_status: { type: "string" }, + + }, + }, + security: [ + { + basicAuth: [], + }, + ], + }, + // preHandler: fastify.auth([fastify.authenticate]), + handler: tanksController.getPendingAndCompletedsurveyOfparticularInstaller, + }); next();