Skip to content

Commit

Permalink
change endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
martabal committed Apr 25, 2024
1 parent 3f2e91d commit fbefa67
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 78 deletions.
4 changes: 3 additions & 1 deletion e2e/src/api/specs/asset.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,9 @@ describe('/asset', () => {
expect(body).toEqual({ id: expect.any(String), duplicate: false });
expect(status).toBe(201);

const { body: user } = await request(app).get('/user/me').set('Authorization', `Bearer ${quotaUser.accessToken}`);
const { body: user } = await request(app)
.get('/auth/user')
.set('Authorization', `Bearer ${quotaUser.accessToken}`);

expect(user).toEqual(expect.objectContaining({ quotaUsageInBytes: 70 }));
});
Expand Down
24 changes: 11 additions & 13 deletions e2e/src/api/specs/user.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ describe('/user', () => {
});

it('should get users', async () => {
const { status, body } = await request(app)
.get('/user/admin')
.set('Authorization', `Bearer ${admin.accessToken}`);
const { status, body } = await request(app).get('/user').set('Authorization', `Bearer ${admin.accessToken}`);
expect(status).toEqual(200);
expect(body).toHaveLength(5);
expect(body).toEqual(
Expand Down Expand Up @@ -77,7 +75,7 @@ describe('/user', () => {

it('should include deleted users', async () => {
const { status, body } = await request(app)
.get(`/user/admin`)
.get(`/user`)
.query({ isAll: false })
.set('Authorization', `Bearer ${admin.accessToken}`);

Expand Down Expand Up @@ -113,15 +111,15 @@ describe('/user', () => {
});
});

describe('GET /user/me', () => {
describe('GET /auth/user', () => {
it('should require authentication', async () => {
const { status, body } = await request(app).get(`/user/me`);
const { status, body } = await request(app).get(`/auth/user`);
expect(status).toBe(401);
expect(body).toEqual(errorDto.unauthorized);
});

it('should get my info', async () => {
const { status, body } = await request(app).get(`/user/me`).set('Authorization', `Bearer ${admin.accessToken}`);
const { status, body } = await request(app).get(`/auth/user`).set('Authorization', `Bearer ${admin.accessToken}`);
expect(status).toBe(200);
expect(body).toMatchObject({
id: admin.userId,
Expand All @@ -140,7 +138,7 @@ describe('/user', () => {
for (const key of Object.keys(createUserDto.user1)) {
it(`should not allow null ${key}`, async () => {
const { status, body } = await request(app)
.post(`/user`)
.post(`/public-users`)
.set('Authorization', `Bearer ${admin.accessToken}`)
.send({ ...createUserDto.user1, [key]: null });
expect(status).toBe(400);

Check failure on line 144 in e2e/src/api/specs/user.e2e-spec.ts

View workflow job for this annotation

GitHub Actions / End-to-End Tests

src/api/specs/user.e2e-spec.ts > /user > POST /user > should not allow null email

AssertionError: expected 404 to be 400 // Object.is equality - Expected + Received - 400 + 404 ❯ src/api/specs/user.e2e-spec.ts:144:24

Check failure on line 144 in e2e/src/api/specs/user.e2e-spec.ts

View workflow job for this annotation

GitHub Actions / End-to-End Tests

src/api/specs/user.e2e-spec.ts > /user > POST /user > should not allow null name

AssertionError: expected 404 to be 400 // Object.is equality - Expected + Received - 400 + 404 ❯ src/api/specs/user.e2e-spec.ts:144:24

Check failure on line 144 in e2e/src/api/specs/user.e2e-spec.ts

View workflow job for this annotation

GitHub Actions / End-to-End Tests

src/api/specs/user.e2e-spec.ts > /user > POST /user > should not allow null password

AssertionError: expected 404 to be 400 // Object.is equality - Expected + Received - 400 + 404 ❯ src/api/specs/user.e2e-spec.ts:144:24
Expand Down Expand Up @@ -223,15 +221,15 @@ describe('/user', () => {

describe('PUT /user', () => {
it('should require authentication', async () => {
const { status, body } = await request(app).put(`/user`);
const { status, body } = await request(app).put(`/public-users`);
expect(status).toBe(401);
expect(body).toEqual(errorDto.unauthorized);
});

for (const key of Object.keys(userDto.admin)) {
it(`should not allow null ${key}`, async () => {
const { status, body } = await request(app)
.put(`/user`)
.put(`/public-users`)
.set('Authorization', `Bearer ${admin.accessToken}`)
.send({ ...userDto.admin, [key]: null });
expect(status).toBe(400);
Expand All @@ -241,7 +239,7 @@ describe('/user', () => {

it('should not allow a non-admin to become an admin', async () => {
const { status, body } = await request(app)
.put(`/user`)
.put(`/public-users`)
.send({ isAdmin: true, id: nonAdmin.userId })
.set('Authorization', `Bearer ${admin.accessToken}`);

Expand All @@ -251,7 +249,7 @@ describe('/user', () => {

it('ignores updates to profileImagePath', async () => {
const { status, body } = await request(app)
.put(`/user`)
.put(`/public-users`)
.send({ id: admin.userId, profileImagePath: 'invalid.jpg' })
.set('Authorization', `Bearer ${admin.accessToken}`);

Expand All @@ -263,7 +261,7 @@ describe('/user', () => {
const before = await getUserById({ id: admin.userId }, { headers: asBearerAuth(admin.accessToken) });

const { status, body } = await request(app)
.put(`/user`)
.put(`/public-users`)
.send({
id: admin.userId,
createdAt: '2023-01-01T00:00:00.000Z',
Expand Down
6 changes: 3 additions & 3 deletions mobile/openapi/README.md

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

2 changes: 1 addition & 1 deletion mobile/openapi/doc/AuthenticationApi.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/doc/UserApi.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/authentication_api.dart

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

8 changes: 4 additions & 4 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.

68 changes: 33 additions & 35 deletions open-api/immich-openapi-specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2540,7 +2540,7 @@
]
}
},
"/auth/me": {
"/auth/user": {
"get": {
"operationId": "getMyUserInfo",
"parameters": [],
Expand Down Expand Up @@ -6995,25 +6995,27 @@
}
},
"/user": {
"post": {
"operationId": "createUser",
"parameters": [],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/CreateUserDto"
}
"get": {
"operationId": "getAllUsers",
"parameters": [
{
"name": "isAll",
"required": true,
"in": "query",
"schema": {
"type": "boolean"
}
},
"required": true
},
}
],
"responses": {
"201": {
"200": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UserResponseDto"
"items": {
"$ref": "#/components/schemas/UserResponseDto"
},
"type": "array"
}
}
},
Expand All @@ -7034,30 +7036,26 @@
"tags": [
"User"
]
}
},
"/user/admin": {
"get": {
"operationId": "getAllUsers",
"parameters": [
{
"name": "isAll",
"required": true,
"in": "query",
"schema": {
"type": "boolean"
},
"post": {
"operationId": "createUser",
"parameters": [],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/CreateUserDto"
}
}
}
],
},
"required": true
},
"responses": {
"200": {
"201": {
"content": {
"application/json": {
"schema": {
"items": {
"$ref": "#/components/schemas/UserResponseDto"
},
"type": "array"
"$ref": "#/components/schemas/UserResponseDto"
}
}
},
Expand All @@ -7080,7 +7078,7 @@
]
}
},
"/user/admin/info/{id}": {
"/user/info/{id}": {
"get": {
"operationId": "getUserById",
"parameters": [
Expand Down
28 changes: 14 additions & 14 deletions open-api/typescript-sdk/src/fetch-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1722,7 +1722,7 @@ export function getMyUserInfo(opts?: Oazapfts.RequestOpts) {
return oazapfts.ok(oazapfts.fetchJson<{
status: 200;
data: UserResponseDto;
}>("/auth/me", {
}>("/auth/user", {
...opts
}));
}
Expand Down Expand Up @@ -2878,6 +2878,18 @@ export function restoreAssets({ bulkIdsDto }: {
body: bulkIdsDto
})));
}
export function getAllUsers({ isAll }: {
isAll: boolean;
}, opts?: Oazapfts.RequestOpts) {
return oazapfts.ok(oazapfts.fetchJson<{
status: 200;
data: UserResponseDto[];
}>(`/user${QS.query(QS.explode({
isAll
}))}`, {
...opts
}));
}
export function createUser({ createUserDto }: {
createUserDto: CreateUserDto;
}, opts?: Oazapfts.RequestOpts) {
Expand All @@ -2890,25 +2902,13 @@ export function createUser({ createUserDto }: {
body: createUserDto
})));
}
export function getAllUsers({ isAll }: {
isAll: boolean;
}, opts?: Oazapfts.RequestOpts) {
return oazapfts.ok(oazapfts.fetchJson<{
status: 200;
data: UserResponseDto[];
}>(`/user/admin${QS.query(QS.explode({
isAll
}))}`, {
...opts
}));
}
export function getUserById({ id }: {
id: string;
}, opts?: Oazapfts.RequestOpts) {
return oazapfts.ok(oazapfts.fetchJson<{
status: 200;
data: UserResponseDto;
}>(`/user/admin/info/${encodeURIComponent(id)}`, {
}>(`/user/info/${encodeURIComponent(id)}`, {
...opts
}));
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/controllers/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class AuthController {
]);
}

@Get('me')
@Get('user')
getMyUserInfo(@Auth() auth: AuthDto): Promise<UserResponseDto> {
return this.userService.getMe(auth);
}
Expand Down
4 changes: 2 additions & 2 deletions server/src/controllers/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import { UUIDParamDto } from 'src/validation';
export class UserController {
constructor(private service: UserService) {}

@Get('admin')
@Get()
getAllUsers(@Query('isAll') isAll: boolean): Promise<UserResponseDto[]> {
return this.service.getAll(isAll);
}

@Get('admin/info/:id')
@Get('info/:id')
getUserById(@Param() { id }: UUIDParamDto): Promise<UserResponseDto> {
return this.service.get(id);
}
Expand Down

0 comments on commit fbefa67

Please sign in to comment.