Skip to content

Commit

Permalink
refactor(server): user info endpoint (#9668)
Browse files Browse the repository at this point in the history
* refactor(server): user info endpoint

* chore: open api
  • Loading branch information
jrasm91 committed May 22, 2024
1 parent 202745f commit ecd018a
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 66 deletions.
6 changes: 3 additions & 3 deletions e2e/src/api/specs/user.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion mobile/openapi/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions mobile/openapi/lib/api/user_api.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 40 additions & 42 deletions open-api/immich-openapi-specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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": {
Expand Down
20 changes: 10 additions & 10 deletions open-api/typescript-sdk/src/fetch-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
16 changes: 8 additions & 8 deletions server/src/controllers/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ export class UserController {
return this.service.getAll(auth, isAll);
}

@Get('info/:id')
@Authenticated()
getUserById(@Param() { id }: UUIDParamDto): Promise<UserResponseDto> {
return this.service.get(id);
@Post()
@Authenticated({ admin: true })
createUser(@Body() createUserDto: CreateUserDto): Promise<UserResponseDto> {
return this.service.create(createUserDto);
}

@Get('me')
Expand All @@ -53,10 +53,10 @@ export class UserController {
return this.service.getMe(auth);
}

@Post()
@Authenticated({ admin: true })
createUser(@Body() createUserDto: CreateUserDto): Promise<UserResponseDto> {
return this.service.create(createUserDto);
@Get(':id')
@Authenticated()
getUserById(@Param() { id }: UUIDParamDto): Promise<UserResponseDto> {
return this.service.get(id);
}

@Delete('profile-image')
Expand Down

0 comments on commit ecd018a

Please sign in to comment.