waterlevel sensors

master
varun 1 year ago
parent cec367205d
commit 3af54baf9e

@ -329,81 +329,164 @@ exports.installSignUp = async (request, reply) => {
); );
return result.seq; return result.seq;
}; };
const saltRounds = 10;
exports.addStore = async (req, reply) => {
try { async function bcryptPassword(password) {
var s_id = await generateStoreId(); encryptedPwd = bcrypt.hash(password, saltRounds);
var building = ((req.body.storename).slice(0, 3)).toUpperCase(); return encryptedPwd;
var store_id = `AWSST${building}${s_id}`; }
async function bcryptComparePassword(pwd, encpassword) {
isSame = bcrypt.compare(pwd, encpassword);
return isSame;
}
exports.addStore = async (request, reply) => {
try {
const s_id = await generateStoreId();
const store_id = `AWIN${s_id}`;
const {
// name,
phone,
address,
address1,
address2,
emails,
password,
profile,
longitude,
latitude,
fcmId,
alternativeNumber,
firstName,
lastName,
city,
createdBy,
updatedBy,
} = request.body;
// Check if a user with the same phone number already exists
const existingStore = await Store.findOne({ phone });
if (existingStore) {
return reply.status(400).send({ message: 'Phone is already registered' });
}
// Hash the password using bcrypt
const hashedPassword = await bcrypt.hash(password, 10);
// Create a new install object with the hashed password and other details
const store = new Store({
// name,
store_id,
phone,
address,
address1,
address2,
emails,
services: { password: { bcrypt: hashedPassword } },
profile,
s_data = { longitude,
storeId: store_id, latitude,
storename: req.body.storename, fcmId,
emails: req.body.emails, alternativeNumber,
password: req.body.password, firstName,
phone: req.body.phone, lastName,
description: req.body.description, city,
profile: { createdBy,
firstName: req.body.firstName, updatedBy,
lastName: req.body.lastName, });
contactNumber: req.body.phone,
alternativeContactNumber: req.body.alternativeContactNumber, // Save the new install to the database
office_address: req.body.office_address, await store.save();
country: req.body.country,
state: req.body.state, reply.send({ message: 'Install Account Created Successfully' });
city: req.body.city, } catch (err) {
zip: req.body.zip, reply.status(500).send({ message: err.message });
}, }
latitude: req.body.latitude, }
longitude: req.body.longitude,
fcmId: req.body.fcmId,
}; // exports.addStore = async (req, reply) => {
// try {
// const { storename, password, phone, emails } = req.body;
var store = new Store(s_data); // if (!emails) {
storepass = req.body.password; // return reply.status(400).send({ error: 'Email is required and cannot be null.' });
// }
// Store hash in your password DB. // var s_id = await generateStoreId();
hash = await bcryptPassword(storepass); // var building = storename.slice(0, 3).toUpperCase();
// var store_id = `AWSST${building}${s_id}`;
if (hash) { // const s_data = {
store.services.password.bcrypt = hash; // storeId: store_id,
if (req.body.role) { // storename,
store.profile.role = req.body.role; // emails: emails.trim(),
} else { // password,
role = ["store"]; // phone,
store.profile.role = role; // description: req.body.description,
} // profile: {
// firstName: req.body.firstName,
// lastName: req.body.lastName,
// contactNumber: phone,
// alternativeContactNumber: req.body.alternativeContactNumber,
// office_address: req.body.office_address,
// country: req.body.country,
// state: req.body.state,
// city: req.body.city,
// zip: req.body.zip,
// },
// latitude: req.body.latitude,
// longitude: req.body.longitude,
// fcmId: req.body.fcmId,
// };
insertedStore = await store.save(); // var store = new Store(s_data);
if (insertedStore) { // var storepass = password;
var retStore = {
armintatankdata: { // // Store hash in your password DB.
storename: insertedStore.storename, // var hash = await bcryptPassword(storepass);
phone: insertedStore.phone,
storeId: insertedStore.storeId, // if (hash) {
office_address: insertedStore.profile.office_address, // store.services.password.bcrypt = hash;
emails: [ // store.profile.role = req.body.role || ["store"];
{
email: insertedStore.emails[0].email, // var insertedStore = await Store.save();
}, // if (insertedStore) {
], // var retStore = {
profile: insertedStore.profile, // armintatankdata: {
latitude: insertedStore.latitude, // storename: insertedStore.storename,
longitude: insertedStore.longitude, // phone: insertedStore.phone,
fcmId: insertedStore.fcmId, // storeId: insertedStore.storeId,
description: insertedStore.description, // office_address: insertedStore.profile.office_address,
}, // emails: insertedStore.emails,
status_code: 200, // profile: insertedStore.profile,
}; // latitude: insertedStore.latitude,
// longitude: insertedStore.longitude,
// fcmId: insertedStore.fcmId,
// description: insertedStore.description,
// },
// status_code: 200,
// };
// return reply.status(200).send(retStore);
// }
// }
// } catch (err) {
// if (err.code === 11000) {
// // Handle duplicate key error
// return reply.status(400).send({ error: 'Duplicate key error', message: err.message });
// }
// throw boom.boomify(err);
// }
// };
return retStore;
}
}
} catch (err) {
throw boom.boomify(err);
}
};
const generatewaterlevelsensorId = async () => { const generatewaterlevelsensorId = async () => {
const result = await Counter.findOneAndUpdate( const result = await Counter.findOneAndUpdate(
@ -417,12 +500,13 @@ exports.installSignUp = async (request, reply) => {
const moment = require('moment'); const moment = require('moment');
exports.createwaterlevelSensor = async (req, reply) => { exports.createwaterlevelSensor = async (req, reply) => {
try { try {
const { hardwareId,hardwareId_company, type, indate } = req.body; const { hardwareId,hardwareId_company, type, indate,storeId } = req.body;
var mater_seq_id = await generatewaterlevelsensorId(); var mater_seq_id = await generatewaterlevelsensorId();
const date = moment().format('MM-DD'); const date = moment().format('MM-DD');
const prefix = 'AS-' + date + '--MALOV1-'; const prefix = 'AS-' + date + '--MALOV1-';
var masterId = `${prefix}${mater_seq_id}`; var masterId = `${prefix}${mater_seq_id}`;
const newSensor = new WaterLeverSensor({ const newSensor = new WaterLeverSensor({
storeId,
hardwareId, hardwareId,
masterId, masterId,
type, type,
@ -436,4 +520,26 @@ exports.installSignUp = async (request, reply) => {
}; };
exports.qccheckwaterlevelSensor = async (request, reply) => {
try {
const { hardwareId } = request.params;
const updateData = request.body;
// Find the document by hardwareId and update it with the fields received in the body
const updatedSensor = await WaterLeverSensor.findOneAndUpdate(
{ hardwareId: hardwareId },
{ $set: updateData },
{ new: true } // Return the updated document
);
if (!updatedSensor) {
return reply.status(404).send({ error: 'Sensor not found' });
}
return reply.status(200).send(updatedSensor);
} catch (error) {
console.error(error);
return reply.status(500).send({ error: 'An error occurred while updating the sensor' });
}
};

@ -101,16 +101,21 @@ const installationschema = new mongoose.Schema({
} }
}); });
const storeSchema = new mongoose.Schema({ const storeSchema = new mongoose.Schema({
storename: { type: String }, storename: { type: String },
phone: { type: String, unique: true, trim: true }, phone: { type: String, unique: true, trim: true },
storeId: { type: String, default: null }, storeId: { type: String, default: null },
phoneVerified: { type: Boolean, default: false }, phoneVerified: { type: Boolean, default: false },
phoneVerificationCode: { type: Number, default: 11111 }, phoneVerificationCode: { type: Number, default: 11111 },
passwordResetCode: { type: Number, default: code }, passwordResetCode: { type: Number, default: 11111 },
oneTimePasswordSetFlag: { type: Boolean, default: false }, oneTimePasswordSetFlag: { type: Boolean, default: false },
emails: [{ email: String, verified: { type: Boolean, default: false } }], emails: { type: String, unique: true },
services: { password: { bcrypt: String } }, services: {
password: {
bcrypt: { type: String, required: true }
}
},
description: { type: String, default: null }, description: { type: String, default: null },
startingPrice: { type: String, default: 0.0 }, startingPrice: { type: String, default: 0.0 },
profile: { profile: {
@ -151,9 +156,16 @@ const installationschema = new mongoose.Schema({
updatedBy: ObjectId, updatedBy: ObjectId,
}, { versionKey: false }); }, { versionKey: false });
module.exports = mongoose.model('Store', storeSchema);
const waterLeverSensorInSchema = new mongoose.Schema({ const waterLeverSensorInSchema = new mongoose.Schema({
storeeId:{ type: String },
hardwareId: { type: String }, hardwareId: { type: String },
masterId: { type: String, default: null }, masterId: { type: String, default: null },
type: { type: String }, type: { type: String },

@ -98,21 +98,13 @@ fastify.post('/api/stores', {
summary: "This is for Create New Store.", summary: "This is for Create New Store.",
body: { body: {
type: "object", type: "object",
required: ["storename", "phone", "emails", "password"],
properties: { properties: {
storename: { type: "string" }, storename: { type: "string" },
phone: { type: "string" }, phone: { type: "string" },
alternativeContactNumber: { type: "string" }, alternativeContactNumber: { type: "string" },
password: { type: "string" }, password: { type: "string" },
emails: { emails: { type: "string" },
type: "array",
maxItems: 2,
items: {
type: "object",
properties: {
email: { type: "string", default: null },
},
},
},
office_address: { type: "string", default: null }, office_address: { type: "string", default: null },
city: { type: "string", default: null }, city: { type: "string", default: null },
state: { type: "string", default: null }, state: { type: "string", default: null },
@ -126,23 +118,22 @@ fastify.post('/api/stores', {
}, },
security: [{ basicAuth: [] }], security: [{ basicAuth: [] }],
}, },
// preHandler: [
// validationHandler.fieldCheck,
// validationHandler.verifyStore,
// validationHandler.validateEmailFormat,
// ],
handler: storeController.addStore, handler: storeController.addStore,
}); });
fastify.post("/api/createwaterlevelSensor", { fastify.post("/api/createwaterlevelSensor", {
schema: { schema: {
description: "This is for creating waterlevel Sensor", description: "This is for creating waterlevel Sensor",
tags: ["Store-Data"], tags: ["Store-Data"],
summary: "This is for creating waterlevel Sensor", summary: "This is for creating waterlevel Sensor",
body: { body: {
type: "object", type: "object",
properties: { properties: {
storeId: { type: "string" },
hardwareId: { type: "string" }, hardwareId: { type: "string" },
type: { type: "string" }, type: { type: "string" },
indate: { type: "string" }, indate: { type: "string" },
@ -153,5 +144,38 @@ fastify.post("/api/createwaterlevelSensor", {
handler: storeController.createwaterlevelSensor, handler: storeController.createwaterlevelSensor,
}) })
fastify.post("/api/qccheckwaterlevelSensor/:hardwareId", {
schema: {
description: "This is for checking waterlevel Sensor",
tags: ["Store-Data"],
summary: "This is for checking waterlevel Sensor",
params: {
required: ["hardwareId"],
type: "object",
properties: {
hardwareId: {
type: "string",
description: "hardwareId",
},
},
},
body: {
type: "object",
properties: {
qccheck: { type: "string" },
qccheckdate: { type: "string" },
qcby: { type: "string" },
comment: { type: "string" },
outforrepairdate: { type: "string" },
sendto: { type: "string" },
repairfeedback: { type: "string" },
},
},
},
handler: storeController.qccheckwaterlevelSensor,
})
next(); next();
}; };

Loading…
Cancel
Save