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 { Profile } from "../entities/Profile"; import { FileInterceptor } from "@nestjs/platform-express"; import * as xlsx from "xlsx"; import { ProfileEducation } from "../entities/ProfileEducation"; import { ProfileSalary } from "../entities/ProfileSalary"; import { ProfileFamilyCouple } from "../entities/ProfileFamilyCouple"; import { ProfileFamilyMother } from "../entities/ProfileFamilyMother"; import { ProfileFamilyFather } from "../entities/ProfileFamilyFather"; import { ProfileEmployee } from "../entities/ProfileEmployee"; @Route("api/v1/org/upload") @Tags("UPLOAD") @Security("bearerAuth") export class ImportDataController extends Controller { private educationRepository = AppDataSource.getRepository(ProfileEducation); private profileFamilyCoupleRepository = AppDataSource.getRepository(ProfileFamilyCouple); private profileFamilyMotherRepository = AppDataSource.getRepository(ProfileFamilyMother); private profileFamilyFatherRepository = AppDataSource.getRepository(ProfileFamilyFather); private salaryRepository = AppDataSource.getRepository(ProfileSalary); private profileRepo = AppDataSource.getRepository(Profile); private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee); /** * API upload EDU * * @summary DEV_0 - upload EDU # * */ @Post("") @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); }), ); } /** * * @param id * @param file * @param request * @returns */ @Post("uploadSQL") @UseInterceptors(FileInterceptor("file")) async UploadFileSQL( @UploadedFile() file: Express.Multer.File, // @Request() request: { user: Record }, ) { const workbook = xlsx.read(file.buffer, { type: "buffer" }); const sheetName = workbook.SheetNames[0]; // Assuming we're reading the first sheet const sheet = workbook.Sheets[sheetName]; const getProFile = xlsx.utils.sheet_to_json(sheet); let profiles: any = []; await Promise.all( getProFile.map(async (item: any) => { // Create a new Profile entity and assign fields from the parsed data const profile = new ProfileEmployee(); // Check if the profile already exists const existingProfile = await this.profileEmpRepo.findOne({ where: { id: item["id"] }, }); // If profile exists, skip saving if (existingProfile) { return; } // Assign fields from the item to the profile entity profile.id = item["id"]; // profile.createdAt = item["createdUserId"] == "NULL" ? null : new Date(item["createdAt"]); profile.createdUserId = item["createdUserId"] == "NULL" ? null : item["createdUserId"]; // profile.lastUpdatedAt = // item["createdUserId"] == "NULL" ? null : new Date(item["lastUpdatedAt"]); profile.lastUpdateUserId = item["lastUpdateUserId"] == "NULL" ? null : item["lastUpdateUserId"]; profile.createdFullName = item["createdFullName"] == "NULL" ? null : item["createdFullName"]; profile.lastUpdateFullName = item["lastUpdateFullName"] == "NULL" ? null : item["lastUpdateFullName"]; profile.prefix = item["prefix"] == "NULL" ? null : item["prefix"]; profile.firstName = item["firstName"] == "NULL" ? null : item["firstName"]; profile.lastName = item["lastName"] == "NULL" ? null : item["lastName"]; profile.citizenId = item["citizenId"] == "NULL" ? null : item["citizenId"]; profile.position = item["position"] == "NULL" ? null : item["position"]; profile.posLevelId = item["posLevelId"] == "NULL" ? null : item["posLevelId"]; profile.posTypeId = item["posTypeId"] == "NULL" ? null : item["posTypeId"]; profile.email = item["email"] == "NULL" ? null : item["email"]; profile.phone = item["phone"] == "NULL" ? null : item["phone"]; profile.keycloak = item["keycloak"] == "NULL" ? null : item["keycloak"]; profile.isProbation = item["isProbation"] == "NULL" ? null : item["isProbation"]; // profile.dateRetire = item["dateRetire"] == "NULL" ? null : new Date(item["dateRetire"]); // profile.birthDate = item["birthDate"] == "NULL" ? null : new Date(item["birthDate"]); profile.salaryLevel = item["salaryLevel"] == "NULL" ? null : item["salaryLevel"]; profile.ethnicity = item["ethnicity"] == "NULL" ? null : item["ethnicity"]; profile.telephoneNumber = item["telephoneNumber"] == "NULL" ? null : item["telephoneNumber"]; profile.group = item["group"] == "NULL" ? null : item["group"]; profile.gender = item["gender"] == "NULL" ? null : item["gender"]; profile.relationship = item["relationship"] == "NULL" ? null : item["relationship"]; profile.religion = item["religion"] == "NULL" ? null : item["religion"]; profile.bloodGroup = item["bloodGroup"] == "NULL" ? null : item["bloodGroup"]; profile.rank = item["rank"] == "NULL" ? null : item["rank"]; profile.employeeClass = item["employeeClass"] == "NULL" ? null : item["employeeClass"]; profile.avatar = item["avatar"] == "NULL" ? null : item["avatar"]; // profile.dateRetireLaw = // item["dateRetireLaw"] == "NULL" ? null : new Date(item["dateRetireLaw"]); profile.registrationAddress = item["registrationAddress"] == "NULL" ? null : item["registrationAddress"]; profile.registrationProvinceId = item["registrationProvinceId"] == "NULL" ? null : item["registrationProvinceId"]; profile.registrationDistrictId = item["registrationDistrictId"] == "NULL" ? null : item["registrationDistrictId"]; profile.registrationSubDistrictId = item["registrationSubDistrictId"] == "NULL" ? null : item["registrationSubDistrictId"]; profile.registrationZipCode = item["registrationZipCode"] == "NULL" ? null : item["registrationZipCode"]; profile.currentAddress = item["currentAddress"] == "NULL" ? null : item["currentAddress"]; profile.currentProvinceId = item["currentProvinceId"] == "NULL" ? null : item["currentProvinceId"]; profile.currentDistrictId = item["currentDistrictId"] == "NULL" ? null : item["currentDistrictId"]; profile.currentSubDistrictId = item["currentSubDistrictId"] == "NULL" ? null : item["currentSubDistrictId"]; profile.currentZipCode = item["currentZipCode"] == "NULL" ? null : item["currentZipCode"]; profile.avatarName = item["avatarName"] == "NULL" ? null : item["avatarName"]; profile.nationality = item["nationality"] == "NULL" ? null : item["nationality"]; // profile.dateAppoint = item["dateAppoint"] == "NULL" ? null : new Date(item["dateAppoint"]); // profile.dateStart = item["dateStart"] == "NULL" ? null : new Date(item["dateStart"]); 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); }), ); await this.profileEmpRepo.save(profiles); return new HttpSuccess(getProFile); } @Post("uploadSQLEdu") @UseInterceptors(FileInterceptor("file")) async UploadFileSQLEdu( @UploadedFile() file: Express.Multer.File, // @Request() request: { user: Record }, ) { const workbook = xlsx.read(file.buffer, { type: "buffer" }); const sheetName = workbook.SheetNames[0]; // Assuming we're reading the first sheet const sheet = workbook.Sheets[sheetName]; const getProFile = xlsx.utils.sheet_to_json(sheet); let profiles: any = []; await Promise.all( getProFile.map(async (item: any) => { // Create a new Profile entity and assign fields from the parsed data const profile = new ProfileEducation(); // Check if the profile already exists const existingProfile = await this.educationRepository.findOne({ where: { id: item["id"] }, }); // If profile exists, skip saving if (existingProfile) { return; } // Assign fields from the item to the profile entit profile.id = item["id"] == "NULL" ? null : item["id"]; // profile.createdAt = item["createdAt"] == "NULL" ? null : new Date(item["createdAt"]); profile.createdUserId = item["createdUserId"] == "NULL" ? null : item["createdUserId"]; // profile.lastUpdatedAt = // item["lastUpdatedAt"] == "NULL" ? null : new Date(item["lastUpdatedAt"]); profile.lastUpdateUserId = item["lastUpdateUserId"] == "NULL" ? null : item["lastUpdateUserId"]; profile.createdFullName = item["createdFullName"] == "NULL" ? null : item["createdFullName"]; profile.lastUpdateFullName = item["lastUpdateFullName"] == "NULL" ? null : item["lastUpdateFullName"]; profile.profileId = item["profileId"] == "NULL" ? null : item["profileId"]; profile.country = item["country"] == "NULL" ? null : item["country"]; profile.degree = item["degree"] == "NULL" ? null : item["degree"]; profile.duration = item["duration"] == "NULL" ? null : item["duration"]; profile.durationYear = item["durationYear"] == "NULL" ? null : item["durationYear"]; profile.field = item["field"] == "NULL" ? null : item["field"]; // profile.finishDate = item["finishDate"] == "NULL" ? null : new Date(item["finishDate"]); profile.fundName = item["fundName"] == "NULL" ? null : item["fundName"]; profile.gpa = item["gpa"] == "NULL" ? null : item["gpa"]; profile.institute = item["institute"] == "NULL" ? null : item["institute"]; profile.other = item["other"] == "NULL" ? null : item["other"]; // profile.startDate = item["startDate"] == "NULL" ? null : new Date(item["startDate"]); // profile.endDate = item["endDate"] == "NULL" ? null : new Date(item["endDate"]); profile.educationLevel = item["educationLevel"] == "NULL" ? null : item["educationLevel"]; profile.educationLevelId = item["educationLevelId"] == "NULL" ? null : item["educationLevelId"]; profile.positionPath = item["positionPath"] == "NULL" ? null : item["positionPath"]; profile.positionPathId = item["positionPathId"] == "NULL" ? null : item["positionPathId"]; profile.isDate = item["isDate"] == "NULL" ? null : item["isDate"]; profile.isEducation = item["isEducation"] == "NULL" ? null : item["isEducation"]; profile.note = item["note"] == "NULL" ? null : item["note"]; profile.profileEmployeeId = item["profileEmployeeId"] == "NULL" ? null : item["profileEmployeeId"]; profiles.push(profile); }), ); await this.educationRepository.save(profiles); return new HttpSuccess(getProFile); } @Post("uploadSQL-Officer") @UseInterceptors(FileInterceptor("file")) async UploadFileSqlOfficer( @UploadedFile() file: Express.Multer.File, // @Request() request: { user: Record }, ) { const workbook = xlsx.read(file.buffer, { type: "buffer" }); const sheetName = workbook.SheetNames[0]; // Assuming we're reading the first sheet const sheet = workbook.Sheets[sheetName]; const getProFile = xlsx.utils.sheet_to_json(sheet); let profiles: any = []; await Promise.all( getProFile.map(async (item: any) => { // Create a new Profile entity and assign fields from the parsed data const profile = new Profile(); // Check if the profile already exists const existingProfile = await this.profileRepo.findOne({ where: { id: item["id"] }, }); // If profile exists, skip saving if (existingProfile) { return; } // Assign fields from the item to the profile entit profile.id = item["id"] == "NULL" ? null : item["id"]; // profile.createdAt = item["createdAt"] == "NULL" ? null : new Date(item["createdAt"]); profile.createdUserId = item["createdUserId"] == "NULL" ? null : item["createdUserId"]; // profile.lastUpdatedAt = // item["lastUpdatedAt"] == "NULL" ? null : new Date(item["lastUpdatedAt"]); profile.lastUpdateUserId = item["lastUpdateUserId"] == "NULL" ? null : item["lastUpdateUserId"]; profile.createdFullName = item["createdFullName"] == "NULL" ? null : item["createdFullName"]; profile.lastUpdateFullName = item["lastUpdateFullName"] == "NULL" ? null : item["lastUpdateFullName"]; profile.prefix = item["prefix"] == "NULL" ? null : item["prefix"]; profile.firstName = item["firstName"] == "NULL" ? null : item["firstName"]; profile.lastName = item["lastName"] == "NULL" ? null : item["lastName"]; profile.citizenId = item["citizenId"] == "NULL" ? null : item["citizenId"]; profile.position = item["position"] == "NULL" ? null : item["position"]; profile.posTypeId = item["posTypeId"] == "NULL" ? null : item["posTypeId"]; profile.posLevelId = item["posLevelId"] == "NULL" ? null : item["posLevelId"]; profile.keycloak = item["keycloak"] == "NULL" ? null : item["keycloak"]; profile.email = item["email"] == "NULL" ? null : item["email"]; profile.phone = item["phone"] == "NULL" ? null : item["phone"]; profile.isProbation = item["isProbation"] == "NULL" ? null : item["isProbation"]; // profile.dateRetire = item["dateRetire"] == "NULL" ? null : new Date(item["dateRetire"]); // profile.birthDate = item["birthDate"] == "NULL" ? null : new Date(item["birthDate"]); profile.rank = item["rank"] == "NULL" ? null : item["rank"]; profile.isLeave = item["isLeave"] == "NULL" ? null : item["isLeave"]; // profile.dateAppoint = item["dateAppoint"] == "NULL" ? null : new Date(item["dateAppoint"]); // profile.dateStart = item["dateStart"] == "NULL" ? null : new Date(item["dateStart"]); profile.govAgeAbsent = item["govAgeAbsent"] == "NULL" ? null : item["govAgeAbsent"]; profile.govAgePlus = item["govAgePlus"] == "NULL" ? null : item["govAgePlus"]; profile.reasonSameDate = item["reasonSameDate"] == "NULL" ? null : item["reasonSameDate"]; profile.ethnicity = item["ethnicity"] == "NULL" ? null : item["ethnicity"]; profile.telephoneNumber = item["telephoneNumber"] == "NULL" ? null : item["telephoneNumber"]; profile.nationality = item["nationality"] == "NULL" ? null : item["nationality"]; profile.gender = item["gender"] == "NULL" ? null : item["gender"]; profile.relationship = item["relationship"] == "NULL" ? null : item["relationship"]; profile.religion = item["religion"] == "NULL" ? null : item["religion"]; profile.bloodGroup = item["bloodGroup"] == "NULL" ? null : item["bloodGroup"]; profile.registrationAddress = item["registrationAddress"] == "NULL" ? null : item["registrationAddress"]; profile.registrationProvinceId = item["registrationProvinceId"] == "NULL" ? null : item["registrationProvinceId"]; profile.registrationDistrictId = item["registrationDistrictId"] == "NULL" ? null : item["registrationDistrictId"]; profile.registrationSubDistrictId = item["registrationSubDistrictId"] == "NULL" ? null : item["registrationSubDistrictId"]; profile.registrationZipCode = item["registrationZipCode"] == "NULL" ? null : item["registrationZipCode"]; profile.currentAddress = item["currentAddress"] == "NULL" ? null : item["currentAddress"]; profile.currentProvinceId = item["currentProvinceId"] == "NULL" ? null : item["currentProvinceId"]; profile.currentDistrictId = item["currentDistrictId"] == "NULL" ? null : item["currentDistrictId"]; profile.currentSubDistrictId = item["currentSubDistrictId"] == "NULL" ? null : item["currentSubDistrictId"]; profile.currentZipCode = item["currentZipCode"] == "NULL" ? null : item["currentZipCode"]; profile.avatar = item["avatar"] == "NULL" ? null : item["avatar"]; profile.avatarName = item["avatarName"] == "NULL" ? null : item["avatarName"]; // profile.dateRetireLaw = // item["dateRetireLaw"] == "NULL" ? null : new Date(item["dateRetireLaw"]); profile.leaveReason = item["leaveReason"] == "NULL" ? null : item["leaveReason"]; profile.dutyTimeId = item["dutyTimeId"] == "NULL" ? null : item["dutyTimeId"]; // profile.dutyTimeEffectiveDate = // item["dutyTimeEffectiveDate"] == "NULL" ? null : new Date(item["dutyTimeEffectiveDate"]); profiles.push(profile); }), ); await this.profileRepo.save(profiles); return new HttpSuccess(getProFile); } @Post("uploadSQLFamilly-Father") @UseInterceptors(FileInterceptor("file")) async UploadFileSQLFamilly( @UploadedFile() file: Express.Multer.File, // @Request() request: { user: Record }, ) { const workbook = xlsx.read(file.buffer, { type: "buffer" }); const sheetName = workbook.SheetNames[0]; // Assuming we're reading the first sheet const sheet = workbook.Sheets[sheetName]; const getProFile = xlsx.utils.sheet_to_json(sheet); let profiles: any = []; await Promise.all( getProFile.map(async (item: any) => { // Create a new Profile entity and assign fields from the parsed data const profile = new ProfileFamilyFather(); // Check if the profile already exists const existingProfile = await this.profileFamilyFatherRepository.findOne({ where: { id: item["id"] }, }); // If profile exists, skip saving if (existingProfile) { return; } // Assign fields from the item to the profile entit profile.id = item["id"] == "NULL" ? null : item["id"]; // profile.createdAt = item["createdAt"] == "NULL" ? null : new Date(item["createdAt"]); profile.createdUserId = item["createdUserId"] == "NULL" ? null : item["createdUserId"]; // profile.lastUpdatedAt = // item["lastUpdatedAt"] == "NULL" ? null : new Date(item["lastUpdatedAt"]); profile.lastUpdateUserId = item["lastUpdateUserId"] == "NULL" ? null : item["lastUpdateUserId"]; profile.createdFullName = item["createdFullName"] == "NULL" ? null : item["createdFullName"]; profile.lastUpdateFullName = item["lastUpdateFullName"] == "NULL" ? null : item["lastUpdateFullName"]; profile.fatherPrefix = item["fatherPrefix"] == "NULL" ? null : item["fatherPrefix"]; profile.fatherFirstName = item["fatherFirstName"] == "NULL" ? null : item["fatherFirstName"]; profile.fatherLastName = item["fatherLastName"] == "NULL" ? null : item["fatherLastName"]; profile.fatherCareer = item["fatherCareer"] == "NULL" ? null : item["fatherCareer"]; profile.fatherCitizenId = item["fatherCitizenId"] == "NULL" ? null : item["fatherCitizenId"]; profile.fatherLive = item["fatherLive"] == "NULL" ? null : item["fatherLive"]; profile.profileId = item["profileId"] == "NULL" ? null : item["profileId"]; profile.profileEmployeeId = item["profileEmployeeId"] == "NULL" ? null : item["profileEmployeeId"]; profiles.push(profile); }), ); await this.profileFamilyFatherRepository.save(profiles); return new HttpSuccess(getProFile); } @Post("uploadSQLFamilly-Mother") @UseInterceptors(FileInterceptor("file")) async UploadFileSQLFamillyMother( @UploadedFile() file: Express.Multer.File, // @Request() request: { user: Record }, ) { const workbook = xlsx.read(file.buffer, { type: "buffer" }); const sheetName = workbook.SheetNames[0]; // Assuming we're reading the first sheet const sheet = workbook.Sheets[sheetName]; const getProFile = xlsx.utils.sheet_to_json(sheet); let profiles: any = []; await Promise.all( getProFile.map(async (item: any) => { // Create a new Profile entity and assign fields from the parsed data const profile = new ProfileFamilyMother(); // Check if the profile already exists const existingProfile = await this.profileFamilyMotherRepository.findOne({ where: { id: item["id"] }, }); // If profile exists, skip saving if (existingProfile) { return; } // Assign fields from the item to the profile entit profile.id = item["id"] == "NULL" ? null : item["id"]; // profile.createdAt = item["createdAt"] == "NULL" ? null : new Date(item["createdAt"]); profile.createdUserId = item["createdUserId"] == "NULL" ? null : item["createdUserId"]; // profile.lastUpdatedAt = // item["lastUpdatedAt"] == "NULL" ? null : new Date(item["lastUpdatedAt"]); profile.lastUpdateUserId = item["lastUpdateUserId"] == "NULL" ? null : item["lastUpdateUserId"]; profile.createdFullName = item["createdFullName"] == "NULL" ? null : item["createdFullName"]; profile.lastUpdateFullName = item["lastUpdateFullName"] == "NULL" ? null : item["lastUpdateFullName"]; profile.motherPrefix = item["motherPrefix"] == "NULL" ? null : item["motherPrefix"]; profile.motherFirstName = item["motherFirstName"] == "NULL" ? null : item["motherFirstName"]; profile.motherLastName = item["motherLastName"] == "NULL" ? null : item["motherLastName"]; profile.motherCareer = item["motherCareer"] == "NULL" ? null : item["motherCareer"]; profile.motherCitizenId = item["motherCitizenId"] == "NULL" ? null : item["motherCitizenId"]; profile.motherLive = item["motherLive"] == "NULL" ? null : item["motherLive"]; profile.profileId = item["profileId"] == "NULL" ? null : item["profileId"]; profile.profileEmployeeId = item["profileEmployeeId"] == "NULL" ? null : item["profileEmployeeId"]; profiles.push(profile); }), ); await this.profileFamilyMotherRepository.save(profiles); return new HttpSuccess(getProFile); } @Post("uploadSQLFamilly-Couple") @UseInterceptors(FileInterceptor("file")) async UploadFileSQLFamillyCouple( @UploadedFile() file: Express.Multer.File, // @Request() request: { user: Record }, ) { const workbook = xlsx.read(file.buffer, { type: "buffer" }); const sheetName = workbook.SheetNames[0]; // Assuming we're reading the first sheet const sheet = workbook.Sheets[sheetName]; const getProFile = xlsx.utils.sheet_to_json(sheet); let profiles: any = []; await Promise.all( getProFile.map(async (item: any) => { // Create a new Profile entity and assign fields from the parsed data const profile = new ProfileFamilyCouple(); // Check if the profile already exists const existingProfile = await this.profileFamilyCoupleRepository.findOne({ where: { id: item["id"] }, }); // If profile exists, skip saving if (existingProfile) { return; } // Assign fields from the item to the profile entit profile.id = item["id"] == "NULL" ? null : item["id"]; // profile.createdAt = item["createdAt"] == "NULL" ? null : new Date(item["createdAt"]); profile.createdUserId = item["createdUserId"] == "NULL" ? null : item["createdUserId"]; // profile.lastUpdatedAt = // item["lastUpdatedAt"] == "NULL" ? null : new Date(item["lastUpdatedAt"]); profile.lastUpdateUserId = item["lastUpdateUserId"] == "NULL" ? null : item["lastUpdateUserId"]; profile.createdFullName = item["createdFullName"] == "NULL" ? null : item["createdFullName"]; profile.lastUpdateFullName = item["lastUpdateFullName"] == "NULL" ? null : item["lastUpdateFullName"]; profile.couple = item["couple"] == "NULL" ? null : item["couple"]; profile.couplePrefix = item["couplePrefix"] == "NULL" ? null : item["couplePrefix"]; profile.coupleFirstName = item["coupleFirstName"] == "NULL" ? null : item["coupleFirstName"]; profile.coupleLastName = item["coupleLastName"] == "NULL" ? null : item["coupleLastName"]; profile.coupleLastNameOld = item["coupleLastNameOld"] == "NULL" ? null : item["coupleLastNameOld"]; profile.coupleCareer = item["coupleCareer"] == "NULL" ? null : item["coupleCareer"]; profile.coupleCitizenId = item["coupleCitizenId"] == "NULL" ? null : item["coupleCitizenId"]; profile.coupleLive = item["coupleLive"] == "NULL" ? null : item["coupleLive"]; profile.relationship = item["relationship"] == "NULL" ? null : item["relationship"]; profile.profileId = item["profileId"] == "NULL" ? null : item["profileId"]; profile.profileEmployeeId = item["profileEmployeeId"] == "NULL" ? null : item["profileEmployeeId"]; profiles.push(profile); }), ); await this.profileFamilyCoupleRepository.save(profiles); return new HttpSuccess(getProFile); } @Post("uploadSQLSalary") @UseInterceptors(FileInterceptor("file")) async UploadFileSQLSalary( @UploadedFile() file: Express.Multer.File, // @Request() request: { user: Record }, ) { const workbook = xlsx.read(file.buffer, { type: "buffer" }); let profiles: any = []; let allData: any[] = []; for (const sheetName of workbook.SheetNames) { const sheet = workbook.Sheets[sheetName]; const getProFile = xlsx.utils.sheet_to_json(sheet); await Promise.all( getProFile.map(async (item: any) => { const profile = new ProfileSalary(); const existingProfile = await this.salaryRepository.findOne({ where: { id: item["id"] }, }); if (existingProfile) { return; } profile.id = item["id"] == "NULL" ? null : item["id"]; // profile.createdAt = item["createdAt"] == "NULL" ? null : new Date(item["createdAt"]); profile.createdUserId = item["createdUserId"] == "NULL" ? null : item["createdUserId"]; // profile.lastUpdatedAt = // item["lastUpdatedAt"] == "NULL" ? null : new Date(item["lastUpdatedAt"]); profile.lastUpdateUserId = item["lastUpdateUserId"] == "NULL" ? null : item["lastUpdateUserId"]; profile.createdFullName = item["createdFullName"] == "NULL" ? null : item["createdFullName"]; profile.lastUpdateFullName = item["lastUpdateFullName"] == "NULL" ? null : item["lastUpdateFullName"]; // profile.date = item["date"] == "NULL" ? null : new Date(item["date"]); profile.amount = item["amount"] == "NULL" ? null : item["amount"]; profile.positionSalaryAmount = item["positionSalaryAmount"] == "NULL" ? null : item["positionSalaryAmount"]; profile.mouthSalaryAmount = item["mouthSalaryAmount"] == "NULL" ? null : item["mouthSalaryAmount"]; profile.profileId = item["profileId"] == "NULL" ? null : item["profileId"]; profile.refCommandNo = item["refCommandNo"] == "NULL" ? null : item["refCommandNo"]; profile.posNo = item["posNo"] == "NULL" ? null : item["posNo"]; profile.position = item["position"] == "NULL" ? null : item["position"]; profile.positionLine = item["positionLine"] == "NULL" ? null : item["positionLine"]; profile.positionPathSide = item["positionPathSide"] == "NULL" ? null : item["positionPathSide"]; profile.positionExecutive = item["positionExecutive"] == "NULL" ? null : item["positionExecutive"]; profile.positionType = item["positionType"] == "NULL" ? null : item["positionType"]; profile.positionLevel = item["positionLevel"] == "NULL" ? null : item["positionLevel"]; profile.templateDoc = item["templateDoc"] == "NULL" ? null : item["templateDoc"]; profile.order = item["order"] == "NULL" ? null : item["order"]; profile.profileEmployeeId = item["profileEmployeeId"] == "NULL" ? null : item["profileEmployeeId"]; profiles.push(profile); }), ); allData = allData.concat(getProFile); } await this.salaryRepository.save(profiles); return new HttpSuccess(allData); } }