mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-09 00:18:00 +01:00
fix: add enpoint for fetching a single user (#1074)
* fix: add enpoint for fetching a single user * fix add api docs
This commit is contained in:
parent
8040abb1c4
commit
d0b2ce3170
@ -61,6 +61,7 @@ export default class UserAdminController extends Controller {
|
|||||||
this.get('/search', this.search);
|
this.get('/search', this.search);
|
||||||
this.post('/', this.createUser, ADMIN);
|
this.post('/', this.createUser, ADMIN);
|
||||||
this.post('/validate-password', this.validatePassword);
|
this.post('/validate-password', this.validatePassword);
|
||||||
|
this.get('/:id', this.getUser, ADMIN);
|
||||||
this.put('/:id', this.updateUser, ADMIN);
|
this.put('/:id', this.updateUser, ADMIN);
|
||||||
this.post('/:id/change-password', this.changePassword, ADMIN);
|
this.post('/:id/change-password', this.changePassword, ADMIN);
|
||||||
this.delete('/:id', this.deleteUser, ADMIN);
|
this.delete('/:id', this.deleteUser, ADMIN);
|
||||||
@ -115,6 +116,12 @@ export default class UserAdminController extends Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getUser(req: Request, res: Response): Promise<void> {
|
||||||
|
const { id } = req.params;
|
||||||
|
const user = await this.userService.getUser(Number(id));
|
||||||
|
res.json(user);
|
||||||
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||||
async createUser(
|
async createUser(
|
||||||
req: IAuthRequest<any, any, ICreateUserBody, any>,
|
req: IAuthRequest<any, any, ICreateUserBody, any>,
|
||||||
|
@ -143,8 +143,6 @@ test('requires known root role', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('update user name', async () => {
|
test('update user name', async () => {
|
||||||
expect.assertions(3);
|
|
||||||
|
|
||||||
const { body } = await app.request
|
const { body } = await app.request
|
||||||
.post('/api/admin/user-admin')
|
.post('/api/admin/user-admin')
|
||||||
.send({
|
.send({
|
||||||
@ -168,6 +166,25 @@ test('update user name', async () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('get a single user', async () => {
|
||||||
|
const { body } = await app.request
|
||||||
|
.post('/api/admin/user-admin')
|
||||||
|
.send({
|
||||||
|
email: 'some2@getunelash.ai',
|
||||||
|
name: 'Some Name 2',
|
||||||
|
rootRole: editorRole.id,
|
||||||
|
})
|
||||||
|
.set('Content-Type', 'application/json');
|
||||||
|
|
||||||
|
const { body: user } = await app.request
|
||||||
|
.get(`/api/admin/user-admin/${body.id}`)
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
expect(user.email).toBe('some2@getunelash.ai');
|
||||||
|
expect(user.name).toBe('Some Name 2');
|
||||||
|
expect(user.id).toBe(body.id);
|
||||||
|
});
|
||||||
|
|
||||||
test('should delete user', async () => {
|
test('should delete user', async () => {
|
||||||
expect.assertions(0);
|
expect.assertions(0);
|
||||||
|
|
||||||
|
@ -65,6 +65,29 @@ Will return all users and all available root roles for the Unleash instance.
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### Get a single users {#get-user}
|
||||||
|
|
||||||
|
`GET https://unleash.host.com/api/admin/user-admin/:id`
|
||||||
|
|
||||||
|
Will return a single user by id.
|
||||||
|
|
||||||
|
**Body**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"createdAt": "2021-05-14T08:58:07.891Z",
|
||||||
|
"email": "random-user2@getunleash.ai",
|
||||||
|
"id": 4,
|
||||||
|
"imageUrl": "https://gravatar.com/avatar/90047524992cd6ae8f66e249a7630d80?size=42&default=retro",
|
||||||
|
"inviteLink": "",
|
||||||
|
"isAPI": false,
|
||||||
|
"loginAttempts": 0,
|
||||||
|
"rootRole": 1,
|
||||||
|
"seenAt": null
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Search for users {#search-for-users}
|
### Search for users {#search-for-users}
|
||||||
|
|
||||||
You can also search for users via the search API. It will preform a simple search based on name and email matching the given query. Requires minimum 2 characters.
|
You can also search for users via the search API. It will preform a simple search based on name and email matching the given query. Requires minimum 2 characters.
|
||||||
|
Loading…
Reference in New Issue
Block a user