I am trying to create two custom pipes ExcelToJsonPipe
and JsonValidationPipe
. First to transform the Excel file content into Json, and second is to validate that Json.
But the transform and validation logic depends on a query parameter which I am trying to pass in the constructor of these pipes.
@UsePipes(
new JoiValidationPipe({
param: getByIdValidations,
query: uploadExcelQueryValidation,
}),
)
@UseInterceptors(FileInterceptor('file'))
@Post(':id/questions/uploadExcel')
async createQuestionsByUploadExcel(
@Param() params,
@Query() query,
@UploadedFile(new ExcelToJsonPipe(query), new JsonValidationPipe(query)) file: Express.Multer.File,
) {
return this._genieJourneyService.generateQuestionsByUploadExcel(params.id, file);
}
But this is one of the two similar errors I am getting:
error TS2552: Cannot find name ‘query’. Did you mean ‘Query’?
192 @UploadedFile(new ExcelToJsonPipe(query), new JsonValidationPipe(query)) file: Express.Multer.File
My question is: how can I pass the query to constructor of these pipes, please?
For more context I am providing some more details:
export const uploadExcelQueryValidation = Joi.object({
gameFormat: Joi.string().valid(...Object.values(GenieGames))
}).unknown(false);
export class ExcelToJsonPipe implements PipeTransform {
constructor(private readonly queryParams: any) {}
async transform(value: any, metadata: ArgumentMetadata) {
if (!value) {
throw new BadRequestException('No file uploaded');
}
// here is some logic to transform the value
}
Thanks in advance. Any help in this will be appreciated.