feat: import resources from csv/xlsx

This commit is contained in:
Ahmed Bouhuolia
2024-03-11 00:21:36 +02:00
parent 1fc6445123
commit 90b4f3ef6d
16 changed files with 467 additions and 184 deletions

View File

@@ -26,6 +26,7 @@ export class ImportFileUploadService {
filename: string
) {
const { Import } = this.tenancy.models(tenantId);
const buffer = await fs.readFile(filePath);
const workbook = XLSX.read(buffer, { type: 'buffer' });
@@ -33,6 +34,7 @@ export class ImportFileUploadService {
const worksheet = workbook.Sheets[firstSheetName];
const jsonData = XLSX.utils.sheet_to_json(worksheet);
// @todo validate the resource.
const _resource = upperFirst(snakeCase(resource));
const exportFile = await Import.query().insert({
@@ -42,8 +44,9 @@ export class ImportFileUploadService {
});
const columns = this.getColumns(jsonData);
// @todo return the resource importable columns.
return {
...exportFile,
export: exportFile,
columns,
};
}