import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { EnterpriseData } from '../entity/enterprise.entity'; import { Repository } from 'typeorm'; @Injectable() export class EnterpriseRepository { constructor( @InjectRepository(EnterpriseData) private readonly enterpriseRepository: Repository, ) {} async save(enterpriseData: EnterpriseData) { enterpriseData.created_date = new Date(); return await this.enterpriseRepository.save(enterpriseData); } async update(enterpriseData: EnterpriseData): Promise { const existingEnterprise = await this.enterpriseRepository.findOne({ where: { id: enterpriseData.id }, }); if (!existingEnterprise) { throw new Error(`Enterprise with id ${enterpriseData.id} not found`); } enterpriseData.modified_date = new Date(); await this.enterpriseRepository.update(enterpriseData.id, enterpriseData); return await this.enterpriseRepository.findOne({ where: { id: enterpriseData.id }, }); } }