mirror of
https://github.com/immich-app/immich.git
synced 2025-02-11 01:18:24 -05:00
chore: remove unused code (#15499)
This commit is contained in:
parent
8440f146e2
commit
36058b9b59
8 changed files with 11 additions and 56 deletions
|
@ -1,6 +1,7 @@
|
|||
import { SystemConfig } from 'src/config';
|
||||
import { StorageFolder, SystemMetadataKey } from 'src/enum';
|
||||
import { Column, DeepPartial, Entity, PrimaryColumn } from 'typeorm';
|
||||
import { DeepPartial } from 'src/types';
|
||||
import { Column, Entity, PrimaryColumn } from 'typeorm';
|
||||
|
||||
@Entity('system_metadata')
|
||||
export class SystemMetadataEntity<T extends keyof SystemMetadata = SystemMetadataKey> {
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import { UserEntity } from 'src/entities/user.entity';
|
||||
import { UserAvatarColor, UserMetadataKey } from 'src/enum';
|
||||
import { DeepPartial } from 'src/types';
|
||||
import { HumanReadableSize } from 'src/utils/bytes';
|
||||
import { Column, DeepPartial, Entity, ManyToOne, PrimaryColumn } from 'typeorm';
|
||||
import { Column, Entity, ManyToOne, PrimaryColumn } from 'typeorm';
|
||||
|
||||
@Entity('user_metadata')
|
||||
export class UserMetadataEntity<T extends keyof UserMetadata = UserMetadataKey> {
|
||||
|
|
|
@ -17,10 +17,9 @@ import { QueueName } from 'src/interfaces/job.interface';
|
|||
import { ILoggerRepository } from 'src/interfaces/logger.interface';
|
||||
import { ISystemMetadataRepository } from 'src/interfaces/system-metadata.interface';
|
||||
import { SystemConfigService } from 'src/services/system-config.service';
|
||||
import { IConfigRepository } from 'src/types';
|
||||
import { DeepPartial, IConfigRepository } from 'src/types';
|
||||
import { mockEnvData } from 'test/repositories/config.repository.mock';
|
||||
import { newTestService } from 'test/utils';
|
||||
import { DeepPartial } from 'typeorm';
|
||||
import { Mocked } from 'vitest';
|
||||
|
||||
const partialConfig = {
|
||||
|
|
|
@ -7,6 +7,8 @@ import { AuditRepository } from 'src/repositories/audit.repository';
|
|||
import { ConfigRepository } from 'src/repositories/config.repository';
|
||||
import { ViewRepository } from 'src/repositories/view-repository';
|
||||
|
||||
export type DeepPartial<T> = T extends object ? { [K in keyof T]?: DeepPartial<T[K]> } : T;
|
||||
|
||||
export type AuthApiKey = {
|
||||
id: string;
|
||||
key: string;
|
||||
|
|
|
@ -9,9 +9,8 @@ import { SystemMetadataKey } from 'src/enum';
|
|||
import { DatabaseLock } from 'src/interfaces/database.interface';
|
||||
import { ILoggerRepository } from 'src/interfaces/logger.interface';
|
||||
import { ISystemMetadataRepository } from 'src/interfaces/system-metadata.interface';
|
||||
import { IConfigRepository } from 'src/types';
|
||||
import { DeepPartial, IConfigRepository } from 'src/types';
|
||||
import { getKeysDeep, unsetDeep } from 'src/utils/misc';
|
||||
import { DeepPartial } from 'typeorm';
|
||||
|
||||
export type SystemConfigValidator = (config: SystemConfig, newConfig: SystemConfig) => void | Promise<void>;
|
||||
|
||||
|
|
|
@ -1,18 +1,8 @@
|
|||
import _ from 'lodash';
|
||||
import { PaginationMode } from 'src/enum';
|
||||
import { FindManyOptions, ObjectLiteral, Repository, SelectQueryBuilder } from 'typeorm';
|
||||
|
||||
export interface PaginationOptions {
|
||||
take: number;
|
||||
skip?: number;
|
||||
}
|
||||
|
||||
export interface PaginatedBuilderOptions {
|
||||
take: number;
|
||||
skip?: number;
|
||||
mode?: PaginationMode;
|
||||
}
|
||||
|
||||
export interface PaginationResult<T> {
|
||||
items: T[];
|
||||
hasNextPage: boolean;
|
||||
|
@ -33,46 +23,9 @@ export async function* usePagination<T>(
|
|||
}
|
||||
}
|
||||
|
||||
export function paginationHelper<Entity extends ObjectLiteral>(
|
||||
items: Entity[],
|
||||
take: number,
|
||||
): PaginationResult<Entity> {
|
||||
export function paginationHelper<Entity extends object>(items: Entity[], take: number): PaginationResult<Entity> {
|
||||
const hasNextPage = items.length > take;
|
||||
items.splice(take);
|
||||
|
||||
return { items, hasNextPage };
|
||||
}
|
||||
|
||||
export async function paginate<Entity extends ObjectLiteral>(
|
||||
repository: Repository<Entity>,
|
||||
{ take, skip }: PaginationOptions,
|
||||
searchOptions?: FindManyOptions<Entity>,
|
||||
): Paginated<Entity> {
|
||||
const items = await repository.find(
|
||||
_.omitBy(
|
||||
{
|
||||
...searchOptions,
|
||||
// Take one more item to check if there's a next page
|
||||
take: take + 1,
|
||||
skip,
|
||||
},
|
||||
_.isUndefined,
|
||||
),
|
||||
);
|
||||
|
||||
return paginationHelper(items, take);
|
||||
}
|
||||
|
||||
export async function paginatedBuilder<Entity extends ObjectLiteral>(
|
||||
qb: SelectQueryBuilder<Entity>,
|
||||
{ take, skip, mode }: PaginatedBuilderOptions,
|
||||
): Paginated<Entity> {
|
||||
if (mode === PaginationMode.LIMIT_OFFSET) {
|
||||
qb.limit(take + 1).offset(skip);
|
||||
} else {
|
||||
qb.take(take + 1).skip(skip);
|
||||
}
|
||||
|
||||
const items = await qb.getMany();
|
||||
return paginationHelper(items, take);
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@ import { UserPreferencesUpdateDto } from 'src/dtos/user-preferences.dto';
|
|||
import { UserPreferences, getDefaultPreferences } from 'src/entities/user-metadata.entity';
|
||||
import { UserEntity } from 'src/entities/user.entity';
|
||||
import { UserMetadataKey } from 'src/enum';
|
||||
import { DeepPartial } from 'src/types';
|
||||
import { getKeysDeep } from 'src/utils/misc';
|
||||
import { DeepPartial } from 'typeorm';
|
||||
|
||||
export const getPreferences = (user: UserEntity) => {
|
||||
const preferences = getDefaultPreferences(user);
|
||||
|
|
2
server/test/fixtures/system-config.stub.ts
vendored
2
server/test/fixtures/system-config.stub.ts
vendored
|
@ -1,5 +1,5 @@
|
|||
import { SystemConfig } from 'src/config';
|
||||
import { DeepPartial } from 'typeorm';
|
||||
import { DeepPartial } from 'src/types';
|
||||
|
||||
export const systemConfigStub = {
|
||||
enabled: {
|
||||
|
|
Loading…
Add table
Reference in a new issue