import { IAssetStackRepository } from '@app/domain'; import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import { AssetStackEntity } from '../entities'; @Injectable() export class AssetStackRepository implements IAssetStackRepository { constructor(@InjectRepository(AssetStackEntity) private repository: Repository) {} create(entity: Partial) { return this.save(entity); } async delete(id: string): Promise { await this.repository.delete(id); } update(entity: Partial) { return this.save(entity); } async getById(id: string): Promise { return this.repository.findOne({ where: { id, }, relations: { primaryAsset: true, assets: true, }, }); } private async save(entity: Partial) { const { id } = await this.repository.save(entity); return this.repository.findOneOrFail({ where: { id, }, relations: { primaryAsset: true, assets: true, }, }); } }