Compare commits

...
2 Commits
Author SHA1 Message Date
Victor Radael 9eb61a0ac9 Merge pull request #189 from dadosfera/feat/upload-csv
FIX: Upload CSV
2022-12-12 17:41:44 -03:00
Victor Radael 4a9e5b0ffc FIX: Upload CSV 2022-12-12 17:04:16 -03:00
@@ -15,6 +15,7 @@ import {
Patch,
UseInterceptors,
UploadedFile,
HttpException,
} from '@nestjs/common';
import {
ApiConsumes,
@@ -265,8 +266,15 @@ export class PipelinesController {
) {
this.logger.info('/upload - Upload Connector Route');
const metadata = PackTheMetadata({ ...user });
let name = `${new Date().getTime()}_${file.originalname.split('.')[0]}`;
const parts_of_file_name = file.originalname.split('.');
const file_format = parts_of_file_name.pop();
const file_name = parts_of_file_name.join('.');
let name = `${new Date().getTime()}_${file_name}`;
body.name ? (name = `${new Date().getTime()}_${body.name}`) : name;
const source_prefix = `${user.customer_name}/${name}.${file_format}`;
const response = await this.pipelinesClientService.uploadFile(
{
file,
@@ -275,9 +283,15 @@ export class PipelinesController {
metadata,
);
const { sep, header, encoding, description } = body;
if (!response.url) {
this.logger.info('pipeline/upload - Failed File pipeline');
throw new HttpException(
'Upload failed, try again in a few minutes, if the problem persists, contact support.',
HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const [file_name, file_format] = file.originalname.split('.');
const { sep, header, encoding, description } = body;
const upload_pipeline = {
connection_id: process.env.UPLOAD_FILE_AGENT_CONNECTION,
@@ -294,7 +308,7 @@ export class PipelinesController {
properties: {
engine: 'csv',
source_bucket: process.env.BUCKET_CUSTOMER_CSV_ASSETS,
source_prefix: `${user.customer_name}/${name}.${file_format}`,
source_prefix,
file_format_params: { sep, encoding, header: Boolean(header) },
is_a_upload_csv: true,
},