feat: add update supplier endpoint
This commit is contained in:
parent
e6659481de
commit
091d4220db
4
src/users/dto/update-supplier.dto.ts
Normal file
4
src/users/dto/update-supplier.dto.ts
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
import { PartialType } from '@nestjs/mapped-types';
|
||||||
|
import { CreateSupplierDto } from './create-supplier.dto';
|
||||||
|
|
||||||
|
export class UpdateSupplierDto extends PartialType(CreateSupplierDto) {}
|
|
@ -6,13 +6,14 @@ import {
|
||||||
Injectable,
|
Injectable,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
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 { Supplier } from '../entities/supplier.entity';
|
||||||
import { InputCoaDto } from '../../transaction/dto/input-coa.dto';
|
import { InputCoaDto } from '../../transaction/dto/input-coa.dto';
|
||||||
import { balanceType, coaType } from '../../helper/enum-list';
|
import { balanceType, coaType } from '../../helper/enum-list';
|
||||||
import { CreateSupplierDto } from '../dto/create-supplier.dto';
|
import { CreateSupplierDto } from '../dto/create-supplier.dto';
|
||||||
import { CoaService } from '../../transaction/coa.service';
|
import { CoaService } from '../../transaction/coa.service';
|
||||||
import * as uuid from 'uuid';
|
import * as uuid from 'uuid';
|
||||||
|
import { UpdateSupplierDto } from '../dto/update-supplier.dto';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SupplierService {
|
export class SupplierService {
|
||||||
|
@ -84,6 +85,34 @@ export class SupplierService {
|
||||||
return supplierData;
|
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) {
|
findAllSupplier(page) {
|
||||||
return this.supplierRepository.findAndCount({
|
return this.supplierRepository.findAndCount({
|
||||||
skip: page * 10,
|
skip: page * 10,
|
||||||
|
|
|
@ -20,6 +20,7 @@ import { SupplierService } from './supplier/supplier.service';
|
||||||
import { PartnerService } from './partner/partner.service';
|
import { PartnerService } from './partner/partner.service';
|
||||||
import { CreatePartnerDto } from './dto/create-partner.dto';
|
import { CreatePartnerDto } from './dto/create-partner.dto';
|
||||||
import { UpdatePartnerDto } from './dto/update-partner.dto';
|
import { UpdatePartnerDto } from './dto/update-partner.dto';
|
||||||
|
import { UpdateSupplierDto } from './dto/update-supplier.dto';
|
||||||
|
|
||||||
@Controller({
|
@Controller({
|
||||||
path: 'users',
|
path: 'users',
|
||||||
|
@ -50,6 +51,18 @@ export class UsersController {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Put('supplier/:id')
|
||||||
|
async updateSupplier(
|
||||||
|
@Param('id', ParseUUIDPipe) id: string,
|
||||||
|
@Body() updatePartnerDto: UpdateSupplierDto,
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
data: await this.supplierService.update(id, updatePartnerDto),
|
||||||
|
statusCode: HttpStatus.CREATED,
|
||||||
|
message: 'success',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Post('partner')
|
@Post('partner')
|
||||||
async createPartner(
|
async createPartner(
|
||||||
@Request() req,
|
@Request() req,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user