test import data
This commit is contained in:
parent
438c153651
commit
e4aa7fcc6d
3 changed files with 432 additions and 30 deletions
87
src/controllers/ImportDataController.ts
Normal file
87
src/controllers/ImportDataController.ts
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
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 #
|
||||
*
|
||||
*/
|
||||
@Post("tab6/{id}")
|
||||
@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);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue