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:
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';
|
||||
|
||||
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[]>;
|
||||
}
|
||||
|
|
|
@ -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] })
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Reference in a new issue