mirror of
https://github.com/immich-app/immich.git
synced 2025-03-04 02:11:44 -05:00
* refactor(server): user endpoints * fix repos * fix unit tests --------- Co-authored-by: Daniel Dietzler <mail@ddietzler.dev> Co-authored-by: Alex <alex.tran1502@gmail.com>
58 lines
1.7 KiB
TypeScript
58 lines
1.7 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
import { DummyValue, GenerateSql } from 'src/decorators';
|
|
import { SessionEntity } from 'src/entities/session.entity';
|
|
import { ISessionRepository, SessionSearchOptions } from 'src/interfaces/session.interface';
|
|
import { Instrumentation } from 'src/utils/instrumentation';
|
|
import { LessThanOrEqual, Repository } from 'typeorm';
|
|
|
|
@Instrumentation()
|
|
@Injectable()
|
|
export class SessionRepository implements ISessionRepository {
|
|
constructor(@InjectRepository(SessionEntity) private repository: Repository<SessionEntity>) {}
|
|
|
|
@GenerateSql({ params: [DummyValue.DATE] })
|
|
search(options: SessionSearchOptions): Promise<SessionEntity[]> {
|
|
return this.repository.find({ where: { updatedAt: LessThanOrEqual(options.updatedBefore) } });
|
|
}
|
|
|
|
@GenerateSql({ params: [DummyValue.STRING] })
|
|
getByToken(token: string): Promise<SessionEntity | null> {
|
|
return this.repository.findOne({
|
|
where: { token },
|
|
relations: {
|
|
user: {
|
|
metadata: true,
|
|
},
|
|
},
|
|
});
|
|
}
|
|
|
|
getByUserId(userId: string): Promise<SessionEntity[]> {
|
|
return this.repository.find({
|
|
where: {
|
|
userId,
|
|
},
|
|
relations: {
|
|
user: true,
|
|
},
|
|
order: {
|
|
updatedAt: 'desc',
|
|
createdAt: 'desc',
|
|
},
|
|
});
|
|
}
|
|
|
|
create<T extends Partial<SessionEntity>>(dto: T): Promise<T & { id: string }> {
|
|
return this.repository.save(dto);
|
|
}
|
|
|
|
update<T extends Partial<SessionEntity>>(dto: T): Promise<T> {
|
|
return this.repository.save(dto);
|
|
}
|
|
|
|
@GenerateSql({ params: [DummyValue.UUID] })
|
|
async delete(id: string): Promise<void> {
|
|
await this.repository.delete({ id });
|
|
}
|
|
}
|