mirror of
https://github.com/dadosfera/maestro.git
synced 2026-09-28 16:04:49 +00:00
95 lines
2.5 KiB
TypeScript
95 lines
2.5 KiB
TypeScript
import { Body, HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
|
import { Timeout } from '@nestjs/schedule';
|
|
import { InputsClientService } from 'src/clients/inputs/client.service';
|
|
import { IIdRequest, Info } from 'src/clients/inputs/interfaces';
|
|
|
|
@Injectable()
|
|
export class InputsService {
|
|
constructor(private inputClient: InputsClientService) {}
|
|
|
|
async create(@Body() data) {
|
|
try {
|
|
if (
|
|
data.plugin == 'csv' ||
|
|
data.plugin == 'json' ||
|
|
data.plugin == 'parquet'
|
|
) {
|
|
const createInputResponse = await this.inputClient.createS3Inputs(data);
|
|
return createInputResponse;
|
|
} else {
|
|
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);
|
|
}
|
|
}
|
|
|
|
@Timeout(60000 * 10) // Timeout set for 10 minutes
|
|
async testConnection(data) {
|
|
try {
|
|
const testConnectionInputResponse = await this.inputClient.testConnection(
|
|
data,
|
|
);
|
|
|
|
return testConnectionInputResponse;
|
|
} catch (err) {
|
|
throw new HttpException(err.message, HttpStatus.NOT_FOUND);
|
|
}
|
|
}
|
|
|
|
async getColumns(data) {
|
|
try {
|
|
const testConnectionGetColumnsResponse =
|
|
await this.inputClient.getColumns(data);
|
|
|
|
return testConnectionGetColumnsResponse;
|
|
} catch (err) {
|
|
throw new HttpException(err.message, HttpStatus.NOT_FOUND);
|
|
}
|
|
}
|
|
}
|