team member login insatllationId field added

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

@ -1021,47 +1021,52 @@ fastify.post("/api/installLogin", {
});
fastify.post("/api/teamMemberLogin", {
fastify.post("/api/teamMemberLogin", {
schema: {
description: "Login API for team members",
tags: ["Installation"],
summary: "Login as a Team Member",
body: {
type: "object",
required: ["type", "phone", "password"],
required: ["type", "phone", "password", "installationId"],
properties: {
type: { type: "string", description: "Role type of the user (e.g., 'team_member')" },
phone: { type: "string", description: "Registered phone number of the team member" },
password: { type: "string", description: "Password for authentication" },
installationId: { type: "string", description: "Installation ID for verification" },
},
},
},
async handler(request, reply) {
try {
const { type, phone, password } = request.body;
const { type, phone, password, installationId } = request.body;
// Find team member in any installation
const installation = await Install.findOne({ "team_member.team_member.phone": phone });
// Find the installation where both phone and installationId match
const installation = await Install.findOne({
"team_member.team_member": {
$elemMatch: { phone: phone, installationTeamMemId: installationId }
}
});
if (!installation) {
return reply.status(401).send({
simplydata: {
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(
(member) => member.phone === phone
(member) => member.phone === phone && member.installationTeamMemId === installationId
);
if (!teamMember) {
return reply.status(401).send({
simplydata: {
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",
access_token: token,
phone: teamMember.phone,
firstName: teamMember.firstName,
firstName: teamMember.firstName || null,
teamMemberId: teamMember.teamMemberId,
alternativePhone: teamMember.alternativePhone || null,
email: teamMember.email || null,
@ -1116,7 +1121,8 @@ fastify.post("/api/installLogin", {
});
}
},
});
});
fastify.post("/api/surveyLogin", {
schema: {

Loading…
Cancel
Save