แก้ไขเพิ่ม 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 { PosLevel } from "../entities/PosLevel";
import { PosType } from "../entities/PosType"; import { PosType } from "../entities/PosType";
import * as fs from "fs"; import * as fs from "fs";
import * as path from "path";
@Route("api/v1/org/upload") @Route("api/v1/org/upload")
@Tags("UPLOAD") @Tags("UPLOAD")
@ -656,10 +657,12 @@ export class ImportDataController extends Controller {
@Get("uploadSQLStatic") @Get("uploadSQLStatic")
async uploadFileSQLStati() { async uploadFileSQLStati() {
const filePath = "/src/controllers/backup-employee-temp-bmatest.xlsx"; // Corrected file path const filePath = path.resolve(__dirname, "backup-employee-temp-bmaStatic.xlsx"); // Corrected file path
if (!fs.existsSync(filePath)) { console.log(filePath);
throw new Error(`File not found: ${filePath}`);
} // if (!fs.existsSync(filePath)) {
// throw new Error(`File not found: ${filePath}`);
// }
const fileBuffer = fs.readFileSync(filePath); const fileBuffer = fs.readFileSync(filePath);
const workbook = xlsx.read(fileBuffer, { type: "buffer" }); const workbook = xlsx.read(fileBuffer, { type: "buffer" });
const sheetName = workbook.SheetNames[0]; // Assuming we're reading the first sheet 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.govAgeAbsent = item["govAgeAbsent"] == "NULL" ? null : item["govAgeAbsent"];
profile.govAgePlus = item["govAgePlus"] == "NULL" ? null : item["govAgePlus"]; profile.govAgePlus = item["govAgePlus"] == "NULL" ? null : item["govAgePlus"];
profile.reasonSameDate = item["reasonSameDate"] == "NULL" ? null : item["reasonSameDate"]; profile.reasonSameDate = item["reasonSameDate"] == "NULL" ? null : item["reasonSameDate"];
profiles.push(profile); // profiles.push(profile);
}), }),
); );
// await this.profileEmpRepo.save(profiles); // 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);
} }
} }