Files
maestro/src/modules/inputs/inputs.service.ts
T
2022-03-29 15:22:42 -03:00

78 lines
1.9 KiB
TypeScript

import { Body, HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { InputsClientService } from 'src/clients/inputs/client.service';
import {
ICreateInputRequest,
IIdRequest,
Info,
} from 'src/clients/inputs/interfaces';
@Injectable()
export class InputsService {
constructor(private inputClient: InputsClientService) {}
async create(@Body() data: ICreateInputRequest) {
try {
const createInputResponse = await this.inputClient.create(data);
return createInputResponse;
} catch (err) {
throw new HttpException(err.message, HttpStatus.NOT_FOUND);
}
}
async findAll(body) {
try {
const findAllInputResponse = await this.inputClient.findAll(body);
return findAllInputResponse;
} catch (err) {
throw new HttpException(err.message, HttpStatus.NOT_FOUND);
}
}
async findOne(idRequest: IIdRequest) {
try {
const findOneInputResponse = await this.inputClient.findOne(idRequest);
return findOneInputResponse;
} catch (err) {
throw new HttpException(err.message, HttpStatus.NOT_FOUND);
}
}
async update(id: string, data, info: Info) {
try {
const updateInputResponse = await this.inputClient.update({
id,
info,
...data,
});
return updateInputResponse;
} catch (err) {
throw new HttpException(err.message, HttpStatus.NOT_FOUND);
}
}
async remove(idRequest: IIdRequest) {
try {
const removeInputResponse = await this.inputClient.remove(idRequest);
return removeInputResponse;
} catch (err) {
throw new HttpException(err.message, HttpStatus.NOT_FOUND);
}
}
async testConnection(data) {
try {
const testConnectionInputResponse = await this.inputClient.testConnection(
data,
);
return testConnectionInputResponse;
} catch (err) {
throw new HttpException(err.message, HttpStatus.NOT_FOUND);
}
}
}