FIX: create partial input

This commit is contained in:
Gabriel Rosa
2022-05-25 11:09:24 -03:00
parent 2344e4dba3
commit e52af6844b
5 changed files with 30 additions and 15 deletions
+2 -2
View File
@@ -4,8 +4,8 @@ import {
Delete,
Get,
Param,
Patch,
Post,
Put,
} from '@nestjs/common';
import { InputsService } from './inputs.service';
import { InputsClientService } from 'src/clients/inputs/client.service';
@@ -71,7 +71,7 @@ export class InputsController {
return response;
}
@Put(':id')
@Patch(':id')
async update(@Body() updateInputDto: UpdateInputRequest, @Param() params) {
const { id } = params;
const { info } = updateInputDto;
+19 -4
View File
@@ -7,6 +7,9 @@ import { IIdRequest, Info } from 'src/clients/inputs/interfaces';
export class InputsService {
constructor(private inputClient: InputsClientService) {}
adjustInputPayload(payload) {
return payload?.input_s3 || payload?.input_jdbc;
}
async create(@Body() data) {
try {
if (
@@ -35,8 +38,12 @@ export class InputsService {
async findAll(body) {
try {
const findAllInputResponse = await this.inputClient.findAll(body);
const findAllInputResponse: any = await this.inputClient.findAll(body);
if (findAllInputResponse?.inputs?.length) {
findAllInputResponse.inputs = findAllInputResponse.inputs.map((input) =>
this.adjustInputPayload(input),
);
}
return findAllInputResponse;
} catch (err) {
throw new HttpException(err.message, HttpStatus.NOT_FOUND);
@@ -45,7 +52,12 @@ export class InputsService {
async findOne(idRequest: IIdRequest) {
try {
const findOneInputResponse = await this.inputClient.findOne(idRequest);
const findOneInputResponse: any = await this.inputClient.findOne(
idRequest,
);
findOneInputResponse.input = this.adjustInputPayload(
findOneInputResponse.input,
);
return findOneInputResponse;
} catch (err) {
throw new HttpException(err.message, HttpStatus.NOT_FOUND);
@@ -54,12 +66,15 @@ export class InputsService {
async update(id: string, data, info: Info) {
try {
const updateInputResponse = await this.inputClient.update({
const updateInputResponse: any = await this.inputClient.update({
id,
info,
...data,
});
updateInputResponse.input = this.adjustInputPayload(
updateInputResponse?.input,
);
return updateInputResponse;
} catch (err) {
throw new HttpException(err.message, HttpStatus.NOT_FOUND);