Merge branch 'development' into 'devops-staging'
Development See merge request empatnusabangsa/ppob/ppob-backend!19
This commit is contained in:
		
							
								
								
									
										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,
 | 
			
		||||
} 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,50 @@ 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;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  setStatus = async (id: string, type: string) => {
 | 
			
		||||
    const supplierData = new Supplier();
 | 
			
		||||
 | 
			
		||||
    if (type === 'active') {
 | 
			
		||||
      supplierData.status = true;
 | 
			
		||||
    } else {
 | 
			
		||||
      supplierData.status = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    await this.connection.transaction(async (manager) => {
 | 
			
		||||
      await manager.update(Supplier, { id: id }, supplierData);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    return supplierData;
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  findAllSupplier(page) {
 | 
			
		||||
    return this.supplierRepository.findAndCount({
 | 
			
		||||
      skip: page * 10,
 | 
			
		||||
 
 | 
			
		||||
@@ -20,6 +20,7 @@ import { SupplierService } from './supplier/supplier.service';
 | 
			
		||||
import { PartnerService } from './partner/partner.service';
 | 
			
		||||
import { CreatePartnerDto } from './dto/create-partner.dto';
 | 
			
		||||
import { UpdatePartnerDto } from './dto/update-partner.dto';
 | 
			
		||||
import { UpdateSupplierDto } from './dto/update-supplier.dto';
 | 
			
		||||
 | 
			
		||||
@Controller({
 | 
			
		||||
  path: 'users',
 | 
			
		||||
@@ -50,6 +51,30 @@ export class UsersController {
 | 
			
		||||
    };
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Get('supplier/:id/:type')
 | 
			
		||||
  async updateSupplier(
 | 
			
		||||
    @Param('id', ParseUUIDPipe) id: string,
 | 
			
		||||
    @Param('type') type: string,
 | 
			
		||||
  ) {
 | 
			
		||||
    return {
 | 
			
		||||
      data: await this.supplierService.setStatus(id, type),
 | 
			
		||||
      statusCode: HttpStatus.CREATED,
 | 
			
		||||
      message: 'success',
 | 
			
		||||
    };
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Put('supplier/:id')
 | 
			
		||||
  async setStatusSupplier(
 | 
			
		||||
    @Param('id', ParseUUIDPipe) id: string,
 | 
			
		||||
    @Body() updatePartnerDto: UpdateSupplierDto,
 | 
			
		||||
  ) {
 | 
			
		||||
    return {
 | 
			
		||||
      data: await this.supplierService.update(id, updatePartnerDto),
 | 
			
		||||
      statusCode: HttpStatus.CREATED,
 | 
			
		||||
      message: 'success',
 | 
			
		||||
    };
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Post('partner')
 | 
			
		||||
  async createPartner(
 | 
			
		||||
    @Request() req,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user