added capacity calculator

master
varun 3 years ago
commit 18ac80e0a7

@ -63,6 +63,7 @@ exports.orderNow = async (req, reply) => {
// console.log("This is the reply in the handler after the validations", reply); // console.log("This is the reply in the handler after the validations", reply);
deliveryData = { deliveryData = {
supplierId: supplierId, supplierId: supplierId,
suppliername: req.body.suppliername,
name: req.body.Name, name: req.body.Name,
phone: req.body.phone, phone: req.body.phone,
alternativeContactNumber: req.body.alternativeContactNumber, alternativeContactNumber: req.body.alternativeContactNumber,
@ -71,6 +72,9 @@ exports.orderNow = async (req, reply) => {
state:req.body.state, state:req.body.state,
zip:req.body.zip, zip:req.body.zip,
status:req.body.status, status:req.body.status,
longitude: req.body.longitude,
latitude:req.body.latitude,
}; };
var agent_mobile = req.body.phone var agent_mobile = req.body.phone
@ -88,6 +92,7 @@ exports.orderNow = async (req, reply) => {
usertobeInserted = checkFormEncoding.agent; usertobeInserted = checkFormEncoding.agent;
console.log("thsi true url string"); console.log("thsi true url string");
agent.supplierId = usertobeInserted.supplierId agent.supplierId = usertobeInserted.supplierId
agent.suppliername = usertobeInserted.suppliername
agent.name = usertobeInserted.name; agent.name = usertobeInserted.name;
agent.phone = usertobeInserted.phone; agent.phone = usertobeInserted.phone;
agent.alternativeContactNumber = usertobeInserted.alternativeContactNumber; agent.alternativeContactNumber = usertobeInserted.alternativeContactNumber;
@ -96,12 +101,15 @@ exports.orderNow = async (req, reply) => {
agent.state = usertobeInserted.state agent.state = usertobeInserted.state
agent.zip = usertobeInserted.zip agent.zip = usertobeInserted.zip
agent.status = usertobeInserted.status agent.status = usertobeInserted.status
agent.longitude = usertobeInserted.longitude
agent.latitude = usertobeInserted.latitude
} }
} }
const insertedagent = await agent.save(); const insertedagent = await agent.save();
console.log("inster...", insertedagent)
return insertedagent; return insertedagent;

@ -1,5 +1,5 @@
//const Tank = require("../models/tanks"); //const Tank = require("../models/tanks");
const { Tank, MotorData } = require('../models/tanks') const { Tank, MotorData, IotData } = require('../models/tanks')
const User = require("../models/User"); const User = require("../models/User");
const boom = require("boom"); const boom = require("boom");
@ -655,3 +655,40 @@ if(shape==="horizontalellipse"){
throw boom.boomify(err); throw boom.boomify(err);
} }
}; };
exports.IotDevice = async (req, reply) => {
try {
const { hardwareId, tankHeight, maxLevel, minLevel, mode } = req.body;
// create a new tank document
const tank = new IotData({ hardwareId, tankHeight, maxLevel, minLevel, mode });
// save the document to MongoDB
await tank.save();
// send a success response
reply.code(200).send({ message: 'Data saved successfully' });
} catch (err) {
// send an error response
reply.code(500).send({ error: err.message });
}
}
exports.getIotD = async(req, reply) => {
try {
await IotData.find({hardwareId: req.query.hardwareId})
.exec()
.then((docs) => {
reply.send({ status_code: 200, data: docs, count: docs.length });
})
.catch((err) => {
console.log(err);
reply.send({ error: err });
});
} catch (err) {
throw boom.boomify(err);
}
}

@ -191,6 +191,8 @@ exports.addUser = async (req, reply) => {
zip: req.body.zip, zip: req.body.zip,
notes: req.body.notes, notes: req.body.notes,
}, },
longitude: req.body.longitude,
latitude:req.body.latitude,
}; };
@ -214,6 +216,8 @@ exports.addUser = async (req, reply) => {
user.buildingName = usertobeInserted.buildingName; user.buildingName = usertobeInserted.buildingName;
user.inchargeName = usertobeInserted.inchargeName; user.inchargeName = usertobeInserted.inchargeName;
user.customerId = usertobeInserted.customer_id; user.customerId = usertobeInserted.customer_id;
user.latitude = usertobeInserted.latitude;
user.longitude = usertobeInserted.longitude
} }
@ -252,6 +256,8 @@ exports.addUser = async (req, reply) => {
}, },
], ],
profile: insertedUser.profile, profile: insertedUser.profile,
longitude: insertedUser.longitude,
latitude:insertedUser.latitude,
}, },
status_code: 200, status_code: 200,
}; };

@ -238,6 +238,33 @@ exports.loginSupplier = async(request, reply) =>{
//Login Delivery Handler //Login Delivery Handler
exports.loginDeliveryBoy = async(request, reply) =>{ exports.loginDeliveryBoy = async(request, reply) =>{
phone = request.body.phone;
phoneVerificationCode = request.body.phoneVerificationCode;
// check if user exists in the system. If user exists , display message that
// username is not available
console.log(
"this is the phone and verification code",
phone,
phoneVerificationCode
);
deliveryBoyExists = await DeliveryBoy.findOne({
phone: phone,
phoneVerified: false,
phoneVerificationCode: phoneVerificationCode,
});
console.log(deliveryBoyExists);
if (deliveryBoyExists) {
// update the phoneVerified flag to true.
const filter = {
phone: phone,
phoneVerificationCode: phoneVerificationCode,
};
const update = { phoneVerified: true };
const doc = await DeliveryBoy.findOneAndUpdate(filter, update);
updatedDeliveryBoy = await DeliveryBoy.findOne({ phone: phone });
}
loginObject = await supplierController.loginDeliveryBoy(request); loginObject = await supplierController.loginDeliveryBoy(request);
console.log("loginObject...",loginObject) console.log("loginObject...",loginObject)
if (loginObject.same) { if (loginObject.same) {
@ -308,7 +335,10 @@ exports.loginDeliveryBoy = async(request, reply) =>{
address: loginObject.delivery.address, address: loginObject.delivery.address,
phoneVerified: loginObject.delivery.phoneVerified, phoneVerified: loginObject.delivery.phoneVerified,
oneTimePasswordSetFlag: loginObject.delivery.oneTimePasswordSetFlag, oneTimePasswordSetFlag: loginObject.delivery.oneTimePasswordSetFlag,
supplierId: loginObject.delivery.supplierId,
suppliername: loginObject.delivery.suppliername,
longitude:loginObject.delivery. longitude,
latitude:loginObject.delivery.latitude,
}, },
}); });
}if (profilePicture) { }if (profilePicture) {
@ -324,6 +354,10 @@ exports.loginDeliveryBoy = async(request, reply) =>{
address: loginObject.delivery.address, address: loginObject.delivery.address,
phoneVerified: loginObject.delivery.phoneVerified, phoneVerified: loginObject.delivery.phoneVerified,
oneTimePasswordSetFlag: loginObject.delivery.oneTimePasswordSetFlag, oneTimePasswordSetFlag: loginObject.delivery.oneTimePasswordSetFlag,
supplierId: loginObject.delivery.supplierId,
suppliername: loginObject.delivery.suppliername,
longitude:loginObject.delivery. longitude,
latitude:loginObject.delivery.latitude,
}, },
}); });
} }
@ -677,16 +711,6 @@ exports.logoutsupplier = async (request, reply) => {
req.body.regError = error; req.body.regError = error;
reply.send(error); reply.send(error);
} }
} else {
error = {
armintatankdata: {
error: true,
code: 10005,
message: "10005 - Verification code entered cannot be validated.",
},
};
req.body.regError = error;
reply.send(error);
} }
} catch (err) { } catch (err) {
throw boom.boomify(err); throw boom.boomify(err);

@ -222,6 +222,8 @@ fastify.post("/api/login", {
address2: loginObject.user.profile.address2, address2: loginObject.user.profile.address2,
phoneVerified: loginObject.user.phoneVerified, phoneVerified: loginObject.user.phoneVerified,
oneTimePasswordSetFlag: loginObject.user.oneTimePasswordSetFlag, oneTimePasswordSetFlag: loginObject.user.oneTimePasswordSetFlag,
latitude: loginObject.user.latitude,
longitude: loginObject.user.longitude,
type: loginObject.user.profile.role, type: loginObject.user.profile.role,
typeasobj: stringToJsonObject, typeasobj: stringToJsonObject,
}, },
@ -241,6 +243,8 @@ fastify.post("/api/login", {
address2: loginObject.user.profile.address2, address2: loginObject.user.profile.address2,
phoneVerified: loginObject.user.phoneVerified, phoneVerified: loginObject.user.phoneVerified,
oneTimePasswordSetFlag: loginObject.user.oneTimePasswordSetFlag, oneTimePasswordSetFlag: loginObject.user.oneTimePasswordSetFlag,
latitude: loginObject.user.latitude,
longitude: loginObject.user.longitude,
type: loginObject.user.profile.role, type: loginObject.user.profile.role,
typeasobj: stringToJsonObject, typeasobj: stringToJsonObject,
}, },

@ -91,6 +91,8 @@ const userSchema = new mongoose.Schema(
coordinates: { type: [Number], default: [0, 0] }, coordinates: { type: [Number], default: [0, 0] },
}, },
longitude: { type : Number},
latitude: {type: Number},
isActive: Boolean, isActive: Boolean,
tenantId: ObjectId, tenantId: ObjectId,
createdAt: { createdAt: {

@ -108,6 +108,7 @@ const supplierSchema = new mongoose.Schema(
const deliveryBoySchema = new mongoose.Schema({ const deliveryBoySchema = new mongoose.Schema({
supplierId:{ type: String, default: null }, supplierId:{ type: String, default: null },
suppliername:{ type: String, default: null },
name: { type: String, default: null }, name: { type: String, default: null },
phone: { type: String, default: null,unique:true }, phone: { type: String, default: null,unique:true },
alternativeContactNumber : { type : String,default: null }, alternativeContactNumber : { type : String,default: null },
@ -121,6 +122,8 @@ const supplierSchema = new mongoose.Schema(
zip: { type: String, default: null }, zip: { type: String, default: null },
timestamp: { type: Date, default: Date.now }, timestamp: { type: Date, default: Date.now },
status: { type: String, default: "Inactive" }, status: { type: String, default: "Inactive" },
longitude: { type : Number},
latitude: {type: Number},
}); });

@ -39,9 +39,21 @@ const motordataSchema = new mongoose.Schema({
}); });
const IOttankSchema = new mongoose.Schema({
hardwareId: { type: String, required: true },
tankHeight: { type: String, required: true },
maxLevel: { type: String, required: true },
minLevel: { type: String, required: true },
mode: { type: Number, required: true }
});
const Tank = mongoose.model("Tank", tanksSchema); const Tank = mongoose.model("Tank", tanksSchema);
const MotorData = mongoose.model("MotorData", motordataSchema); const MotorData = mongoose.model("MotorData", motordataSchema);
const IotData = mongoose.model("IotData", IOttankSchema);
module.exports = { module.exports = {
Tank, MotorData Tank, MotorData,IotData
} }

@ -77,6 +77,7 @@ module.exports = function (fastify, opts, next) {
body: { body: {
type: "object", type: "object",
properties: { properties: {
suppliername: { type: "string"},
Name: { type: "string" }, Name: { type: "string" },
phone: { type: "string" }, phone: { type: "string" },
alternativeContactNumber : { type : "string" }, alternativeContactNumber : { type : "string" },
@ -85,7 +86,8 @@ module.exports = function (fastify, opts, next) {
state: { type: "string", default: null }, state: { type: "string", default: null },
zip: { type: "string", default: null }, zip: { type: "string", default: null },
status: { type: "string" }, status: { type: "string" },
latitude: { type: 'number' },
longitude: { type: 'number'}
}, },
}, },

@ -161,6 +161,7 @@ module.exports = function (fastify, opts, next) {
type: "object", type: "object",
required: ["phone"], required: ["phone"],
properties: { properties: {
phoneVerificationCode: { type: "string" },
phone: { type: "string" }, phone: { type: "string" },
}, },
}, },

@ -298,6 +298,41 @@ module.exports = function (fastify, opts, next) {
width: { type: "string", default: null }, width: { type: "string", default: null },
height: { type: "string" }, height: { type: "string" },
diameter:{ type: "string" }, diameter:{ type: "string" },
},
},
security: [
{
basicAuth: [],
},
],
},
// preHandler: [
// fastify.auth([fastify.operatorAuthenticate]),
// validationHandler.validatePhoneFormat,
// ],
preHandler: fastify.auth([fastify.authenticate]),
handler: tanksController.calculateCapacity,
});
fastify.route({
method: "POST",
url: "/api/APIWrite",
schema: {
tags: ["Tank"],
description: "This is for cretae IOT Device",
summary: "This is for Create IOT Device.",
body: {
type: "object",
properties: {
hardwareId: { type: "string" },
tankHeight: { type: "string"},
maxLevel: { type: "string" },
minLevel: { type: "string" },
mode: { type: "string" },
}, },
}, },
security: [ security: [
@ -310,10 +345,31 @@ module.exports = function (fastify, opts, next) {
// fastify.auth([fastify.operatorAuthenticate]), // fastify.auth([fastify.operatorAuthenticate]),
// validationHandler.validatePhoneFormat, // validationHandler.validatePhoneFormat,
// ], // ],
preHandler: fastify.auth([fastify.authenticate]),
handler: tanksController.calculateCapacity,
handler: tanksController.IotDevice,
}); });
fastify.get("/api/APIRead", {
schema: {
tags: ["Tank"],
description: "This is for Get IOT Data",
summary: "This is for to Get IOT Data",
querystring: {
hardwareId: {type: 'string'}
},
security: [
{
basicAuth: [],
},
],
},
preHandler: fastify.auth([fastify.authenticate]),
handler: tanksController.getIotD,
});
next(); next();

@ -155,6 +155,8 @@ module.exports = function (fastify, opts, next) {
zip: { type: "string", default: null }, zip: { type: "string", default: null },
country: { type: "string", default: null }, country: { type: "string", default: null },
notes: { type: "string", default: null }, notes: { type: "string", default: null },
latitude: { type: 'number' },
longitude: { type: 'number'}
}, },
}, },
security: [ security: [

Loading…
Cancel
Save