import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { MediaData } from '../entity/media-data.entity'; import { Repository } from 'typeorm'; @Injectable() export class MediaDataRepository { constructor( @InjectRepository(MediaData) private readonly mediaRepository: Repository, ) {} async findByAttributeKeyAndMappedEntityIdAndMappedEntityType( attributeKey: string, mappedEntityId: number, mappedEntityType: string, ) { return await this.mediaRepository.findOne({ where: { mapped_attribute_key: attributeKey, mapped_entity_id: mappedEntityId, mapped_entity_type: mappedEntityType, }, }); } async findByMappedEntityIdAndMappedEntityType( mappedEntityId: number, mappedEntityType: string, ) { return await this.mediaRepository.find({ where: { mapped_entity_id: mappedEntityId, mapped_entity_type: mappedEntityType, }, }); } async deleteByAttributeKeyAndMappedEntityIdAndMappedEntityType( attributeKey: string, mappedEntityId: number, mappedEntityType: string, ) { return await this.mediaRepository.delete({ mapped_attribute_key: attributeKey, mapped_entity_id: mappedEntityId, mapped_entity_type: mappedEntityType, }); } }