|
|
@ -265,11 +265,13 @@ fastify.post("/api/login", {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check for staff login
|
|
|
|
// Check for staff login
|
|
|
|
const allUsers = await User.find({ "staff.staff": { $elemMatch: { phone } } });
|
|
|
|
const allUsers = await User.find({ "staff.staff": { $elemMatch: { phone } } });
|
|
|
|
for (const currentUser of allUsers) {
|
|
|
|
for (const currentUser of allUsers) {
|
|
|
|
const staffMember = currentUser.staff.staff.find(staff => staff.phone === phone && staff.status === "active");
|
|
|
|
const staffMember = currentUser.staff.staff.find(staff => staff.phone === phone && staff.status === "active");
|
|
|
|
if (staffMember && staffMember.password === password) {
|
|
|
|
if (staffMember && staffMember.password === password) {
|
|
|
|
|
|
|
|
|
|
|
|
const token = fastify.jwt.sign(
|
|
|
|
const token = fastify.jwt.sign(
|
|
|
|
{
|
|
|
|
{
|
|
|
|
name: staffMember.name,
|
|
|
|
name: staffMember.name,
|
|
|
@ -286,7 +288,21 @@ fastify.post("/api/login", {
|
|
|
|
name: staffMember.name,
|
|
|
|
name: staffMember.name,
|
|
|
|
phone: staffMember.phone,
|
|
|
|
phone: staffMember.phone,
|
|
|
|
customerId: currentUser.customerId,
|
|
|
|
customerId: currentUser.customerId,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
buildingName: currentUser.buildingName,
|
|
|
|
|
|
|
|
email: currentUser.emails,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
address1: currentUser.address1,
|
|
|
|
|
|
|
|
address2: currentUser.address2,
|
|
|
|
|
|
|
|
phoneVerified: true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
latitude: currentUser.latitude,
|
|
|
|
|
|
|
|
longitude: currentUser.longitude,
|
|
|
|
|
|
|
|
type: "staff",
|
|
|
|
message: "Staff login successful",
|
|
|
|
message: "Staff login successful",
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|