varun 1 year ago
commit f3798182d9

@ -13,7 +13,7 @@ const supplierController = require("../controllers/supplierController")
exports.installSignUp = async (request, reply) => {
try {
const {
name,
//name,
phone,
address,
installationId,
@ -25,15 +25,18 @@ exports.installSignUp = async (request, reply) => {
longitude,
latitude,
fcmId,
alternativeNumber,
firstName,
lastName,
createdBy,
updatedBy,
} = request.body;
// Check if the email address is valid
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (emails.some((emailObj) => !emailRegex.test(emailObj.email))) {
return reply.status(400).send({ message: 'Invalid email address' });
}
// const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
// if (emails.some((emailObj) => !emailRegex.test(emailObj.email))) {
// return reply.status(400).send({ message: 'Invalid email address' });
// }
// Check if a user with the same phone number already exists
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
const install = new Install({
name,
//name,
phone,
address,
installationId,
@ -58,8 +61,12 @@ exports.installSignUp = async (request, reply) => {
longitude,
latitude,
fcmId,
alternativeNumber,
firstName,
lastName,
createdBy,
updatedBy,
});
// 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 createConnectionController = require("./controllers/createConnectionController");
const storeController = require("./controllers/storeController.js")
const boom = require("boom");
const cors = require("cors");
const swagger = require("./config/swagger");
@ -291,88 +292,122 @@ fastify.post("/api/installotplogin", {
},
},
async handler(req, reply) {
const { phone, phoneVerificationCode } = req.body;
// Assuming loginUserInstall function exists and works properly
try{
const loginObject = await userController.loginUserWithOTP(req);
try {
const phone = req.body.phone;
const phoneVerificationCode = req.body.phoneVerificationCode;
if (loginObject.same) {
const phoneVerified = loginObject.user.phoneVerified;
const oneTimePasswordSetFlag = loginObject.user.oneTimePasswordSetFlag;
const installationExists = await Install.findOne({
phone: phone,
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({
simplydata: {
error: false,
phoneVerified: false,
phone: loginObject.user.phone,
oneTimePasswordSetFlag: oneTimePasswordSetFlag,
message: "Please Verify your phone number",
armintatankdata: {
error: true,
code: 10005,
message: "10005 - Verification code entered cannot be validated.",
},
});
} 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 {
reply.send({
simplydata: {
error: true,
code: 400,
message: "Invalid phone or phoneVerificationCode supplied",
},
});
} catch (err) {
throw boom.boomify(err);
}
}catch(e){
console.log('errrorrrr',e)
}
},
});
@ -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');

@ -5,7 +5,7 @@ const ObjectId = Schema.Types.ObjectId;
const installationschema = new mongoose.Schema({
name: { type: String },
// name: { type: String },
phone: { type: String, unique: true, trim: true },
address: String,
installationId: { type: String },
@ -18,6 +18,8 @@ const installationschema = new mongoose.Schema({
profile: {
alternativeNumber: { type: String, default: null },
firstName: { type: String, default: null },
lastName: { type: String, default: null },
address1: { type: String, default: null },
address2: { 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 },
manager: { 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 },
longitude: { type: 'number', default: 0.0 },
fcmId: { type: 'string', default: null },
alternativeNumber : { type: 'string', default: null },
firstName :{ type: 'string', default: null },
lastName : { type: 'string', default: null },
},
},
security: [

Loading…
Cancel
Save