From ecd018a82685b5be065b3b07b740b68d9bd4005d Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Wed, 22 May 2024 14:15:33 -0400 Subject: [PATCH] refactor(server): user info endpoint (#9668) * refactor(server): user info endpoint * chore: open api --- e2e/src/api/specs/user.e2e-spec.ts | 6 +- mobile/openapi/README.md | Bin 27350 -> 27345 bytes mobile/openapi/lib/api/user_api.dart | Bin 15790 -> 15780 bytes open-api/immich-openapi-specs.json | 82 ++++++++++---------- open-api/typescript-sdk/src/fetch-client.ts | 20 ++--- server/src/controllers/user.controller.ts | 16 ++-- 6 files changed, 61 insertions(+), 63 deletions(-) diff --git a/e2e/src/api/specs/user.e2e-spec.ts b/e2e/src/api/specs/user.e2e-spec.ts index 7518e732ec..08b2d34ef6 100644 --- a/e2e/src/api/specs/user.e2e-spec.ts +++ b/e2e/src/api/specs/user.e2e-spec.ts @@ -93,15 +93,15 @@ describe('/users', () => { }); }); - describe('GET /users/info/:id', () => { + describe('GET /users/:id', () => { 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); }); it('should get the user info', async () => { const { status, body } = await request(app) - .get(`/users/info/${admin.userId}`) + .get(`/users/${admin.userId}`) .set('Authorization', `Bearer ${admin.accessToken}`); expect(status).toBe(200); expect(body).toMatchObject({ diff --git a/mobile/openapi/README.md b/mobile/openapi/README.md index e23b1fea7688e74fe32d7252ad3000ff67f28673..ad38d3f49e6f5dd14038e7509ac14ba687ae950d 100644 GIT binary patch delta 18 acmcb1mGR5@wS?3x0bZwT*ytMqu6IH7x3+m)RIJzQnlVb($ZQh~#h93Yo)DOM@ diff --git a/open-api/immich-openapi-specs.json b/open-api/immich-openapi-specs.json index 929338b734..cb334534bd 100644 --- a/open-api/immich-openapi-specs.json +++ b/open-api/immich-openapi-specs.json @@ -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": { "get": { "operationId": "getMyUserInfo", @@ -6462,6 +6420,46 @@ "tags": [ "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": { diff --git a/open-api/typescript-sdk/src/fetch-client.ts b/open-api/typescript-sdk/src/fetch-client.ts index 02ff002f01..29a8f5c0fe 100644 --- a/open-api/typescript-sdk/src/fetch-client.ts +++ b/open-api/typescript-sdk/src/fetch-client.ts @@ -2750,16 +2750,6 @@ export function updateUser({ 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) { return oazapfts.ok(oazapfts.fetchJson<{ status: 200; @@ -2809,6 +2799,16 @@ export function deleteUser({ id, 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 }: { id: string; }, opts?: Oazapfts.RequestOpts) { diff --git a/server/src/controllers/user.controller.ts b/server/src/controllers/user.controller.ts index a1720dd404..4c058e7aae 100644 --- a/server/src/controllers/user.controller.ts +++ b/server/src/controllers/user.controller.ts @@ -41,10 +41,10 @@ export class UserController { return this.service.getAll(auth, isAll); } - @Get('info/:id') - @Authenticated() - getUserById(@Param() { id }: UUIDParamDto): Promise { - return this.service.get(id); + @Post() + @Authenticated({ admin: true }) + createUser(@Body() createUserDto: CreateUserDto): Promise { + return this.service.create(createUserDto); } @Get('me') @@ -53,10 +53,10 @@ export class UserController { return this.service.getMe(auth); } - @Post() - @Authenticated({ admin: true }) - createUser(@Body() createUserDto: CreateUserDto): Promise { - return this.service.create(createUserDto); + @Get(':id') + @Authenticated() + getUserById(@Param() { id }: UUIDParamDto): Promise { + return this.service.get(id); } @Delete('profile-image')