diff --git a/src/controllers/userController.js b/src/controllers/userController.js index f6dc5db9..179ce6e0 100644 --- a/src/controllers/userController.js +++ b/src/controllers/userController.js @@ -289,6 +289,7 @@ exports.loginUser = async (req, fcmIds, deviceId) => { // If not a main user, check staff inside all users if (!user) { + const users = await User.find({ "staff.staff.phone": phone }); for (const u of users) { const foundStaff = u.staff.staff.find((s) => s.phone === phone); @@ -301,7 +302,6 @@ exports.loginUser = async (req, fcmIds, deviceId) => { } } - // If no user or staff found, return invalid credentials if (!user) return { same: false }; @@ -324,6 +324,9 @@ exports.loginUser = async (req, fcmIds, deviceId) => { throw boom.boomify(err); } }; + + + exports.loginUserWithOTP = async (req) => { try { const phone = req.body.phone; diff --git a/src/index.js b/src/index.js index f7fa9ba1..37514d76 100644 --- a/src/index.js +++ b/src/index.js @@ -202,7 +202,7 @@ fastify.post("/api/login", { simplydata: { error: false, phoneVerified: false, - phone: user.phone, + phone: loginObject.isStaff ? loginObject.staffMember.phone : user.phone, oneTimePasswordSetFlag, message: "Please Verify your phone number", }, @@ -214,7 +214,7 @@ fastify.post("/api/login", { simplydata: { error: false, phoneVerified, - phone: user.phone, + phone: loginObject.isStaff ? loginObject.staffMember.phone : user.phone, oneTimePasswordSetFlag: true, message: "Password must be reset", }, @@ -237,7 +237,7 @@ fastify.post("/api/login", { access_token: token, buildingName: user.buildingName, email: user.emails, - phone: user.phone, + phone: loginObject.isStaff ? loginObject.staffMember.phone : user.phone, customerId: user.customerId, username: loginObject.isStaff ? loginObject.staffMember.name : user.username, address1: user.profile.address1, @@ -251,7 +251,10 @@ fastify.post("/api/login", { }, }; - + if (loginObject.isStaff) { + responsePayload.simplydata.all_motor_access = loginObject.staffMember.all_motor_access; + } + if (profilePicture) { responsePayload.simplydata.picture = profilePicture.picture; } @@ -263,6 +266,7 @@ fastify.post("/api/login", { + fastify.post("/api/installotplogin", { schema: { description: "This is for Login Otp Installation",