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

@@ -0,0 +1,36 @@
import { Inject, Service } from 'typedi';
import HasTenancyService from '../Tenancy/TenancyService';
import { ImportMappingAttr } from './interfaces';
@Service()
export class ImportFileMapping {
@Inject()
private tenancy: HasTenancyService;
/**
* Mapping the excel sheet columns with resource columns.
* @param {number} tenantId
* @param {number} importId
* @param {ImportMappingAttr} maps
*/
public async mapping(
tenantId: number,
importId: number,
maps: ImportMappingAttr[]
) {
const { Import } = this.tenancy.models(tenantId);
const importFile = await Import.query()
.findOne('filename', importId)
.throwIfNotFound();
// @todo validate the resource columns.
// @todo validate the sheet columns.
const mappingStringified = JSON.stringify(maps);
await Import.query().findById(importFile.id).patch({
mapping: mappingStringified,
});
}
}