|
|
|
@ -5,6 +5,7 @@ const { User,Counter, generateBookingId,resetCounter,generateCustomerId,ProfileP
|
|
|
|
|
const tankersController = require("./controllers/tankersController.js");
|
|
|
|
|
const createConnectionController = require("./controllers/createConnectionController");
|
|
|
|
|
const storeController = require("./controllers/storeController.js")
|
|
|
|
|
const boom = require("boom");
|
|
|
|
|
|
|
|
|
|
const cors = require("cors");
|
|
|
|
|
const swagger = require("./config/swagger");
|
|
|
|
@ -291,24 +292,37 @@ fastify.post("/api/installotplogin", {
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
async handler(req, reply) {
|
|
|
|
|
const { phone, phoneVerificationCode } = req.body;
|
|
|
|
|
try {
|
|
|
|
|
const phone = req.body.phone;
|
|
|
|
|
const phoneVerificationCode = req.body.phoneVerificationCode;
|
|
|
|
|
|
|
|
|
|
// Assuming loginUserInstall function exists and works properly
|
|
|
|
|
try{
|
|
|
|
|
const installationExists = await Install.findOne({
|
|
|
|
|
phone: phone,
|
|
|
|
|
phoneVerificationCode: phoneVerificationCode,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const loginObject = await userController.loginUserWithOTP(req);
|
|
|
|
|
if (installationExists) {
|
|
|
|
|
const filter = {
|
|
|
|
|
phone: phone,
|
|
|
|
|
phoneVerificationCode: phoneVerificationCode,
|
|
|
|
|
};
|
|
|
|
|
const update = { phoneVerified: true };
|
|
|
|
|
await Install.findOneAndUpdate(filter, update);
|
|
|
|
|
|
|
|
|
|
const loginObject = await userController.loginUserWithOTP(req);
|
|
|
|
|
|
|
|
|
|
if (loginObject.same) {
|
|
|
|
|
const phoneVerified = loginObject.user.phoneVerified;
|
|
|
|
|
const oneTimePasswordSetFlag = loginObject.user.oneTimePasswordSetFlag;
|
|
|
|
|
if (loginObject.user) {
|
|
|
|
|
const { user } = loginObject;
|
|
|
|
|
const phoneVerified = user.phoneVerified;
|
|
|
|
|
const oneTimePasswordSetFlag = user.oneTimePasswordSetFlag;
|
|
|
|
|
|
|
|
|
|
if (!phoneVerified) {
|
|
|
|
|
reply.send({
|
|
|
|
|
simplydata: {
|
|
|
|
|
error: false,
|
|
|
|
|
phoneVerified: false,
|
|
|
|
|
phone: loginObject.user.phone,
|
|
|
|
|
phone: user.phone,
|
|
|
|
|
oneTimePasswordSetFlag: oneTimePasswordSetFlag,
|
|
|
|
|
message: "Please Verify your phone number",
|
|
|
|
|
},
|
|
|
|
@ -318,7 +332,7 @@ fastify.post("/api/installotplogin", {
|
|
|
|
|
simplydata: {
|
|
|
|
|
error: false,
|
|
|
|
|
phoneVerified: phoneVerified,
|
|
|
|
|
phone: loginObject.user.phone,
|
|
|
|
|
phone: user.phone,
|
|
|
|
|
oneTimePasswordSetFlag: true,
|
|
|
|
|
message: "Password must be reset",
|
|
|
|
|
},
|
|
|
|
@ -326,32 +340,35 @@ fastify.post("/api/installotplogin", {
|
|
|
|
|
} else {
|
|
|
|
|
const token = fastify.jwt.sign(
|
|
|
|
|
{
|
|
|
|
|
name: loginObject.user.name,
|
|
|
|
|
name: user.name,
|
|
|
|
|
},
|
|
|
|
|
'your_jwt_secret', // Replace with your actual JWT secret
|
|
|
|
|
{ expiresIn: '30d' }
|
|
|
|
|
{ expiresIn: "30d" }
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const profilePicture = await ProfilePictureInstall.findOne({ customerId: loginObject.user._id });
|
|
|
|
|
const profilePicture = await ProfilePictureInstall.findOne({
|
|
|
|
|
customerId: user._id,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const responsePayload = {
|
|
|
|
|
simplydata: {
|
|
|
|
|
error: false,
|
|
|
|
|
apiversion: fastify.config.APIVERSION,
|
|
|
|
|
access_token: token,
|
|
|
|
|
email: loginObject.user.emails,
|
|
|
|
|
phone: loginObject.user.phone,
|
|
|
|
|
name: loginObject.user.name,
|
|
|
|
|
address1: loginObject.user.profile.address1,
|
|
|
|
|
address2: loginObject.user.profile.address2,
|
|
|
|
|
phoneVerified: loginObject.user.phoneVerified,
|
|
|
|
|
oneTimePasswordSetFlag: loginObject.user.oneTimePasswordSetFlag,
|
|
|
|
|
type: loginObject.user.profile.role,
|
|
|
|
|
fcmId: loginObject.user.fcmId,
|
|
|
|
|
team: loginObject.user.team,
|
|
|
|
|
city:loginObject.user.city,
|
|
|
|
|
manager:loginObject.user.manager,
|
|
|
|
|
// typeasobj: JSON.parse(loginObject.user.profile.role),
|
|
|
|
|
email: user.emails,
|
|
|
|
|
phone: user.phone,
|
|
|
|
|
name: user.name,
|
|
|
|
|
address1: user.profile.address1,
|
|
|
|
|
address2: user.profile.address2,
|
|
|
|
|
phoneVerified: user.phoneVerified,
|
|
|
|
|
oneTimePasswordSetFlag: user.oneTimePasswordSetFlag,
|
|
|
|
|
type: user.profile.role,
|
|
|
|
|
fcmId: user.fcmId,
|
|
|
|
|
team: user.team,
|
|
|
|
|
city: user.city,
|
|
|
|
|
manager: user.manager,
|
|
|
|
|
firstName: user.firstName,
|
|
|
|
|
lastName: user.lastName,
|
|
|
|
|
alternativeNumber: user.alternativeNumber,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -361,6 +378,15 @@ fastify.post("/api/installotplogin", {
|
|
|
|
|
|
|
|
|
|
reply.send(responsePayload);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
reply.send({
|
|
|
|
|
simplydata: {
|
|
|
|
|
error: true,
|
|
|
|
|
code: 400,
|
|
|
|
|
message: "Invalid Details",
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
reply.send({
|
|
|
|
|
simplydata: {
|
|
|
|
@ -370,8 +396,17 @@ fastify.post("/api/installotplogin", {
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}catch(e){
|
|
|
|
|
console.log('errrorrrr',e)
|
|
|
|
|
} else {
|
|
|
|
|
reply.send({
|
|
|
|
|
armintatankdata: {
|
|
|
|
|
error: true,
|
|
|
|
|
code: 10005,
|
|
|
|
|
message: "10005 - Verification code entered cannot be validated.",
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
@ -462,7 +497,7 @@ fastify.register(require("./routes/forTestingRoute"));
|
|
|
|
|
const {Storage} = require('@google-cloud/storage');
|
|
|
|
|
const { Supplier, profilePictureSupplier } = require("./models/supplier");
|
|
|
|
|
const multer = require('fastify-multer');
|
|
|
|
|
const { ProfilePictureInstall } = require("./models/store.js");
|
|
|
|
|
const { ProfilePictureInstall, Install } = require("./models/store.js");
|
|
|
|
|
fastify.register(require('fastify-formbody'));
|
|
|
|
|
// fastify.register(multer.contentParser);
|
|
|
|
|
// const multipart = require('fastify-multipart');
|
|
|
|
|