1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2024-12-29 15:11:58 +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';
type E = SessionEntity;
export interface ISessionRepository {
create(dto: Partial<SessionEntity>): Promise<SessionEntity>;
update(dto: Partial<SessionEntity>): Promise<SessionEntity>;
create<T extends Partial<E>>(dto: T): Promise<T>;
update<T extends Partial<E>>(dto: T): Promise<T>;
delete(id: string): Promise<void>;
getByToken(token: string): Promise<SessionEntity | null>;
getByUserId(userId: string): Promise<SessionEntity[]>;
getByToken(token: string): Promise<E | null>;
getByUserId(userId: string): Promise<E[]>;
}

View file

@ -31,12 +31,12 @@ export class SessionRepository implements ISessionRepository {
});
}
create(session: Partial<SessionEntity>): Promise<SessionEntity> {
return this.repository.save(session);
create<T extends Partial<SessionEntity>>(dto: T): Promise<T & { id: string }> {
return this.repository.save(dto);
}
update(session: Partial<SessionEntity>): Promise<SessionEntity> {
return this.repository.save(session);
update<T extends Partial<SessionEntity>>(dto: T): Promise<T> {
return this.repository.save(dto);
}
@GenerateSql({ params: [DummyValue.UUID] })

View file

@ -3,8 +3,8 @@ import { Mocked, vitest } from 'vitest';
export const newSessionRepositoryMock = (): Mocked<ISessionRepository> => {
return {
create: vitest.fn(),
update: vitest.fn(),
create: vitest.fn() as any,
update: vitest.fn() as any,
delete: vitest.fn(),
getByToken: vitest.fn(),
getByUserId: vitest.fn(),