|
|
@ -1,7 +1,7 @@
|
|
|
|
const boom = require("boom");
|
|
|
|
const boom = require("boom");
|
|
|
|
const bcrypt = require('bcrypt');
|
|
|
|
const bcrypt = require('bcrypt');
|
|
|
|
const jwt = require('jsonwebtoken');
|
|
|
|
const jwt = require('jsonwebtoken');
|
|
|
|
|
|
|
|
const customJwtAuth = require("../customAuthJwt");
|
|
|
|
const fastify = require("fastify")({
|
|
|
|
const fastify = require("fastify")({
|
|
|
|
logger: true,
|
|
|
|
logger: true,
|
|
|
|
//disableRequestLogging: true,
|
|
|
|
//disableRequestLogging: true,
|
|
|
@ -9,9 +9,10 @@ const fastify = require("fastify")({
|
|
|
|
// you get access to the req here if you need it - must be a synchronous function
|
|
|
|
// you get access to the req here if you need it - must be a synchronous function
|
|
|
|
return uuidv4();
|
|
|
|
return uuidv4();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});const { Install, ProfilePictureInstall, generateinstallationId } = require("../models/store");
|
|
|
|
});
|
|
|
|
|
|
|
|
const { Install, ProfilePictureInstall, generateinstallationId,Store} = require("../models/store");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const supplierController = require("../controllers/supplierController")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -316,3 +317,185 @@ exports.installSignUp = async (request, reply) => {
|
|
|
|
throw boom.boomify(err);
|
|
|
|
throw boom.boomify(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const generateStoreId = async () => {
|
|
|
|
|
|
|
|
const result = await Counter.findOneAndUpdate(
|
|
|
|
|
|
|
|
{ _id: 'store_id' },
|
|
|
|
|
|
|
|
{ $inc: { seq: 1 } },
|
|
|
|
|
|
|
|
{ upsert: true, new: true }
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
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}`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var store = new Store(s_data);
|
|
|
|
|
|
|
|
storepass = req.body.password;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Store hash in your password DB.
|
|
|
|
|
|
|
|
hash = await bcryptPassword(storepass);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (hash) {
|
|
|
|
|
|
|
|
store.services.password.bcrypt = hash;
|
|
|
|
|
|
|
|
if (req.body.role) {
|
|
|
|
|
|
|
|
store.profile.role = req.body.role;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
role = ["store"];
|
|
|
|
|
|
|
|
store.profile.role = role;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return retStore;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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,
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|