2023-02-25 09:12:03 -05:00
|
|
|
import { IAlbumRepository } from '@app/domain';
|
|
|
|
|
import { Injectable } from '@nestjs/common';
|
|
|
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
2023-03-18 08:44:42 -05:00
|
|
|
import { In, Repository } from 'typeorm';
|
2023-02-25 09:12:03 -05:00
|
|
|
import { AlbumEntity } from '../entities';
|
|
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class AlbumRepository implements IAlbumRepository {
|
|
|
|
|
constructor(@InjectRepository(AlbumEntity) private repository: Repository<AlbumEntity>) {}
|
|
|
|
|
|
2023-03-18 08:44:42 -05:00
|
|
|
getByIds(ids: string[]): Promise<AlbumEntity[]> {
|
|
|
|
|
return this.repository.find({
|
|
|
|
|
where: {
|
|
|
|
|
id: In(ids),
|
|
|
|
|
},
|
|
|
|
|
relations: {
|
|
|
|
|
owner: true,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-25 09:12:03 -05:00
|
|
|
async deleteAll(userId: string): Promise<void> {
|
|
|
|
|
await this.repository.delete({ ownerId: userId });
|
|
|
|
|
}
|
2023-03-02 21:47:08 -05:00
|
|
|
|
|
|
|
|
getAll(): Promise<AlbumEntity[]> {
|
2023-03-18 08:44:42 -05:00
|
|
|
return this.repository.find({
|
|
|
|
|
relations: {
|
|
|
|
|
owner: true,
|
|
|
|
|
},
|
|
|
|
|
});
|
2023-03-02 21:47:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async save(album: Partial<AlbumEntity>) {
|
|
|
|
|
const { id } = await this.repository.save(album);
|
|
|
|
|
return this.repository.findOneOrFail({ where: { id } });
|
|
|
|
|
}
|
2023-02-25 09:12:03 -05:00
|
|
|
}
|