mirror of
https://github.com/dadosfera/maestro.git
synced 2026-09-05 22:24:47 +00:00
80 lines
2.3 KiB
TypeScript
80 lines
2.3 KiB
TypeScript
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
|
import { TransformationsClientService } from 'src/clients/transformations/client.service';
|
|
import {
|
|
ICreateTransformationsRequest,
|
|
IIdRequest,
|
|
} from 'src/clients/transformations/interfaces';
|
|
import { trSnakeToCamel } from 'src/utils/CaseConverter';
|
|
|
|
@Injectable()
|
|
export class TransformationsService {
|
|
constructor(private transformationClient: TransformationsClientService) {}
|
|
|
|
async create(createTransformationDto: ICreateTransformationsRequest) {
|
|
const { transformations, info } = createTransformationDto;
|
|
|
|
if (!transformations || transformations.length == 0) {
|
|
throw new HttpException('Missing transformations field.', 400);
|
|
}
|
|
|
|
try {
|
|
const convertedDTO = transformations.map((tr) => {
|
|
return trSnakeToCamel(tr);
|
|
});
|
|
const createTransformationResponse =
|
|
await this.transformationClient.create({
|
|
transformations: convertedDTO,
|
|
info: info,
|
|
});
|
|
|
|
return createTransformationResponse;
|
|
} catch (err) {
|
|
throw new HttpException(err.message, HttpStatus.NOT_FOUND);
|
|
}
|
|
}
|
|
|
|
async findOne(data: IIdRequest) {
|
|
try {
|
|
const findOneTransformationResponse =
|
|
await this.transformationClient.findOne(data);
|
|
return findOneTransformationResponse;
|
|
} catch (err) {
|
|
throw new HttpException(err.message, HttpStatus.NOT_FOUND);
|
|
}
|
|
}
|
|
|
|
async findAll(data) {
|
|
try {
|
|
const findAllTransformationResponse =
|
|
await this.transformationClient.findAll(data);
|
|
|
|
return findAllTransformationResponse;
|
|
} catch (err) {
|
|
throw new HttpException(err.message, HttpStatus.NOT_FOUND);
|
|
}
|
|
}
|
|
|
|
async update(id: string, data) {
|
|
try {
|
|
data.transformation['id'] = id;
|
|
const updateTransformationResponse =
|
|
await this.transformationClient.update({ ...data });
|
|
|
|
return updateTransformationResponse;
|
|
} catch (err) {
|
|
throw new HttpException(err.message, HttpStatus.NOT_FOUND);
|
|
}
|
|
}
|
|
|
|
async remove(data: IIdRequest) {
|
|
try {
|
|
const removeTransformationResponse =
|
|
await this.transformationClient.remove(data);
|
|
|
|
return removeTransformationResponse;
|
|
} catch (err) {
|
|
throw new HttpException(err.message, HttpStatus.NOT_FOUND);
|
|
}
|
|
}
|
|
}
|