1
0
Fork 0
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:
Jason Rasmussen 2024-04-20 23:45:55 -04:00 committed by GitHub
parent cef84f6ced
commit a93534fc3c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 10 deletions

View file

@ -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[]>;
} }

View file

@ -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] })

View file

@ -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(),