2023-02-25 09:12:03 -05:00
|
|
|
import { IAlbumRepository } from '@app/domain';
|
|
|
|
|
import { Injectable } from '@nestjs/common';
|
|
|
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
|
|
|
import { Repository } from 'typeorm';
|
|
|
|
|
import { AlbumEntity } from '../entities';
|
|
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class AlbumRepository implements IAlbumRepository {
|
|
|
|
|
constructor(@InjectRepository(AlbumEntity) private repository: Repository<AlbumEntity>) {}
|
|
|
|
|
|
|
|
|
|
async deleteAll(userId: string): Promise<void> {
|
|
|
|
|
await this.repository.delete({ ownerId: userId });
|
|
|
|
|
}
|
2023-03-02 21:47:08 -05:00
|
|
|
|
|
|
|
|
getAll(): Promise<AlbumEntity[]> {
|
|
|
|
|
return this.repository.find();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|