varun 1 year ago
commit f3798182d9

@ -13,7 +13,7 @@ const supplierController = require("../controllers/supplierController")
exports.installSignUp = async (request, reply) => { exports.installSignUp = async (request, reply) => {
try { try {
const { const {
name, //name,
phone, phone,
address, address,
installationId, installationId,
@ -25,15 +25,18 @@ exports.installSignUp = async (request, reply) => {
longitude, longitude,
latitude, latitude,
fcmId, fcmId,
alternativeNumber,
firstName,
lastName,
createdBy, createdBy,
updatedBy, updatedBy,
} = request.body; } = request.body;
// Check if the email address is valid // Check if the email address is valid
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; // const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (emails.some((emailObj) => !emailRegex.test(emailObj.email))) { // if (emails.some((emailObj) => !emailRegex.test(emailObj.email))) {
return reply.status(400).send({ message: 'Invalid email address' }); // return reply.status(400).send({ message: 'Invalid email address' });
} // }
// Check if a user with the same phone number already exists // Check if a user with the same phone number already exists
const existingInstall = await Install.findOne({ phone }); const existingInstall = await Install.findOne({ phone });
@ -46,7 +49,7 @@ exports.installSignUp = async (request, reply) => {
// Create a new install object with the hashed password and other details // Create a new install object with the hashed password and other details
const install = new Install({ const install = new Install({
name, //name,
phone, phone,
address, address,
installationId, installationId,
@ -58,8 +61,12 @@ exports.installSignUp = async (request, reply) => {
longitude, longitude,
latitude, latitude,
fcmId, fcmId,
alternativeNumber,
firstName,
lastName,
createdBy, createdBy,
updatedBy, updatedBy,
}); });
// Save the new install to the database // Save the new install to the database

@ -5,6 +5,7 @@ const { User,Counter, generateBookingId,resetCounter,generateCustomerId,ProfileP
const tankersController = require("./controllers/tankersController.js"); const tankersController = require("./controllers/tankersController.js");
const createConnectionController = require("./controllers/createConnectionController"); const createConnectionController = require("./controllers/createConnectionController");
const storeController = require("./controllers/storeController.js") const storeController = require("./controllers/storeController.js")
const boom = require("boom");
const cors = require("cors"); const cors = require("cors");
const swagger = require("./config/swagger"); const swagger = require("./config/swagger");
@ -291,88 +292,122 @@ fastify.post("/api/installotplogin", {
}, },
}, },
async handler(req, reply) { async handler(req, reply) {
const { phone, phoneVerificationCode } = req.body; try {
const phone = req.body.phone;
// Assuming loginUserInstall function exists and works properly const phoneVerificationCode = req.body.phoneVerificationCode;
try{
const loginObject = await userController.loginUserWithOTP(req);
if (loginObject.same) { const installationExists = await Install.findOne({
const phoneVerified = loginObject.user.phoneVerified; phone: phone,
const oneTimePasswordSetFlag = loginObject.user.oneTimePasswordSetFlag; phoneVerificationCode: phoneVerificationCode,
});
if (!phoneVerified) { 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) {
if (loginObject.user) {
const { user } = loginObject;
const phoneVerified = user.phoneVerified;
const oneTimePasswordSetFlag = user.oneTimePasswordSetFlag;
if (!phoneVerified) {
reply.send({
simplydata: {
error: false,
phoneVerified: false,
phone: user.phone,
oneTimePasswordSetFlag: oneTimePasswordSetFlag,
message: "Please Verify your phone number",
},
});
} else if (oneTimePasswordSetFlag) {
reply.send({
simplydata: {
error: false,
phoneVerified: phoneVerified,
phone: user.phone,
oneTimePasswordSetFlag: true,
message: "Password must be reset",
},
});
} else {
const token = fastify.jwt.sign(
{
name: user.name,
},
{ expiresIn: "30d" }
);
const profilePicture = await ProfilePictureInstall.findOne({
customerId: user._id,
});
const responsePayload = {
simplydata: {
error: false,
apiversion: fastify.config.APIVERSION,
access_token: token,
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,
},
};
if (profilePicture) {
responsePayload.simplydata.picture = profilePicture.picture;
}
reply.send(responsePayload);
}
} else {
reply.send({
simplydata: {
error: true,
code: 400,
message: "Invalid Details",
},
});
}
} else {
reply.send({
simplydata: {
error: true,
code: 400,
message: "Invalid phone or phoneVerificationCode supplied",
},
});
}
} else {
reply.send({ reply.send({
simplydata: { armintatankdata: {
error: false, error: true,
phoneVerified: false, code: 10005,
phone: loginObject.user.phone, message: "10005 - Verification code entered cannot be validated.",
oneTimePasswordSetFlag: oneTimePasswordSetFlag,
message: "Please Verify your phone number",
}, },
}); });
} else if (oneTimePasswordSetFlag) {
reply.send({
simplydata: {
error: false,
phoneVerified: phoneVerified,
phone: loginObject.user.phone,
oneTimePasswordSetFlag: true,
message: "Password must be reset",
},
});
} else {
const token = fastify.jwt.sign(
{
name: loginObject.user.name,
},
'your_jwt_secret', // Replace with your actual JWT secret
{ expiresIn: '30d' }
);
const profilePicture = await ProfilePictureInstall.findOne({ customerId: loginObject.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),
},
};
if (profilePicture) {
responsePayload.simplydata.picture = profilePicture.picture;
}
reply.send(responsePayload);
} }
} else { } catch (err) {
reply.send({ throw boom.boomify(err);
simplydata: {
error: true,
code: 400,
message: "Invalid phone or phoneVerificationCode supplied",
},
});
} }
}catch(e){
console.log('errrorrrr',e)
}
}, },
}); });
@ -462,7 +497,7 @@ fastify.register(require("./routes/forTestingRoute"));
const {Storage} = require('@google-cloud/storage'); const {Storage} = require('@google-cloud/storage');
const { Supplier, profilePictureSupplier } = require("./models/supplier"); const { Supplier, profilePictureSupplier } = require("./models/supplier");
const multer = require('fastify-multer'); 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(require('fastify-formbody'));
// fastify.register(multer.contentParser); // fastify.register(multer.contentParser);
// const multipart = require('fastify-multipart'); // const multipart = require('fastify-multipart');

@ -5,7 +5,7 @@ const ObjectId = Schema.Types.ObjectId;
const installationschema = new mongoose.Schema({ const installationschema = new mongoose.Schema({
name: { type: String }, // name: { type: String },
phone: { type: String, unique: true, trim: true }, phone: { type: String, unique: true, trim: true },
address: String, address: String,
installationId: { type: String }, installationId: { type: String },
@ -18,6 +18,8 @@ const installationschema = new mongoose.Schema({
profile: { profile: {
alternativeNumber: { type: String, default: null }, alternativeNumber: { type: String, default: null },
firstName: { type: String, default: null },
lastName: { type: String, default: null },
address1: { type: String, default: null }, address1: { type: String, default: null },
address2: { type: String, default: null }, address2: { type: String, default: null },
city: { type: String, default: null }, city: { type: String, default: null },

@ -25,7 +25,7 @@ module.exports = function (fastify, opts, next) {
}, },
}, },
}, },
name: { type: 'string' }, //name: { type: 'string' },
team: { type: 'string', default: null }, team: { type: 'string', default: null },
manager: { type: 'string', default: null }, manager: { type: 'string', default: null },
address1: { type: 'string', default: null }, address1: { type: 'string', default: null },
@ -38,6 +38,9 @@ module.exports = function (fastify, opts, next) {
latitude: { type: 'number', default: 0.0 }, latitude: { type: 'number', default: 0.0 },
longitude: { type: 'number', default: 0.0 }, longitude: { type: 'number', default: 0.0 },
fcmId: { type: 'string', default: null }, fcmId: { type: 'string', default: null },
alternativeNumber : { type: 'string', default: null },
firstName :{ type: 'string', default: null },
lastName : { type: 'string', default: null },
}, },
}, },
security: [ security: [

Loading…
Cancel
Save