diff --git a/lib/port.js b/lib/port.js index d72b791..0837b94 100644 --- a/lib/port.js +++ b/lib/port.js @@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.getImportationTemplate = exports.exportEntity = exports.importEntity = exports.clearPorts = exports.registerPorts = void 0; const tslib_1 = require("tslib"); const assert_1 = tslib_1.__importDefault(require("assert")); +const xlsx_1 = require("xlsx"); const Importations = {}; const Exportations = {}; function registerPorts(importations, exportations) { @@ -41,12 +42,24 @@ async function importEntity(params, context) { const entity = params.get('entity'); const file = params.get('file'); const id = params.get('id'); +<<<<<<< HEAD const option = params.get('option'); throw new Error('not implement yet'); +======= + const arrayBuffer = await file.arrayBuffer(); + const workbook = (0, xlsx_1.read)(arrayBuffer); + const { SheetNames, Sheets } = workbook; + for (const sheetName of SheetNames) { + const sheet = Sheets[sheetName]; + const dataList = xlsx_1.utils.sheet_to_json(sheet, {}); + console.log(dataList); + } + // throw new Error('not implement yet'); +>>>>>>> 8533a93fe25ac6bd0406d879dd47c6c17248957c } exports.importEntity = importEntity; async function exportEntity(params, context) { - throw new Error('not implement yet'); + throw new Error('export not implement yet'); } exports.exportEntity = exportEntity; async function getImportationTemplate(params, context) { diff --git a/package.json b/package.json index 2be4f62..6793b3d 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,8 @@ "dependencies": { "lodash": "^4.17.21", "oak-domain": "file:../oak-domain", - "oak-external-sdk": "file:../oak-external-sdk" + "oak-external-sdk": "file:../oak-external-sdk", + "xlsx": "^0.18.5" }, "devDependencies": { "@types/node": "^18.0.0", diff --git a/src/port.ts b/src/port.ts index c2fed8a..5246314 100644 --- a/src/port.ts +++ b/src/port.ts @@ -2,7 +2,7 @@ import assert from 'assert'; import { EntityDict, SelectOption } from 'oak-domain/lib/types/Entity'; import { Importation, Exportation } from 'oak-domain/lib/types/Port'; import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore'; - +import { read, utils } from 'xlsx'; const Importations: Record = {}; const Exportations: Record = {}; @@ -48,9 +48,24 @@ export async function importEntity< const entity = params.get('entity') as keyof ED; const file = params.get('file') as File; const id = params.get('id') as string; +<<<<<<< HEAD const option = params.get('option') as Object; throw new Error('not implement yet'); +======= + const arrayBuffer = await file.arrayBuffer(); + const workbook = read(arrayBuffer); + const { SheetNames, Sheets } = workbook; + for (const sheetName of SheetNames) { + const sheet = Sheets[sheetName]; + const dataList = utils.sheet_to_json( + sheet + ); + console.log(dataList); + } + + // throw new Error('not implement yet'); +>>>>>>> 8533a93fe25ac6bd0406d879dd47c6c17248957c } export async function exportEntity< @@ -62,7 +77,7 @@ export async function exportEntity< id: string; filter?: ED[T]['Selection']['filter']; }, context: Cxt): Promise { - throw new Error('not implement yet'); + throw new Error('export not implement yet'); } export async function getImportationTemplate<