แก้ไขเพิ่ม static file เพิ่มเติม

This commit is contained in:
AnandaTon 2024-07-25 10:57:27 +07:00
parent a14c04a81c
commit d40afb7583

View file

@ -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);
}
}