-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9db6745
commit 047adc1
Showing
8 changed files
with
3,676 additions
and
4,822 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,15 +64,15 @@ describe('POST /user/deactivate', () => { | |
|
||
const response = await request(app) | ||
.post(`/user/deactivate`) | ||
.set('Cookie', `token=${token}`) | ||
.set('Authorization', `Bearer ${token}`) | ||
.send({ email: `${testUser.email}` }); | ||
expect(response.status).toBe(200); | ||
expect(response.body.message).toBe('User deactivated successfully'); | ||
}, 60000); | ||
|
||
it('should return 404 when email is not submitted', async () => { | ||
const token = jwt.sign(data, jwtSecretKey); | ||
const response = await request(app).post(`/user/deactivate`).set('Cookie', `token=${token}`); | ||
const response = await request(app).post(`/user/deactivate`).set('Authorization', `Bearer ${token}`); | ||
|
||
expect(response.status).toBe(404); | ||
expect(response.body.error).toBe('Email is needed'); | ||
|
@@ -81,7 +81,7 @@ describe('POST /user/deactivate', () => { | |
const token = jwt.sign(data, jwtSecretKey); | ||
const response = await request(app) | ||
.post(`/user/deactivate`) | ||
.set('Cookie', `token=${token}`) | ||
.set('Authorization', `Bearer ${token}`) | ||
.send({ email: `${testUser.email}` }); | ||
|
||
expect(response.status).toBe(200); | ||
|
@@ -92,7 +92,7 @@ describe('POST /user/deactivate', () => { | |
const token = jwt.sign(data, jwtSecretKey); | ||
const response = await request(app) | ||
.post(`/user/deactivate`) | ||
.set('Cookie', `token=${token}`) | ||
.set('Authorization', `Bearer ${token}`) | ||
.send({ email: '[email protected]' }); | ||
|
||
expect(response.status).toBe(404); | ||
|
@@ -106,7 +106,7 @@ describe('POST /user/activate', () => { | |
|
||
const response = await request(app) | ||
.post(`/user/activate`) | ||
.set('Cookie', `token=${token}`) | ||
.set('Authorization', `Bearer ${token}`) | ||
.send({ email: `${testUser.email}` }); | ||
|
||
expect(response.status).toBe(200); | ||
|
@@ -115,7 +115,7 @@ describe('POST /user/activate', () => { | |
|
||
it('should return 404 when email is not submitted', async () => { | ||
const token = jwt.sign(data, jwtSecretKey); | ||
const response = await request(app).post(`/user/activate`).set('Cookie', `token=${token}`); | ||
const response = await request(app).post(`/user/activate`).set('Authorization', `Bearer ${token}`); | ||
|
||
expect(response.status).toBe(404); | ||
expect(response.body.error).toBe('Email is needed'); | ||
|
@@ -125,7 +125,7 @@ describe('POST /user/activate', () => { | |
const token = jwt.sign(data, jwtSecretKey); | ||
const response = await request(app) | ||
.post(`/user/activate`) | ||
.set('Cookie', `token=${token}`) | ||
.set('Authorization', `Bearer ${token}`) | ||
.send({ email: `${testUser.email}` }); | ||
|
||
expect(response.status).toBe(200); | ||
|
@@ -142,7 +142,7 @@ describe('POST /user/activate', () => { | |
const token = jwt.sign(data, jwtSecretKey); | ||
const response = await request(app) | ||
.post('/user/activate') | ||
.set('Cookie', `token=${token}`) | ||
.set('Authorization', `Bearer ${token}`) | ||
.send({ email: '[email protected]' }); | ||
|
||
expect(response.status).toBe(404); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Request, Response } from 'express'; | ||
import { getRepository } from 'typeorm'; | ||
import { User } from '../../entities/User'; | ||
|
||
const getAllUsers = async (req: Request, res: Response) => { | ||
try { | ||
const userRepository = getRepository(User); | ||
|
||
const users = await userRepository | ||
.createQueryBuilder('user') | ||
.select([ | ||
'user.id', | ||
'user.firstName', | ||
'user.lastName', | ||
'user.email', | ||
'user.gender', | ||
'user.phoneNumber', | ||
'user.photoUrl', | ||
'user.verified', | ||
'user.twoFactorEnabled', | ||
'user.status', | ||
'user.userType', | ||
'user.role', | ||
'user.createdAt', | ||
'user.updatedAt', | ||
]) | ||
.getMany(); | ||
|
||
res.status(200).json({ message: 'All users retrieved', users }); | ||
} catch (error) { | ||
return res.status(500).json({ error: 'Internal server error' }); | ||
} | ||
}; | ||
|
||
export default getAllUsers; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Request, Response } from 'express'; | ||
import { getRepository } from 'typeorm'; | ||
import { User } from '../../entities/User'; | ||
|
||
const getUserById = async (req: Request, res: Response) => { | ||
const userId = req.params.id; | ||
try { | ||
const userRepository = getRepository(User); | ||
|
||
const user = await userRepository | ||
.createQueryBuilder('user') | ||
.select([ | ||
'user.id', | ||
'user.firstName', | ||
'user.lastName', | ||
'user.email', | ||
'user.gender', | ||
'user.phoneNumber', | ||
'user.photoUrl', | ||
'user.verified', | ||
'user.twoFactorEnabled', | ||
'user.status', | ||
'user.userType', | ||
'user.role', | ||
'user.createdAt', | ||
'user.updatedAt', | ||
]) | ||
.where('user.id = :id', { id: userId }) | ||
.getOne(); | ||
|
||
user && res.status(200).json({ message: 'User retrived', user }); | ||
} catch (error) { | ||
return res.status(500).json({ error: 'Internal server error' }); | ||
} | ||
}; | ||
|
||
export default getUserById; |