diff --git a/src/controllers/storeController.js b/src/controllers/storeController.js index 423dc264..02d0153a 100644 --- a/src/controllers/storeController.js +++ b/src/controllers/storeController.js @@ -16,6 +16,8 @@ exports.installSignUp = async (request, reply) => { //name, phone, address, + address1, + address2, installationId, emails, password, @@ -28,6 +30,7 @@ exports.installSignUp = async (request, reply) => { alternativeNumber, firstName, lastName, + city, createdBy, updatedBy, } = request.body; @@ -51,7 +54,9 @@ exports.installSignUp = async (request, reply) => { const install = new Install({ //name, phone, - address, + address, + address1, + address2, installationId, emails, services: { password: { bcrypt: hashedPassword } }, @@ -64,6 +69,7 @@ exports.installSignUp = async (request, reply) => { alternativeNumber, firstName, lastName, + city, createdBy, updatedBy, diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 813e4f56..e7820ffd 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -301,6 +301,8 @@ exports.updateTanklevels = async (req, reply) => { } }; + + exports.getTanklevels = async (req, reply) => { try { const customerId = req.params.customerId; @@ -317,23 +319,27 @@ exports.getTanklevels = async (req, reply) => { console.log("updated_data", updated_data); updated_data.forEach((tank) => { - const capacity = parseInt(tank.capacity.replace(/,/g, '')); + const waterlevel = parseInt(tank.waterlevel.replace(/,/g, ''), 10); + const capacity = parseInt(tank.capacity.replace(/,/g, ''), 10); + console.log(`Processing tank: ${tank.tankName}`); + console.log(`Type of Water: ${tank.typeOfWater}, Location: ${tank.tankLocation}, Waterlevel: ${waterlevel}, Capacity: ${capacity}`); + if (tank.tankLocation === 'sump' && tank.typeOfWater === 'Drinking Water') { - sumSumpDrinkingWater += parseInt(tank.waterlevel); + sumSumpDrinkingWater += waterlevel; sumSumpDrinkingWaterCapacity += capacity; } else if (tank.tankLocation === 'overhead' && tank.typeOfWater === 'Drinking Water') { - sumOverheadDrinkingWater += parseInt(tank.waterlevel); + sumOverheadDrinkingWater += waterlevel; sumOverheadDrinkingWaterCapacity += capacity; } else if (tank.tankLocation === 'sump' && tank.typeOfWater === 'Bore Water') { - sumSumpBoreWater += parseInt(tank.waterlevel); + sumSumpBoreWater += waterlevel; sumSumpBoreWaterCapacity += capacity; } else if (tank.tankLocation === 'overhead' && tank.typeOfWater === 'Bore Water') { - sumOverheadBoreWater += parseInt(tank.waterlevel); + sumOverheadBoreWater += waterlevel; sumOverheadBoreWaterCapacity += capacity; } }); - reply.send({ + const responseData = { status_code: 200, data: updated_data, totalDrinkingWaterInSump: sumSumpDrinkingWater, @@ -344,14 +350,21 @@ exports.getTanklevels = async (req, reply) => { totalDrinkingWaterInOverheadCapacity: sumOverheadDrinkingWaterCapacity, totalBoreWaterInSumpCapacity: sumSumpBoreWaterCapacity, totalBoreWaterInOverheadCapacity: sumOverheadBoreWaterCapacity, - }); + }; + + if (!reply.sent) { + reply.send(responseData); + } - return { message: 'success' }; } catch (err) { + if (!reply.sent) { + reply.code(500).send({ error: 'Internal Server Error' }); + } throw boom.boomify(err); } }; + const intervals = {}; let sump_water_levels=[]; let supplier_tanks = []; diff --git a/src/index.js b/src/index.js index 6074f290..938b5624 100644 --- a/src/index.js +++ b/src/index.js @@ -279,9 +279,9 @@ fastify.post("/api/login", { fastify.post("/api/installotplogin", { schema: { - description: "This is for Login Otp Boy", + description: "This is for Login Otp Installation", tags: ["Install"], - summary: "This is for Login Otp Boy", + summary: "This is for Login Otp Installation", body: { type: "object", required: ["phone", "phoneVerificationCode"], @@ -340,7 +340,7 @@ fastify.post("/api/installotplogin", { } else { const token = fastify.jwt.sign( { - name: user.name, + firstName: user.firstName, }, { expiresIn: "30d" } ); @@ -348,7 +348,7 @@ fastify.post("/api/installotplogin", { const profilePicture = await ProfilePictureInstall.findOne({ customerId: user._id, }); - +console.log(user) const responsePayload = { simplydata: { error: false, @@ -356,9 +356,9 @@ fastify.post("/api/installotplogin", { access_token: token, email: user.emails, phone: user.phone, - name: user.name, - address1: user.profile.address1, - address2: user.profile.address2, + //name: user.name, + address1: user.address1, + address2: user.address2, phoneVerified: user.phoneVerified, oneTimePasswordSetFlag: user.oneTimePasswordSetFlag, type: user.profile.role, @@ -368,6 +368,7 @@ fastify.post("/api/installotplogin", { manager: user.manager, firstName: user.firstName, lastName: user.lastName, + address: user.address, alternativeNumber: user.alternativeNumber, }, }; diff --git a/src/models/store.js b/src/models/store.js index 8c81f868..1f11d440 100644 --- a/src/models/store.js +++ b/src/models/store.js @@ -15,14 +15,14 @@ const installationschema = new mongoose.Schema({ oneTimePasswordSetFlag: { type: Boolean, default: false }, emails: [{ email: String, verified: { type: Boolean, default: false } }], services: { password: { bcrypt: String } }, - + alternativeNumber: { type: String, default: null }, + firstName: { type: String, default: null }, + lastName: { type: String, default: null }, + address1: { type: String, default: null }, + address2: { type: String, default: null }, + city: { type: String, default: null }, profile: { - alternativeNumber: { type: String, default: null }, - firstName: { type: String, default: null }, - lastName: { type: String, default: null }, - address1: { type: String, default: null }, - address2: { type: String, default: null }, - city: { type: String, default: null }, + state: { type: String, default: null }, country: { type: String, default: null }, }, diff --git a/src/models/tanks.js b/src/models/tanks.js index a4348860..b661f92b 100644 --- a/src/models/tanks.js +++ b/src/models/tanks.js @@ -33,7 +33,7 @@ const RoleSchema = new Schema({ name: String }); const tanksSchema = new mongoose.Schema({ hardwareId: { type: String }, - InstallerId: { type: String, default: null }, + InstallerId0: { type: String, default: null }, tankhardwareId: { type: String }, hardwareId_type: { type: String }, hardwareId_company: { type: String }, @@ -42,6 +42,7 @@ const tanksSchema = new mongoose.Schema({ blockName: { type: String, default: null }, capacity: { type: String, default: "0" }, height: { type: String, default: "0" }, + tankLocation: { type: String, default: null }, waterCapacityPerCm:{ type: String, default: "0" }, typeOfWater: { type: String, default: null }, waterlevel: { type: String, default: "0" }, diff --git a/src/routes/storeRoute.js b/src/routes/storeRoute.js index 18af0a14..c131b5a2 100644 --- a/src/routes/storeRoute.js +++ b/src/routes/storeRoute.js @@ -28,6 +28,7 @@ module.exports = function (fastify, opts, next) { //name: { type: 'string' }, team: { type: 'string', default: null }, manager: { type: 'string', default: null }, + address: { type: 'string', default: null }, address1: { type: 'string', default: null }, address2: { type: 'string', default: null }, city: { type: 'string', default: null }, diff --git a/src/routes/tanksRoute.js b/src/routes/tanksRoute.js index 25bd5f57..8d2acfdb 100644 --- a/src/routes/tanksRoute.js +++ b/src/routes/tanksRoute.js @@ -251,7 +251,7 @@ module.exports = function (fastify, opts, next) { }, ], }, - preHandler: fastify.auth([fastify.authenticate]), + // preHandler: fastify.auth([fastify.authenticate]), handler: tanksController.getTanklevels, });