chore(server): remove user count endpoint (#4724)

* chore: remove unused endpoint

* chore: open api
This commit is contained in:
Jason Rasmussen
2023-10-30 15:29:18 -04:00
committed by GitHub
parent 2f87463170
commit 8dcd159bd6
21 changed files with 3 additions and 613 deletions

View File

@@ -5177,48 +5177,6 @@
]
}
},
"/user/count": {
"get": {
"operationId": "getUserCount",
"parameters": [
{
"name": "admin",
"required": false,
"in": "query",
"schema": {
"default": false,
"type": "boolean"
}
}
],
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UserCountResponseDto"
}
}
},
"description": ""
}
},
"security": [
{
"bearer": []
},
{
"cookie": []
},
{
"api_key": []
}
],
"tags": [
"User"
]
}
},
"/user/info/{id}": {
"get": {
"operationId": "getUserById",
@@ -8769,17 +8727,6 @@
],
"type": "object"
},
"UserCountResponseDto": {
"properties": {
"userCount": {
"type": "integer"
}
},
"required": [
"userCount"
],
"type": "object"
},
"UserResponseDto": {
"properties": {
"createdAt": {

View File

@@ -1,4 +1,3 @@
export * from './create-profile-image.dto';
export * from './create-user.dto';
export * from './update-user.dto';
export * from './user-count.dto';

View File

@@ -1,13 +0,0 @@
import { Transform } from 'class-transformer';
import { IsBoolean } from 'class-validator';
import { Optional } from '../../domain.util';
export class UserCountDto {
@IsBoolean()
@Optional()
@Transform(({ value }) => value === 'true')
/**
* When true, return the number of admins accounts
*/
admin?: boolean = false;
}

View File

@@ -1,3 +1,2 @@
export * from './create-profile-image-response.dto';
export * from './user-count-response.dto';
export * from './user-response.dto';

View File

@@ -1,12 +0,0 @@
import { ApiProperty } from '@nestjs/swagger';
export class UserCountResponseDto {
@ApiProperty({ type: 'integer' })
userCount!: number;
}
export function mapUserCountResponse(count: number): UserCountResponseDto {
return {
userCount: count,
};
}

View File

@@ -220,24 +220,6 @@ describe(UserService.name, () => {
});
});
describe('getCount', () => {
it('should get the user count', async () => {
userMock.getList.mockResolvedValue([adminUser]);
const response = await sut.getCount({});
expect(userMock.getList).toHaveBeenCalled();
expect(response).toEqual({ userCount: 1 });
});
it('should get the user count of all admin users', async () => {
userMock.getList.mockResolvedValue([adminUser, immichUser]);
await expect(sut.getCount({ admin: true })).resolves.toEqual({ userCount: 1 });
expect(userMock.getList).toHaveBeenCalled();
});
});
describe('update', () => {
it('should update user', async () => {
const update: UpdateUserDto = {

View File

@@ -14,15 +14,8 @@ import {
IUserRepository,
} from '../repositories';
import { StorageCore, StorageFolder } from '../storage';
import { CreateUserDto, UpdateUserDto, UserCountDto } from './dto';
import {
CreateProfileImageResponseDto,
UserCountResponseDto,
UserResponseDto,
mapCreateProfileImageResponse,
mapUser,
mapUserCountResponse,
} from './response-dto';
import { CreateUserDto, UpdateUserDto } from './dto';
import { CreateProfileImageResponseDto, UserResponseDto, mapCreateProfileImageResponse, mapUser } from './response-dto';
import { UserCore } from './user.core';
@Injectable()
@@ -64,16 +57,6 @@ export class UserService {
return mapUser(user);
}
async getCount(dto: UserCountDto): Promise<UserCountResponseDto> {
let users = await this.userCore.getList();
if (dto.admin) {
users = users.filter((user) => user.isAdmin);
}
return mapUserCountResponse(users.length);
}
async create(createUserDto: CreateUserDto): Promise<UserResponseDto> {
const createdUser = await this.userCore.createUser(createUserDto);
return mapUser(createdUser);

View File

@@ -1,11 +1,9 @@
import {
AuthUserDto,
UserCountDto as CountDto,
CreateUserDto as CreateDto,
CreateProfileImageDto,
CreateProfileImageResponseDto,
UpdateUserDto as UpdateDto,
UserCountResponseDto,
UserResponseDto,
UserService,
} from '@app/domain';
@@ -59,12 +57,6 @@ export class UserController {
return this.service.create(createUserDto);
}
@AdminRoute()
@Get('count')
getUserCount(@Query() dto: CountDto): Promise<UserCountResponseDto> {
return this.service.getCount(dto);
}
@AdminRoute()
@Delete(':id')
deleteUser(@AuthUser() authUser: AuthUserDto, @Param() { id }: UUIDParamDto): Promise<UserResponseDto> {

View File

@@ -312,32 +312,4 @@ describe(`${UserController.name}`, () => {
expect(before.updatedAt).not.toEqual(after.updatedAt);
});
});
describe('GET /user/count', () => {
it('should require authentication', async () => {
const { status, body } = await request(server).get(`/user/count`);
expect(status).toBe(401);
expect(body).toEqual(errorStub.unauthorized);
});
it('should start with just the admin', async () => {
const { status, body } = await request(server).get(`/user/count`).set('Authorization', `Bearer ${accessToken}`);
expect(status).toBe(200);
expect(body).toEqual({ userCount: 1 });
});
it('should return the total user count', async () => {
for (let i = 0; i < 5; i++) {
await api.userApi.create(server, accessToken, {
email: `user${i + 1}@immich.app`,
password: 'Password123',
firstName: `User ${i + 1}`,
lastName: 'Test',
});
}
const { status, body } = await request(server).get(`/user/count`).set('Authorization', `Bearer ${accessToken}`);
expect(status).toBe(200);
expect(body).toEqual({ userCount: 6 });
});
});
});