//service class
async importExcel(userId, file){
const business = await this.getBusinessByUserId(Types.ObjectId(userId));
let errorData = [];
readXlsxFile(file, {schema}).then(async ({rows, errors}) => {
if(errors.length === 0){
await this.excelUploadQueue.add({
rows,
business
})
}
errors.forEach((error) => {
const errors = {
column: error.column,
value: error.value,
reason: error.reason,
}
errorData.push(errors)
});
console.log(errorData); can access the errorData here
})
console.log(errorData); cannot access it here, i want to access it here so that i
return errorData; // can return it here to my controller
}
//controller
@UseGuards(JwtAuthGuard)
@UseInterceptors(FileInterceptor('file'
, {
storage: diskStorage({
destination: './csv',
filename: (req, file, cb) => {
const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9)
cb(null, file.fieldname + '-' + uniqueSuffix + "-" + file.originalname)
}
})
}
))
@Post('/import-excel/employee')
@ApiOperation({summary: 'upload exployee data via excel'})
async uploadExcel(
@UploadedFile() file: Express.Multer.File,
@Request() req
){
const { id: userId } = req.user;
return await this.businessService.importExcel(userId, file.path);
}
How can i go abt it,been on it for some hours....When i apply a settimeout like the below code setTimeout(() => { console.log(errorData) // i could access it but its not returning to my controller }, 100);