mirror of
https://github.com/immich-app/immich.git
synced 2025-01-01 08:31:59 +00:00
refactor(server): session interface types (#8977)
This commit is contained in:
parent
cef84f6ced
commit
a93534fc3c
3 changed files with 12 additions and 10 deletions
|
@ -2,10 +2,12 @@ import { SessionEntity } from 'src/entities/session.entity';
|
||||||
|
|
||||||
export const ISessionRepository = 'ISessionRepository';
|
export const ISessionRepository = 'ISessionRepository';
|
||||||
|
|
||||||
|
type E = SessionEntity;
|
||||||
|
|
||||||
export interface ISessionRepository {
|
export interface ISessionRepository {
|
||||||
create(dto: Partial<SessionEntity>): Promise<SessionEntity>;
|
create<T extends Partial<E>>(dto: T): Promise<T>;
|
||||||
update(dto: Partial<SessionEntity>): Promise<SessionEntity>;
|
update<T extends Partial<E>>(dto: T): Promise<T>;
|
||||||
delete(id: string): Promise<void>;
|
delete(id: string): Promise<void>;
|
||||||
getByToken(token: string): Promise<SessionEntity | null>;
|
getByToken(token: string): Promise<E | null>;
|
||||||
getByUserId(userId: string): Promise<SessionEntity[]>;
|
getByUserId(userId: string): Promise<E[]>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,12 +31,12 @@ export class SessionRepository implements ISessionRepository {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
create(session: Partial<SessionEntity>): Promise<SessionEntity> {
|
create<T extends Partial<SessionEntity>>(dto: T): Promise<T & { id: string }> {
|
||||||
return this.repository.save(session);
|
return this.repository.save(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
update(session: Partial<SessionEntity>): Promise<SessionEntity> {
|
update<T extends Partial<SessionEntity>>(dto: T): Promise<T> {
|
||||||
return this.repository.save(session);
|
return this.repository.save(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GenerateSql({ params: [DummyValue.UUID] })
|
@GenerateSql({ params: [DummyValue.UUID] })
|
||||||
|
|
|
@ -3,8 +3,8 @@ import { Mocked, vitest } from 'vitest';
|
||||||
|
|
||||||
export const newSessionRepositoryMock = (): Mocked<ISessionRepository> => {
|
export const newSessionRepositoryMock = (): Mocked<ISessionRepository> => {
|
||||||
return {
|
return {
|
||||||
create: vitest.fn(),
|
create: vitest.fn() as any,
|
||||||
update: vitest.fn(),
|
update: vitest.fn() as any,
|
||||||
delete: vitest.fn(),
|
delete: vitest.fn(),
|
||||||
getByToken: vitest.fn(),
|
getByToken: vitest.fn(),
|
||||||
getByUserId: vitest.fn(),
|
getByUserId: vitest.fn(),
|
||||||
|
|
Loading…
Reference in a new issue