-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #260 from dhanush-2397/dev
API added to upload files for dimension
- Loading branch information
Showing
12 changed files
with
134 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/ingestion/services/upload-dimension-file/upload-dimension-file.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { UploadDimensionFileService } from './upload-dimension-file.service'; | ||
|
||
describe('UploadDimensionFileService', () => { | ||
let service: UploadDimensionFileService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [UploadDimensionFileService], | ||
}).compile(); | ||
|
||
service = module.get<UploadDimensionFileService>(UploadDimensionFileService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
53 changes: 53 additions & 0 deletions
53
src/ingestion/services/upload-dimension-file/upload-dimension-file.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { HttpCustomService } from './../HttpCustomService'; | ||
import { Injectable } from '@nestjs/common'; | ||
const fs = require('fs'); | ||
const FormData = require('form-data'); | ||
|
||
@Injectable() | ||
export class UploadDimensionFileService { | ||
constructor(private httpService:HttpCustomService){} | ||
|
||
async uploadFiles(){ | ||
let folderPath = './dimension-files' | ||
try{ | ||
let result = await this.httpService.get(process.env.URL + '/generatejwt') | ||
let token: any = result?.data; | ||
let res = await this.callCsvImportAPI(token, folderPath) | ||
return res | ||
}catch(error){ | ||
return {code:400, error:error} | ||
} | ||
} | ||
async callCsvImportAPI(data: string, folderPath:string){ | ||
const files = fs.readdirSync(folderPath); | ||
let promises = []; | ||
for(let i=0;i<files?.length;i++){ | ||
const filePath = folderPath + '/' +files[i] | ||
const fileName: string = files[i]?.split('-')[0] | ||
console.log("The file name is:", fileName) | ||
const formData = new FormData(); | ||
formData.append('ingestion_type','dimension'); | ||
formData.append('ingestion_name',`${fileName}`); | ||
formData.append('file',fs.createReadStream(filePath)); | ||
try{ | ||
let url = `${process.env.URL}` + '/new_programs'; | ||
const headers = { | ||
Authorization: 'Bearer'+ ' '+data, | ||
|
||
}; | ||
promises.push(this.httpService.post(url,formData,{headers: headers})) | ||
|
||
}catch(error){ | ||
console.error("error during csv import:", error) | ||
} | ||
} | ||
try{ | ||
await Promise.all(promises) | ||
return { code: 200, message:"Uploading the files"} | ||
}catch(error){ | ||
console.error("error is", error) | ||
return {code:400, error:"Error occured during the upload"} | ||
} | ||
|
||
} | ||
} |
34 changes: 0 additions & 34 deletions
34
src/ingestion/services/v4-data-emission/v4-data-emission.service.ts
This file was deleted.
Oops, something went wrong.