import { BaseRepository } from '@edr/api-common'; import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { DeepPartial, EntityManager, In, Repository } from 'typeorm'; import { WagonAllocationContainerItem } from './entities/wagon-allocation-container-item.entity'; @Injectable() export class WagonAllocationContainerItemsRepository extends BaseRepository { constructor( @InjectRepository(WagonAllocationContainerItem) repository: Repository, ) { super(repository); } private repo(manager?: EntityManager) { return manager ? manager.getRepository(WagonAllocationContainerItem) : this.repository; } async createMany( items: DeepPartial[], manager?: EntityManager, ): Promise { if (!items.length) return []; const repo = this.repo(manager); return repo.save(repo.create(items)); } async deleteByAllocationIds(allocationIds: string[], manager?: EntityManager): Promise { if (!allocationIds.length) return; await this.repo(manager).delete({ wagonBookingAllocationId: In(allocationIds) }); } }