|
|
|
@ -10,7 +10,9 @@ const fastify = require("fastify")({
|
|
|
|
|
return uuidv4();
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
const { Install, ProfilePictureInstall, generateinstallationId,Store} = require("../models/store");
|
|
|
|
|
const { Install, ProfilePictureInstall, generateinstallationId,Store,WaterLeverSensor} = require("../models/store");
|
|
|
|
|
const { User,Counter, generateBookingId,resetCounter,generateCustomerId,ProfilePicture} = require('../models/User')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -403,99 +405,35 @@ exports.installSignUp = async (request, reply) => {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const generatewaterlevelsensorId = async () => {
|
|
|
|
|
const result = await Counter.findOneAndUpdate(
|
|
|
|
|
{ _id: 'waterlevelsensor_id' },
|
|
|
|
|
{ $inc: { seq: 1 } },
|
|
|
|
|
{ upsert: true, new: true }
|
|
|
|
|
);
|
|
|
|
|
return result.seq;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// exports.loginStore = async (request, reply) => {
|
|
|
|
|
// try {
|
|
|
|
|
// let store = await Store.findOne({ phone: request.body.phone });
|
|
|
|
|
// if (!store) {
|
|
|
|
|
// return reply.code(400).send({
|
|
|
|
|
// simplydata: {
|
|
|
|
|
// error: true,
|
|
|
|
|
// code: 400,
|
|
|
|
|
// message: "Invalid Phone or Password",
|
|
|
|
|
// },
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// const isMatch = await bcrypt.compare(request.body.password, store.services.password.bcrypt);
|
|
|
|
|
// if (!isMatch) {
|
|
|
|
|
// return reply.code(400).send({
|
|
|
|
|
// simplydata: {
|
|
|
|
|
// error: true,
|
|
|
|
|
// code: 400,
|
|
|
|
|
// message: "Invalid Phone or Password",
|
|
|
|
|
// },
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// const token = request.jwt.sign(
|
|
|
|
|
// {
|
|
|
|
|
// storename: store.storename,
|
|
|
|
|
// storeId: store._id,
|
|
|
|
|
// roles: store.profile.role,
|
|
|
|
|
// },
|
|
|
|
|
// { expiresIn: "30d" }
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
// var profilePicture = await profilePictureStore.findOne({ storeId: store.storeId });
|
|
|
|
|
|
|
|
|
|
// if (!profilePicture) {
|
|
|
|
|
// reply.send({
|
|
|
|
|
// simplydata: {
|
|
|
|
|
// error: false,
|
|
|
|
|
// apiversion: fastify.config.APIVERSION,
|
|
|
|
|
// access_token: token,
|
|
|
|
|
// email: store.emails,
|
|
|
|
|
// phone: store.phone,
|
|
|
|
|
// storeId: store.storeId,
|
|
|
|
|
// storename: store.storename,
|
|
|
|
|
// office_address: store.profile.office_address,
|
|
|
|
|
// phoneVerified: store.phoneVerified,
|
|
|
|
|
// oneTimePasswordSetFlag: store.oneTimePasswordSetFlag,
|
|
|
|
|
// latitude: store.latitude,
|
|
|
|
|
// longitude: store.longitude,
|
|
|
|
|
// description: store.description,
|
|
|
|
|
// type: store.profile.role,
|
|
|
|
|
// typeasobj: JSON.stringify(Object.assign({}, store.profile.role)),
|
|
|
|
|
// },
|
|
|
|
|
// });
|
|
|
|
|
// } else {
|
|
|
|
|
// reply.send({
|
|
|
|
|
// simplydata: {
|
|
|
|
|
// error: false,
|
|
|
|
|
// apiversion: fastify.config.APIVERSION,
|
|
|
|
|
// access_token: token,
|
|
|
|
|
// picture: profilePicture.picture,
|
|
|
|
|
// email: store.emails,
|
|
|
|
|
// phone: store.phone,
|
|
|
|
|
// storeId: store.storeId,
|
|
|
|
|
// storename: store.storename,
|
|
|
|
|
// office_address: store.profile.office_address,
|
|
|
|
|
// phoneVerified: store.phoneVerified,
|
|
|
|
|
// oneTimePasswordSetFlag: store.oneTimePasswordSetFlag,
|
|
|
|
|
// latitude: store.latitude,
|
|
|
|
|
// longitude: store.longitude,
|
|
|
|
|
// description: store.description,
|
|
|
|
|
// type: store.profile.role,
|
|
|
|
|
// typeasobj: JSON.stringify(Object.assign({}, store.profile.role)),
|
|
|
|
|
// },
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
// } catch (err) {
|
|
|
|
|
// reply.send({
|
|
|
|
|
// simplydata: {
|
|
|
|
|
// error: true,
|
|
|
|
|
// code: 500,
|
|
|
|
|
// message: err.message,
|
|
|
|
|
// },
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const moment = require('moment');
|
|
|
|
|
exports.createwaterlevelSensor = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { hardwareId,hardwareId_company, type, indate } = 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({
|
|
|
|
|
hardwareId,
|
|
|
|
|
masterId,
|
|
|
|
|
type,
|
|
|
|
|
indate
|
|
|
|
|
});
|
|
|
|
|
const savedSensor = await newSensor.save();
|
|
|
|
|
reply.code(201).send(savedSensor);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
reply.code(500).send(err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|