|
|
|
@ -329,81 +329,164 @@ exports.installSignUp = async (request, reply) => {
|
|
|
|
|
);
|
|
|
|
|
return result.seq;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.addStore = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
var s_id = await generateStoreId();
|
|
|
|
|
var building = ((req.body.storename).slice(0, 3)).toUpperCase();
|
|
|
|
|
var store_id = `AWSST${building}${s_id}`;
|
|
|
|
|
const saltRounds = 10;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function bcryptPassword(password) {
|
|
|
|
|
encryptedPwd = bcrypt.hash(password, saltRounds);
|
|
|
|
|
return encryptedPwd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 = {
|
|
|
|
|
storeId: store_id,
|
|
|
|
|
storename: req.body.storename,
|
|
|
|
|
emails: req.body.emails,
|
|
|
|
|
password: req.body.password,
|
|
|
|
|
phone: req.body.phone,
|
|
|
|
|
description: req.body.description,
|
|
|
|
|
profile: {
|
|
|
|
|
firstName: req.body.firstName,
|
|
|
|
|
lastName: req.body.lastName,
|
|
|
|
|
contactNumber: req.body.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,
|
|
|
|
|
};
|
|
|
|
|
longitude,
|
|
|
|
|
latitude,
|
|
|
|
|
fcmId,
|
|
|
|
|
alternativeNumber,
|
|
|
|
|
firstName,
|
|
|
|
|
lastName,
|
|
|
|
|
city,
|
|
|
|
|
createdBy,
|
|
|
|
|
updatedBy,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Save the new install to the database
|
|
|
|
|
await store.save();
|
|
|
|
|
|
|
|
|
|
reply.send({ message: 'Install Account Created Successfully' });
|
|
|
|
|
} catch (err) {
|
|
|
|
|
reply.status(500).send({ message: err.message });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// exports.addStore = async (req, reply) => {
|
|
|
|
|
// try {
|
|
|
|
|
// const { storename, password, phone, emails } = req.body;
|
|
|
|
|
|
|
|
|
|
var store = new Store(s_data);
|
|
|
|
|
storepass = req.body.password;
|
|
|
|
|
// if (!emails) {
|
|
|
|
|
// return reply.status(400).send({ error: 'Email is required and cannot be null.' });
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// Store hash in your password DB.
|
|
|
|
|
hash = await bcryptPassword(storepass);
|
|
|
|
|
// var s_id = await generateStoreId();
|
|
|
|
|
// var building = storename.slice(0, 3).toUpperCase();
|
|
|
|
|
// var store_id = `AWSST${building}${s_id}`;
|
|
|
|
|
|
|
|
|
|
if (hash) {
|
|
|
|
|
store.services.password.bcrypt = hash;
|
|
|
|
|
if (req.body.role) {
|
|
|
|
|
store.profile.role = req.body.role;
|
|
|
|
|
} else {
|
|
|
|
|
role = ["store"];
|
|
|
|
|
store.profile.role = role;
|
|
|
|
|
}
|
|
|
|
|
// const s_data = {
|
|
|
|
|
// storeId: store_id,
|
|
|
|
|
// storename,
|
|
|
|
|
// emails: emails.trim(),
|
|
|
|
|
// password,
|
|
|
|
|
// phone,
|
|
|
|
|
// 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();
|
|
|
|
|
if (insertedStore) {
|
|
|
|
|
var retStore = {
|
|
|
|
|
armintatankdata: {
|
|
|
|
|
storename: insertedStore.storename,
|
|
|
|
|
phone: insertedStore.phone,
|
|
|
|
|
storeId: insertedStore.storeId,
|
|
|
|
|
office_address: insertedStore.profile.office_address,
|
|
|
|
|
emails: [
|
|
|
|
|
{
|
|
|
|
|
email: insertedStore.emails[0].email,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
profile: insertedStore.profile,
|
|
|
|
|
latitude: insertedStore.latitude,
|
|
|
|
|
longitude: insertedStore.longitude,
|
|
|
|
|
fcmId: insertedStore.fcmId,
|
|
|
|
|
description: insertedStore.description,
|
|
|
|
|
},
|
|
|
|
|
status_code: 200,
|
|
|
|
|
};
|
|
|
|
|
// var store = new Store(s_data);
|
|
|
|
|
// var storepass = password;
|
|
|
|
|
|
|
|
|
|
// // Store hash in your password DB.
|
|
|
|
|
// var hash = await bcryptPassword(storepass);
|
|
|
|
|
|
|
|
|
|
// if (hash) {
|
|
|
|
|
// store.services.password.bcrypt = hash;
|
|
|
|
|
// store.profile.role = req.body.role || ["store"];
|
|
|
|
|
|
|
|
|
|
// var insertedStore = await Store.save();
|
|
|
|
|
// if (insertedStore) {
|
|
|
|
|
// var retStore = {
|
|
|
|
|
// armintatankdata: {
|
|
|
|
|
// storename: insertedStore.storename,
|
|
|
|
|
// phone: insertedStore.phone,
|
|
|
|
|
// storeId: insertedStore.storeId,
|
|
|
|
|
// office_address: insertedStore.profile.office_address,
|
|
|
|
|
// emails: insertedStore.emails,
|
|
|
|
|
// 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 result = await Counter.findOneAndUpdate(
|
|
|
|
@ -417,12 +500,13 @@ exports.installSignUp = async (request, reply) => {
|
|
|
|
|
const moment = require('moment');
|
|
|
|
|
exports.createwaterlevelSensor = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { hardwareId,hardwareId_company, type, indate } = req.body;
|
|
|
|
|
const { hardwareId,hardwareId_company, type, indate,storeId } = req.body;
|
|
|
|
|
var mater_seq_id = await generatewaterlevelsensorId();
|
|
|
|
|
const date = moment().format('MM-DD');
|
|
|
|
|
const prefix = 'AS-' + date + '--MALOV1-';
|
|
|
|
|
var masterId = `${prefix}${mater_seq_id}`;
|
|
|
|
|
const newSensor = new WaterLeverSensor({
|
|
|
|
|
storeId,
|
|
|
|
|
hardwareId,
|
|
|
|
|
masterId,
|
|
|
|
|
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' });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|