team member login insatllationId field added

master^2
Bhaskar 7 months ago
parent 1a7d82a23f
commit a81685ad49

@ -1028,40 +1028,45 @@ fastify.post("/api/installLogin", {
summary: "Login as a Team Member", summary: "Login as a Team Member",
body: { body: {
type: "object", type: "object",
required: ["type", "phone", "password"], required: ["type", "phone", "password", "installationId"],
properties: { properties: {
type: { type: "string", description: "Role type of the user (e.g., 'team_member')" }, type: { type: "string", description: "Role type of the user (e.g., 'team_member')" },
phone: { type: "string", description: "Registered phone number of the team member" }, phone: { type: "string", description: "Registered phone number of the team member" },
password: { type: "string", description: "Password for authentication" }, password: { type: "string", description: "Password for authentication" },
installationId: { type: "string", description: "Installation ID for verification" },
}, },
}, },
}, },
async handler(request, reply) { async handler(request, reply) {
try { try {
const { type, phone, password } = request.body; const { type, phone, password, installationId } = request.body;
// Find team member in any installation // Find the installation where both phone and installationId match
const installation = await Install.findOne({ "team_member.team_member.phone": phone }); const installation = await Install.findOne({
"team_member.team_member": {
$elemMatch: { phone: phone, installationTeamMemId: installationId }
}
});
if (!installation) { if (!installation) {
return reply.status(401).send({ return reply.status(401).send({
simplydata: { simplydata: {
error: true, error: true,
message: "Invalid phone number or password", message: "Invalid phone number or installation ID",
}, },
}); });
} }
// Find team member details // Find the specific team member inside the array
const teamMember = installation.team_member.team_member.find( const teamMember = installation.team_member.team_member.find(
(member) => member.phone === phone (member) => member.phone === phone && member.installationTeamMemId === installationId
); );
if (!teamMember) { if (!teamMember) {
return reply.status(401).send({ return reply.status(401).send({
simplydata: { simplydata: {
error: true, error: true,
message: "Invalid phone number or password", message: "Invalid phone number or installation ID",
}, },
}); });
} }
@ -1097,7 +1102,7 @@ fastify.post("/api/installLogin", {
message: "Login successful", message: "Login successful",
access_token: token, access_token: token,
phone: teamMember.phone, phone: teamMember.phone,
firstName: teamMember.firstName, firstName: teamMember.firstName || null,
teamMemberId: teamMember.teamMemberId, teamMemberId: teamMember.teamMemberId,
alternativePhone: teamMember.alternativePhone || null, alternativePhone: teamMember.alternativePhone || null,
email: teamMember.email || null, email: teamMember.email || null,
@ -1118,6 +1123,7 @@ fastify.post("/api/installLogin", {
}, },
}); });
fastify.post("/api/surveyLogin", { fastify.post("/api/surveyLogin", {
schema: { schema: {
description: "This is for Login Survey", description: "This is for Login Survey",

Loading…
Cancel
Save