mirror of
https://github.com/dadosfera/maestro.git
synced 2026-09-19 00:54:48 +00:00
78 lines
1.9 KiB
TypeScript
78 lines
1.9 KiB
TypeScript
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
|
import { TransformationsClientService } from 'src/clients/transformations/client.service';
|
|
import { ICreateTransformationsRequest } from 'src/clients/transformations/interfaces';
|
|
import { trSnakeToCamel } from 'src/utils/CaseConverter';
|
|
|
|
@Injectable()
|
|
export class TransformationsService {
|
|
|
|
constructor( private transformationClient: TransformationsClientService){}
|
|
|
|
async create(createTransformationDto:ICreateTransformationsRequest){
|
|
try{
|
|
|
|
let convertedDTO = createTransformationDto.transformations.map((tr)=>{
|
|
|
|
return trSnakeToCamel(tr)
|
|
})
|
|
|
|
const createTransformationResponse = await this.transformationClient.create({transformations:convertedDTO});
|
|
|
|
return createTransformationResponse
|
|
|
|
}catch(err){
|
|
throw new HttpException(err.message,HttpStatus.NOT_FOUND)
|
|
}
|
|
|
|
}
|
|
|
|
async findOne(id:string){
|
|
|
|
try{
|
|
const findOneTransformationResponse = await this.transformationClient.findOne({id});
|
|
return findOneTransformationResponse
|
|
}catch(err){
|
|
throw new HttpException(err.message,HttpStatus.NOT_FOUND)
|
|
}
|
|
|
|
}
|
|
|
|
async findAll(){
|
|
|
|
try{
|
|
const findAllTransformationResponse = await this.transformationClient.findAll();
|
|
|
|
return findAllTransformationResponse
|
|
|
|
}catch(err){
|
|
throw new HttpException(err.message,HttpStatus.NOT_FOUND)
|
|
}
|
|
}
|
|
|
|
async update(id:string, data){
|
|
|
|
try{
|
|
|
|
const updateTransformationResponse = await this.transformationClient.update({id,...data});
|
|
|
|
return updateTransformationResponse
|
|
|
|
}catch(err){
|
|
throw new HttpException(err.message,HttpStatus.NOT_FOUND)
|
|
}
|
|
}
|
|
|
|
async remove(id:string){
|
|
|
|
try{
|
|
|
|
const removeTransformationResponse = await this.transformationClient.remove({id});
|
|
|
|
return removeTransformationResponse
|
|
|
|
}catch(err){
|
|
throw new HttpException(err.message,HttpStatus.NOT_FOUND)
|
|
}
|
|
}
|
|
}
|