IO-3020 IO-3036 Initial removal of ProManager
This commit is contained in:
@@ -57,108 +57,108 @@ const createUser = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
const sendPromanagerWelcomeEmail = (req, res) => {
|
||||
const { authid, email } = req.body;
|
||||
// const sendPromanagerWelcomeEmail = (req, res) => {
|
||||
// const { authid, email } = req.body;
|
||||
|
||||
// Fetch user from Firebase
|
||||
admin
|
||||
.auth()
|
||||
.getUser(authid)
|
||||
.then((userRecord) => {
|
||||
if (!userRecord) {
|
||||
return Promise.reject({ status: 404, message: "User not found in Firebase." });
|
||||
}
|
||||
// // Fetch user from Firebase
|
||||
// admin
|
||||
// .auth()
|
||||
// .getUser(authid)
|
||||
// .then((userRecord) => {
|
||||
// if (!userRecord) {
|
||||
// return Promise.reject({ status: 404, message: "User not found in Firebase." });
|
||||
// }
|
||||
|
||||
// Fetch user data from the database using GraphQL
|
||||
return client.request(
|
||||
`
|
||||
query GET_USER_BY_EMAIL($email: String!) {
|
||||
users(where: { email: { _eq: $email } }) {
|
||||
email
|
||||
validemail
|
||||
associations {
|
||||
id
|
||||
shopid
|
||||
bodyshop {
|
||||
id
|
||||
convenient_company
|
||||
}
|
||||
}
|
||||
}
|
||||
}`,
|
||||
{ email: email.toLowerCase() }
|
||||
);
|
||||
})
|
||||
.then((dbUserResult) => {
|
||||
const dbUser = dbUserResult?.users?.[0];
|
||||
if (!dbUser) {
|
||||
return Promise.reject({ status: 404, message: "User not found in database." });
|
||||
}
|
||||
// // Fetch user data from the database using GraphQL
|
||||
// return client.request(
|
||||
// `
|
||||
// query GET_USER_BY_EMAIL($email: String!) {
|
||||
// users(where: { email: { _eq: $email } }) {
|
||||
// email
|
||||
// validemail
|
||||
// associations {
|
||||
// id
|
||||
// shopid
|
||||
// bodyshop {
|
||||
// id
|
||||
// convenient_company
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }`,
|
||||
// { email: email.toLowerCase() }
|
||||
// );
|
||||
// })
|
||||
// .then((dbUserResult) => {
|
||||
// const dbUser = dbUserResult?.users?.[0];
|
||||
// if (!dbUser) {
|
||||
// return Promise.reject({ status: 404, message: "User not found in database." });
|
||||
// }
|
||||
|
||||
// Validate email before proceeding
|
||||
if (!dbUser.validemail) {
|
||||
logger.log("admin-send-welcome-email-skip", "debug", req.user.email, null, {
|
||||
message: "User email is not valid, skipping email.",
|
||||
email
|
||||
});
|
||||
return res.status(200).json({ message: "User email is not valid, email not sent." });
|
||||
}
|
||||
// // Validate email before proceeding
|
||||
// if (!dbUser.validemail) {
|
||||
// logger.log("admin-send-welcome-email-skip", "debug", req.user.email, null, {
|
||||
// message: "User email is not valid, skipping email.",
|
||||
// email
|
||||
// });
|
||||
// return res.status(200).json({ message: "User email is not valid, email not sent." });
|
||||
// }
|
||||
|
||||
// Check if the user's company is ProManager
|
||||
const convenientCompany = dbUser.associations?.[0]?.bodyshop?.convenient_company;
|
||||
if (convenientCompany !== "promanager") {
|
||||
logger.log("admin-send-welcome-email-skip", "debug", req.user.email, null, {
|
||||
message: 'convenient_company is not "promanager", skipping email.',
|
||||
convenientCompany
|
||||
});
|
||||
return res.status(200).json({ message: `convenient_company is not "promanager", email not sent.` });
|
||||
}
|
||||
// // Check if the user's company is ProManager
|
||||
// const convenientCompany = dbUser.associations?.[0]?.bodyshop?.convenient_company;
|
||||
// if (convenientCompany !== "promanager") {
|
||||
// logger.log("admin-send-welcome-email-skip", "debug", req.user.email, null, {
|
||||
// message: 'convenient_company is not "promanager", skipping email.',
|
||||
// convenientCompany
|
||||
// });
|
||||
// return res.status(200).json({ message: `convenient_company is not "promanager", email not sent.` });
|
||||
// }
|
||||
|
||||
// Generate password reset link
|
||||
return admin
|
||||
.auth()
|
||||
.generatePasswordResetLink(dbUser.email)
|
||||
.then((resetLink) => ({ dbUser, resetLink }));
|
||||
})
|
||||
.then(({ dbUser, resetLink }) => {
|
||||
// Send welcome email (replace with your actual email-sending service)
|
||||
return sendProManagerWelcomeEmail({
|
||||
to: dbUser.email,
|
||||
subject: "Welcome to the ProManager platform.",
|
||||
html: generateEmailTemplate({
|
||||
header: "",
|
||||
subHeader: "",
|
||||
body: `
|
||||
<p>Welcome to the ProManager platform. Please click the link below to reset your password:</p>
|
||||
<p><a href="${resetLink}">Reset your password</a></p>
|
||||
<p>User Details:</p>
|
||||
<ul>
|
||||
<li>Email: ${dbUser.email}</li>
|
||||
</ul>
|
||||
`
|
||||
})
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
// Log success and return response
|
||||
logger.log("admin-send-welcome-email", "debug", req.user.email, null, {
|
||||
request: req.body,
|
||||
ioadmin: true,
|
||||
emailSentTo: email
|
||||
});
|
||||
res.status(200).json({ message: "Welcome email sent successfully." });
|
||||
})
|
||||
.catch((error) => {
|
||||
logger.log("admin-send-welcome-email-error", "ERROR", req.user.email, null, { error });
|
||||
// // Generate password reset link
|
||||
// return admin
|
||||
// .auth()
|
||||
// .generatePasswordResetLink(dbUser.email)
|
||||
// .then((resetLink) => ({ dbUser, resetLink }));
|
||||
// })
|
||||
// .then(({ dbUser, resetLink }) => {
|
||||
// // Send welcome email (replace with your actual email-sending service)
|
||||
// return sendProManagerWelcomeEmail({
|
||||
// to: dbUser.email,
|
||||
// subject: "Welcome to the ProManager platform.",
|
||||
// html: generateEmailTemplate({
|
||||
// header: "",
|
||||
// subHeader: "",
|
||||
// body: `
|
||||
// <p>Welcome to the ProManager platform. Please click the link below to reset your password:</p>
|
||||
// <p><a href="${resetLink}">Reset your password</a></p>
|
||||
// <p>User Details:</p>
|
||||
// <ul>
|
||||
// <li>Email: ${dbUser.email}</li>
|
||||
// </ul>
|
||||
// `
|
||||
// })
|
||||
// });
|
||||
// })
|
||||
// .then(() => {
|
||||
// // Log success and return response
|
||||
// logger.log("admin-send-welcome-email", "debug", req.user.email, null, {
|
||||
// request: req.body,
|
||||
// ioadmin: true,
|
||||
// emailSentTo: email
|
||||
// });
|
||||
// res.status(200).json({ message: "Welcome email sent successfully." });
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// logger.log("admin-send-welcome-email-error", "ERROR", req.user.email, null, { error });
|
||||
|
||||
if (!res.headersSent) {
|
||||
res.status(error.status || 500).json({
|
||||
message: error.message || "Error sending welcome email.",
|
||||
error
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
// if (!res.headersSent) {
|
||||
// res.status(error.status || 500).json({
|
||||
// message: error.message || "Error sending welcome email.",
|
||||
// error
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
// };
|
||||
|
||||
const updateUser = (req, res) => {
|
||||
logger.log("admin-update-user", "debug", req.user.email, null, {
|
||||
|
||||
Reference in New Issue
Block a user