2024-06-06 11:15:26 +07:00
|
|
|
import {
|
|
|
|
|
Controller,
|
|
|
|
|
Get,
|
|
|
|
|
Post,
|
|
|
|
|
Put,
|
|
|
|
|
Delete,
|
|
|
|
|
Route,
|
|
|
|
|
Security,
|
|
|
|
|
Tags,
|
|
|
|
|
Body,
|
|
|
|
|
Path,
|
|
|
|
|
Request,
|
|
|
|
|
Query,
|
|
|
|
|
UploadedFile,
|
|
|
|
|
} from "tsoa";
|
|
|
|
|
import { AppDataSource } from "../database/data-source";
|
|
|
|
|
import { Brackets } from "typeorm";
|
|
|
|
|
import HttpSuccess from "../interfaces/http-success";
|
|
|
|
|
import HttpError from "../interfaces/http-error";
|
|
|
|
|
import HttpStatusCode from "../interfaces/http-status";
|
|
|
|
|
import { UseInterceptors } from "@nestjs/common";
|
|
|
|
|
import { FileInterceptor } from "@nestjs/platform-express";
|
|
|
|
|
import * as xlsx from "xlsx";
|
|
|
|
|
import { ProfileEducation } from "../entities/ProfileEducation";
|
|
|
|
|
|
|
|
|
|
@Route("api/v1/development/scholarship")
|
|
|
|
|
@Tags("DevelopmentScholarship")
|
|
|
|
|
@Security("bearerAuth")
|
|
|
|
|
export class ImportDataController extends Controller {
|
|
|
|
|
private educationRepository = AppDataSource.getRepository(ProfileEducation);
|
|
|
|
|
/**
|
|
|
|
|
* API upload EDU
|
|
|
|
|
*
|
|
|
|
|
* @summary DEV_0 - upload EDU #
|
|
|
|
|
*
|
|
|
|
|
*/
|
2024-06-06 11:17:18 +07:00
|
|
|
@Post("upload")
|
2024-06-06 11:15:26 +07:00
|
|
|
@UseInterceptors(FileInterceptor("file"))
|
|
|
|
|
async UploadUserDevelopemtById(
|
|
|
|
|
@UploadedFile() file: Express.Multer.File,
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
|
|
const workbook = xlsx.read(file.buffer, { type: "buffer" });
|
|
|
|
|
const sheetName = workbook.SheetNames[1];
|
|
|
|
|
const sheet = workbook.Sheets[sheetName];
|
|
|
|
|
const getEducations = xlsx.utils.sheet_to_json(sheet);
|
|
|
|
|
|
|
|
|
|
await Promise.all(
|
|
|
|
|
getEducations.map(async (item: any) => {
|
|
|
|
|
if (item["id"] === undefined) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const education = new ProfileEducation();
|
|
|
|
|
|
|
|
|
|
education.id = item["id"];
|
|
|
|
|
education.createdAt = item["createdAt"];
|
|
|
|
|
education.createdUserId = item["createdUserId"];
|
|
|
|
|
education.lastUpdatedAt = item["lastUpdatedAt"];
|
|
|
|
|
education.lastUpdateUserId = item["lastUpdateUserId"];
|
|
|
|
|
education.createdFullName = item["createdFullName"];
|
|
|
|
|
education.lastUpdateFullName = item["lastUpdateFullName"];
|
|
|
|
|
education.profileId = item["profileId"];
|
|
|
|
|
education.country = item["country"];
|
|
|
|
|
education.degree = item["degree"];
|
|
|
|
|
education.duration = item["duration"];
|
|
|
|
|
education.durationYear = item["durationYear"];
|
|
|
|
|
education.field = item["field"];
|
|
|
|
|
education.finishDate = item["finishDate"];
|
|
|
|
|
education.fundName = item["fundName"];
|
|
|
|
|
education.institute = item["institute"];
|
|
|
|
|
education.other = item["other"];
|
|
|
|
|
education.startDate = item["startDate"];
|
|
|
|
|
education.endDate = item["endDate"];
|
|
|
|
|
education.educationLevel = item["educationLevel"];
|
|
|
|
|
education.educationLevelId = item["educationLevelId"];
|
|
|
|
|
education.positionPath = item["positionPath"];
|
|
|
|
|
education.positionPathId = item["positionPathId"];
|
|
|
|
|
education.isDate = item["isDate"];
|
|
|
|
|
education.isEducation = item["isEducation"];
|
|
|
|
|
education.note = item["note"];
|
|
|
|
|
education.profileEmployeeId = item["profileEmployeeId"];
|
|
|
|
|
|
|
|
|
|
await this.educationRepository.save(education);
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|