feat: add update supplier endpoint
This commit is contained in:
@@ -6,13 +6,14 @@ import {
|
||||
Injectable,
|
||||
} from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Connection, EntityNotFoundError, Repository } from 'typeorm';
|
||||
import { Connection, EntityNotFoundError, Not, Repository } from 'typeorm';
|
||||
import { Supplier } from '../entities/supplier.entity';
|
||||
import { InputCoaDto } from '../../transaction/dto/input-coa.dto';
|
||||
import { balanceType, coaType } from '../../helper/enum-list';
|
||||
import { CreateSupplierDto } from '../dto/create-supplier.dto';
|
||||
import { CoaService } from '../../transaction/coa.service';
|
||||
import * as uuid from 'uuid';
|
||||
import { UpdateSupplierDto } from '../dto/update-supplier.dto';
|
||||
|
||||
@Injectable()
|
||||
export class SupplierService {
|
||||
@@ -84,6 +85,34 @@ export class SupplierService {
|
||||
return supplierData;
|
||||
}
|
||||
|
||||
async update(id: string, updateSupplierDto: UpdateSupplierDto) {
|
||||
const check = await this.supplierRepository.findOne({
|
||||
code: updateSupplierDto.code,
|
||||
id: Not(id),
|
||||
});
|
||||
|
||||
if (check) {
|
||||
throw new HttpException(
|
||||
{
|
||||
statusCode: HttpStatus.NOT_ACCEPTABLE,
|
||||
error: 'Supplier Already Exist',
|
||||
},
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
}
|
||||
|
||||
const supplierData = new Supplier();
|
||||
|
||||
supplierData.name = updateSupplierDto.name;
|
||||
supplierData.status = true;
|
||||
|
||||
await this.connection.transaction(async (manager) => {
|
||||
await manager.update(Supplier, { id: id }, supplierData);
|
||||
});
|
||||
|
||||
return supplierData;
|
||||
}
|
||||
|
||||
findAllSupplier(page) {
|
||||
return this.supplierRepository.findAndCount({
|
||||
skip: page * 10,
|
||||
|
||||
Reference in New Issue
Block a user