From d40afb758314bbdd2e615ebfcf8ac963994ed38d Mon Sep 17 00:00:00 2001 From: AnandaTon Date: Thu, 25 Jul 2024 10:57:27 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84=E0=B8=82?= =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1=20static=20file?= =?UTF-8?q?=20=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1=E0=B9=80?= =?UTF-8?q?=E0=B8=95=E0=B8=B4=E0=B8=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ImportDataController.ts | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/controllers/ImportDataController.ts b/src/controllers/ImportDataController.ts index de4ca377..6120155c 100644 --- a/src/controllers/ImportDataController.ts +++ b/src/controllers/ImportDataController.ts @@ -31,6 +31,7 @@ import { ProfileEmployee } from "../entities/ProfileEmployee"; import { PosLevel } from "../entities/PosLevel"; import { PosType } from "../entities/PosType"; import * as fs from "fs"; +import * as path from "path"; @Route("api/v1/org/upload") @Tags("UPLOAD") @@ -656,10 +657,12 @@ export class ImportDataController extends Controller { @Get("uploadSQLStatic") async uploadFileSQLStati() { - const filePath = "/src/controllers/backup-employee-temp-bmatest.xlsx"; // Corrected file path - if (!fs.existsSync(filePath)) { - throw new Error(`File not found: ${filePath}`); - } + const filePath = path.resolve(__dirname, "backup-employee-temp-bmaStatic.xlsx"); // Corrected file path + console.log(filePath); + + // if (!fs.existsSync(filePath)) { + // throw new Error(`File not found: ${filePath}`); + // } const fileBuffer = fs.readFileSync(filePath); const workbook = xlsx.read(fileBuffer, { type: "buffer" }); const sheetName = workbook.SheetNames[0]; // Assuming we're reading the first sheet @@ -741,12 +744,15 @@ export class ImportDataController extends Controller { profile.govAgeAbsent = item["govAgeAbsent"] == "NULL" ? null : item["govAgeAbsent"]; profile.govAgePlus = item["govAgePlus"] == "NULL" ? null : item["govAgePlus"]; profile.reasonSameDate = item["reasonSameDate"] == "NULL" ? null : item["reasonSameDate"]; - profiles.push(profile); + // profiles.push(profile); }), ); // await this.profileEmpRepo.save(profiles); - console.log(profiles); + // console.log(profiles.id); + console.log(`Row count: ${getProFile.length}`); - return new HttpSuccess(getProFile); + return new HttpSuccess({ rowCount: getProFile.length }); + + // return new HttpSuccess(getProFile); } }