Skip to content

Commit

Permalink
Implement manual validation and remove interceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
neos1803 committed Aug 20, 2021
1 parent 481db27 commit b873b0b
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/app.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import { Args, Mutation, Query, Resolver } from "@nestjs/graphql";
import { FileUpload, GraphQLUpload } from "graphql-upload";
import { createWriteStream } from "fs";
// import { UseInterceptors } from "@nestjs/common";
// import { SingleFileInterceptor } from "src/interceptors/request.inteceptors";
import { BadRequestException, InternalServerErrorException } from "@nestjs/common";
import { fileSizeValidation } from "./utils/validation";

@Resolver()
export class AppResolver {

@Mutation(returns => Boolean)
// @UseInterceptors(SingleFileInterceptor('file'))
async uploadFile(
@Args('file', { type: () => GraphQLUpload }) file: FileUpload
) {
try {
// console.log(file)
// const file_name = await this.uploadFileHelper(file);
console.log(1)
if (file.filename.split(".").pop() != 'png') throw new BadRequestException("File type musst be png");
await fileSizeValidation(file.createReadStream(), 1000).catch((e) => {
throw new BadRequestException(e)
});

const file_name = await this.uploadFileHelper(file);
return true;
} catch (error) {
throw new Error(error.message);
throw new InternalServerErrorException(error.message);
}
}

Expand Down

0 comments on commit b873b0b

Please sign in to comment.