|
|
|
@ -1435,34 +1435,29 @@ fastify.post("/api/teamMemberLogin", {
|
|
|
|
|
summary: "This is for Login Support",
|
|
|
|
|
body: {
|
|
|
|
|
type: "object",
|
|
|
|
|
required: [ "phone", "password"],
|
|
|
|
|
required: ["phone", "password", "type"],
|
|
|
|
|
properties: {
|
|
|
|
|
phone: { type: "string", description: "Registered phone number" },
|
|
|
|
|
password: { type: "string", description: "Password for authentication" },
|
|
|
|
|
type: { type: "string", description: "Role of the user (e.g., 'Support_Manager')" },
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
async handler(req, reply) {
|
|
|
|
|
try {
|
|
|
|
|
const { phone, password } = req.body;
|
|
|
|
|
const { phone, password, type } = req.body;
|
|
|
|
|
|
|
|
|
|
// Check if user exists in the Department Schema
|
|
|
|
|
const user = await Deparments.findOne({ phone });
|
|
|
|
|
console.log("user", user)
|
|
|
|
|
|
|
|
|
|
if (!user) {
|
|
|
|
|
return reply.code(400).send({ message: "User not found" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Verify Password
|
|
|
|
|
const isMatch = await bcrypt.compare(password, user.services.password.bcrypt);
|
|
|
|
|
|
|
|
|
|
if (!isMatch) {
|
|
|
|
|
return reply.code(400).send({ message: "Invalid credentials" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let survey = await Support.findOne({ phone });
|
|
|
|
|
|
|
|
|
|
if (!survey) {
|
|
|
|
|
survey = new Support({
|
|
|
|
|
phone: user.phone,
|
|
|
|
@ -1481,15 +1476,17 @@ fastify.post("/api/teamMemberLogin", {
|
|
|
|
|
profile: {
|
|
|
|
|
state: user.state,
|
|
|
|
|
country: user.country,
|
|
|
|
|
//role: type, // Store type in profile.role
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await survey.save();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const token = fastify.jwt.sign(
|
|
|
|
|
{ phone: user.phone },
|
|
|
|
|
{
|
|
|
|
|
userId: user._id,
|
|
|
|
|
phone: user.phone,
|
|
|
|
|
role: type
|
|
|
|
|
},
|
|
|
|
|
"Scret",
|
|
|
|
|
{ expiresIn: "1h" }
|
|
|
|
|
);
|
|
|
|
@ -1497,35 +1494,35 @@ fastify.post("/api/teamMemberLogin", {
|
|
|
|
|
return reply.send({
|
|
|
|
|
simplydata: {
|
|
|
|
|
error: false,
|
|
|
|
|
message: "Login successful",
|
|
|
|
|
apiversion: "1.0.0",
|
|
|
|
|
access_token: token,
|
|
|
|
|
email: user.email || [],
|
|
|
|
|
installationId: user.departmentId || "",
|
|
|
|
|
phone: user.phone,
|
|
|
|
|
supportId: user.departmentId,
|
|
|
|
|
firstName: user.firstName,
|
|
|
|
|
lastName: user.lastName,
|
|
|
|
|
email: user.email,
|
|
|
|
|
alternativeNumber: user.alternativeContactNumber,
|
|
|
|
|
departmentName: user.departmentName,
|
|
|
|
|
designation: user.desginationName,
|
|
|
|
|
reportingManager: user.reportingManager,
|
|
|
|
|
city: user.city,
|
|
|
|
|
zone: user.zone,
|
|
|
|
|
address1: user.address1,
|
|
|
|
|
address2: user.address2,
|
|
|
|
|
profile: {
|
|
|
|
|
state: user.state,
|
|
|
|
|
country: user.country,
|
|
|
|
|
//role: type, // Store type in profile.role
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
address1: user.address1 || "",
|
|
|
|
|
address2: user.address2 || "",
|
|
|
|
|
phoneVerified: false,
|
|
|
|
|
oneTimePasswordSetFlag: false,
|
|
|
|
|
type: type, // <== returned from the request
|
|
|
|
|
fcmIds: null,
|
|
|
|
|
team: null,
|
|
|
|
|
city: user.city || "",
|
|
|
|
|
manager: user.reportingManager || null,
|
|
|
|
|
firstName: user.firstName || "",
|
|
|
|
|
lastName: user.lastName || "",
|
|
|
|
|
address: "",
|
|
|
|
|
alternativeNumber: user.alternativeContactNumber || "",
|
|
|
|
|
profilePicture: null
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
// return reply.send(survey);
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Login Error:", error);
|
|
|
|
|
return reply.code(500).send({ message: "Internal server error" });
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
fastify.post("/api/supportTeamMemberLogin", {
|
|
|
|
|
schema: {
|
|
|
|
|
description: "Login Support TeamMember",
|
|
|
|
@ -1537,7 +1534,7 @@ fastify.post("/api/teamMemberLogin", {
|
|
|
|
|
properties: {
|
|
|
|
|
type: {
|
|
|
|
|
type: "string",
|
|
|
|
|
description: "Role type of the user (e.g., 'team_member')"
|
|
|
|
|
description: "Role type of the user (e.g., 'Support_TeamMember')"
|
|
|
|
|
},
|
|
|
|
|
phone: {
|
|
|
|
|
type: "string",
|
|
|
|
@ -1588,17 +1585,35 @@ fastify.post("/api/teamMemberLogin", {
|
|
|
|
|
support_teamMemberId: teamMember.support_teamMemberId,
|
|
|
|
|
name: teamMember.name,
|
|
|
|
|
phone: teamMember.phone,
|
|
|
|
|
type: "Support_TeamMember"
|
|
|
|
|
type: type
|
|
|
|
|
},
|
|
|
|
|
"JWT_SECRET",
|
|
|
|
|
{ expiresIn: '7d' }
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return reply.send({
|
|
|
|
|
status_code: 200,
|
|
|
|
|
message: 'Login successful',
|
|
|
|
|
token,
|
|
|
|
|
teamMember
|
|
|
|
|
simplydata: {
|
|
|
|
|
error: false,
|
|
|
|
|
apiversion: "1.0.0",
|
|
|
|
|
access_token: token,
|
|
|
|
|
email: [],
|
|
|
|
|
installationId: teamMember.support_teamMemberId || "",
|
|
|
|
|
phone: teamMember.phone,
|
|
|
|
|
address1: teamMember.address1 || "",
|
|
|
|
|
address2: teamMember.address2 || "",
|
|
|
|
|
phoneVerified: false,
|
|
|
|
|
oneTimePasswordSetFlag: false,
|
|
|
|
|
type: type,
|
|
|
|
|
fcmIds: null,
|
|
|
|
|
team: null,
|
|
|
|
|
city: teamMember.city || "",
|
|
|
|
|
manager: null,
|
|
|
|
|
firstName: teamMember.name?.split(" ")[0] || "",
|
|
|
|
|
lastName: teamMember.name?.split(" ")[1] || "",
|
|
|
|
|
address: "",
|
|
|
|
|
alternativeNumber: teamMember.alternativeNumber || "",
|
|
|
|
|
profilePicture: null
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
@ -1610,6 +1625,7 @@ fastify.post("/api/teamMemberLogin", {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fastify.post("/api/storelogin", {
|
|
|
|
|
schema: {
|
|
|
|
|
description: "This is for Store Login",
|
|
|
|
|