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); } } }