1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-01 08:31:59 +00:00

refactor(server): user info endpoint (#9668)

* refactor(server): user info endpoint

* chore: open api
This commit is contained in:
Jason Rasmussen 2024-05-22 14:15:33 -04:00 committed by GitHub
parent 202745f14b
commit ecd018a826
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 61 additions and 63 deletions

View file

@ -93,15 +93,15 @@ describe('/users', () => {
}); });
}); });
describe('GET /users/info/:id', () => { describe('GET /users/:id', () => {
it('should require authentication', async () => { it('should require authentication', async () => {
const { status } = await request(app).get(`/users/info/${admin.userId}`); const { status } = await request(app).get(`/users/${admin.userId}`);
expect(status).toEqual(401); expect(status).toEqual(401);
}); });
it('should get the user info', async () => { it('should get the user info', async () => {
const { status, body } = await request(app) const { status, body } = await request(app)
.get(`/users/info/${admin.userId}`) .get(`/users/${admin.userId}`)
.set('Authorization', `Bearer ${admin.accessToken}`); .set('Authorization', `Bearer ${admin.accessToken}`);
expect(status).toBe(200); expect(status).toBe(200);
expect(body).toMatchObject({ expect(body).toMatchObject({

BIN
mobile/openapi/README.md generated

Binary file not shown.

Binary file not shown.

View file

@ -6229,48 +6229,6 @@
] ]
} }
}, },
"/users/info/{id}": {
"get": {
"operationId": "getUserById",
"parameters": [
{
"name": "id",
"required": true,
"in": "path",
"schema": {
"format": "uuid",
"type": "string"
}
}
],
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UserResponseDto"
}
}
},
"description": ""
}
},
"security": [
{
"bearer": []
},
{
"cookie": []
},
{
"api_key": []
}
],
"tags": [
"User"
]
}
},
"/users/me": { "/users/me": {
"get": { "get": {
"operationId": "getMyUserInfo", "operationId": "getMyUserInfo",
@ -6462,6 +6420,46 @@
"tags": [ "tags": [
"User" "User"
] ]
},
"get": {
"operationId": "getUserById",
"parameters": [
{
"name": "id",
"required": true,
"in": "path",
"schema": {
"format": "uuid",
"type": "string"
}
}
],
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UserResponseDto"
}
}
},
"description": ""
}
},
"security": [
{
"bearer": []
},
{
"cookie": []
},
{
"api_key": []
}
],
"tags": [
"User"
]
} }
}, },
"/users/{id}/restore": { "/users/{id}/restore": {

View file

@ -2750,16 +2750,6 @@ export function updateUser({ updateUserDto }: {
body: updateUserDto body: updateUserDto
}))); })));
} }
export function getUserById({ id }: {
id: string;
}, opts?: Oazapfts.RequestOpts) {
return oazapfts.ok(oazapfts.fetchJson<{
status: 200;
data: UserResponseDto;
}>(`/users/info/${encodeURIComponent(id)}`, {
...opts
}));
}
export function getMyUserInfo(opts?: Oazapfts.RequestOpts) { export function getMyUserInfo(opts?: Oazapfts.RequestOpts) {
return oazapfts.ok(oazapfts.fetchJson<{ return oazapfts.ok(oazapfts.fetchJson<{
status: 200; status: 200;
@ -2809,6 +2799,16 @@ export function deleteUser({ id, deleteUserDto }: {
body: deleteUserDto body: deleteUserDto
}))); })));
} }
export function getUserById({ id }: {
id: string;
}, opts?: Oazapfts.RequestOpts) {
return oazapfts.ok(oazapfts.fetchJson<{
status: 200;
data: UserResponseDto;
}>(`/users/${encodeURIComponent(id)}`, {
...opts
}));
}
export function restoreUser({ id }: { export function restoreUser({ id }: {
id: string; id: string;
}, opts?: Oazapfts.RequestOpts) { }, opts?: Oazapfts.RequestOpts) {

View file

@ -41,10 +41,10 @@ export class UserController {
return this.service.getAll(auth, isAll); return this.service.getAll(auth, isAll);
} }
@Get('info/:id') @Post()
@Authenticated() @Authenticated({ admin: true })
getUserById(@Param() { id }: UUIDParamDto): Promise<UserResponseDto> { createUser(@Body() createUserDto: CreateUserDto): Promise<UserResponseDto> {
return this.service.get(id); return this.service.create(createUserDto);
} }
@Get('me') @Get('me')
@ -53,10 +53,10 @@ export class UserController {
return this.service.getMe(auth); return this.service.getMe(auth);
} }
@Post() @Get(':id')
@Authenticated({ admin: true }) @Authenticated()
createUser(@Body() createUserDto: CreateUserDto): Promise<UserResponseDto> { getUserById(@Param() { id }: UUIDParamDto): Promise<UserResponseDto> {
return this.service.create(createUserDto); return this.service.get(id);
} }
@Delete('profile-image') @Delete('profile-image')