Skip to content

Commit

Permalink
users (unverified) list
Browse files Browse the repository at this point in the history
  • Loading branch information
Bouchemel-Nasreddine committed Nov 5, 2023
1 parent 5155246 commit f8d4169
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 4 deletions.
98 changes: 97 additions & 1 deletion src/controllers/adminController.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,104 @@ const verifyUserProfile = async (req, res) => {

}

const getAllUsers = async (req, res) => {

const admin = verifyToken(getTokenFromHeaders(req.headers));

if (!admin) {
return res.status(401).json({ message: 'Unauthorized' });
}
//verify if admin.if exist in db
try {
const adminDb = await prisma.admin.findUnique({ where: { id: admin.id } });

if (!adminDb) {
return res.status(401).json({ message: 'Unauthorized' });
}
} catch (err) {
console.log(err);
return res.status(500).json({ message: 'Something went wrong, please try again later or try contact assitance service ' });
}

try {
//get list of all users
const users = await prisma.user.findMany({
select: {
id: true,
firstName: true,
lastName: true,
email: true,
phone: true,
profileVerified: true,
emailVerified: true,
phoneVerified: true,
createdAt: true,
updatedAt: true
}
});

return res.status(200).json(users);
}
catch (err) {
console.log(err);
return res.status(500).json({ message: 'Something went wrong, please try again later or try contact assitance service ' });
}

}

const getAllUnverifiedUsers = async (req, res) => {
const admin = verifyToken(getTokenFromHeaders(req.headers));

if (!admin) {
return res.status(401).json({ message: 'Unauthorized' });
}
//verify if admin.if exist in db
try {
const adminDb = await prisma.admin.findUnique({ where: { id: admin.id } });

if (!adminDb) {
return res.status(401).json({ message: 'Unauthorized' });
}
} catch (err) {
console.log(err);
return res.status(500).json({ message: 'Something went wrong, please try again later or try contact assitance service ' });
}

//getting all the user that have phone and email verified but not profile verified
try {
const users = await prisma.User.findMany({
where: {
emailVerified: true,
phoneVerified: true,
profileVerified: false
},
select: {
id: true,
firstName: true,
lastName: true,
email: true,
phone: true,
profileVerified: true,
emailVerified: true,
phoneVerified: true,
createdAt: true,
updatedAt: true
}
});

return res.status(200).json(users);
}
catch (err) {
console.log(err);
return res.status(500).json({ message: 'Something went wrong, please try again later or try contact assitance service ' });
}

}

module.exports = {
register,
login,
verifyUserProfile
verifyUserProfile,
getAllUsers,
getAllUnverifiedUsers
}
6 changes: 3 additions & 3 deletions src/controllers/authController.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ const verifyPhone = async (req, res) => {
}

const id = req.params.id;

const { country_code, phone } = req.body;
//verifing if the user exists
try {
const user = await prisma.user.findUnique({
Expand All @@ -245,14 +245,14 @@ const verifyPhone = async (req, res) => {
return res.status(404).json({ message: 'User does not exist' });
} else if (user.phoneVerified) {
return res.status(409).json({ message: 'Phone number already verified' });
} else if (user.countryCode !== parseInt(country_code) || user.phone !== parseInt(phone)) {
return res.status(400).json({ message: 'Phone number with id ' + id + ' does not match with the phone number provided' });
}
} catch (error) {
console.log(error);
return res.status(500).json({ message: 'Something went wrong, please try again later or try contact assitance service ' });
}

const { country_code, phone } = req.body;

const options = {
method: 'GET',
url: 'https://phonenumbervalidatefree.p.rapidapi.com/ts_PhoneNumberValidateTest.jsp',
Expand Down
4 changes: 4 additions & 0 deletions src/routes/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ router.post('/login-admin', [

router.get('/verify-user/:user_id', adminController.verifyUserProfile);

router.get('/get-all-users', adminController.getAllUsers);

router.get('/get-all-unverified-users', adminController.getAllUnverifiedUsers);

module.exports = router;

0 comments on commit f8d4169

Please sign in to comment.