api collaboration
This commit is contained in:
@@ -13,13 +13,18 @@ interface Iresponse {
|
||||
interface Isignup {
|
||||
userName: string;
|
||||
email: string;
|
||||
password: string;
|
||||
confirmPassword: string;
|
||||
password: string
|
||||
}
|
||||
interface Isignin {
|
||||
email: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
interface signout {
|
||||
email: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
interface IforGotPassword {
|
||||
email: string;
|
||||
}
|
||||
@@ -32,15 +37,15 @@ export async function existingUserData(email: string, organization: string) {
|
||||
return existingData;
|
||||
}
|
||||
export const signupService = async (data: Isignup): Promise<Iresponse> => {
|
||||
const { userName, email, password, confirmPassword } = data;
|
||||
const { userName, email, password } = data;
|
||||
try {
|
||||
const mailCaseChange = email.toLocaleLowerCase();
|
||||
const organization = email.split("@")[1].split(".")[0];
|
||||
const mailExistance = await existingUserData(mailCaseChange, organization);
|
||||
if (mailExistance !== null) return { status: "User Already exists" };
|
||||
if (password !== confirmPassword) {
|
||||
return { status: "Passwords do not match" };
|
||||
}
|
||||
// if (password !== confirmPassword) {
|
||||
// return { status: "Passwords do not match" };
|
||||
// }
|
||||
let role;
|
||||
const passwordHashed = await hashGenerate(password);
|
||||
const userCount = await userModel(organization).countDocuments({});
|
||||
@@ -72,8 +77,7 @@ export const signinService = async (data: Isignin): Promise<Iresponse> => {
|
||||
const mailCaseChange = email.toLocaleLowerCase();
|
||||
const organization = email.split("@")[1].split(".")[0];
|
||||
const mailExistance = await existingUserData(mailCaseChange, organization);
|
||||
if (mailExistance == null)
|
||||
return { status: "User not found!!! Kindly Signup" };
|
||||
if (!mailExistance) return { status: "User not found!!! Kindly Signup" };
|
||||
const comparePassword = await hashValidator(
|
||||
password,
|
||||
mailExistance.password
|
||||
@@ -230,3 +234,39 @@ export const forgetPassword = async ({
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const signOutService = async (data: signout): Promise<Iresponse> => {
|
||||
const { email } = data;
|
||||
try {
|
||||
const mailCaseChange = email.toLocaleLowerCase();
|
||||
const organization = email.split("@")[1].split(".")[0];
|
||||
const mailExistance = await existingUserData(mailCaseChange, organization);
|
||||
if (!mailExistance) return { status: "User not found!!! Kindly Signup" };
|
||||
|
||||
const tokenData = await tokenModel(organization).findOne({
|
||||
userId: mailExistance._id,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
if (!tokenData) return { status: "Token not found" };
|
||||
await Promise.all([
|
||||
redis.del(`token:${mailCaseChange}`),
|
||||
redis.del(`user:${mailCaseChange}`),
|
||||
]);
|
||||
tokenData.refreshToken = "";
|
||||
await tokenData.save();
|
||||
mailExistance.visitorBrowserID = "";
|
||||
await mailExistance.save();
|
||||
return { status: "Success" };
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return {
|
||||
status: error.message,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
status: "An unexpected error occurred",
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user