Skip to content

Commit

Permalink
Move cast above check
Browse files Browse the repository at this point in the history
  • Loading branch information
viral32111 committed Nov 3, 2023
1 parent 02af5ec commit 74f80c6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Server/source/routes/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ expressApp.put( "/api/upload", ( request, response ) => {

// If we got to this point, then no errors occured

// Cast because TypeScript doesn't know how to do this automatically
const uploadedFiles = request.files as Express.Multer.File[] | undefined

// Fail if no files were uploaded
if ( request.files === undefined || request.files.length <= 0 ) return respondToRequest( response, HTTPStatusCodes.BadRequest, {
if ( !uploadedFiles || uploadedFiles.length <= 0 ) return respondToRequest( response, HTTPStatusCodes.BadRequest, {
error: ErrorCodes.NoFilesUploaded
} )

// Cast because TypeScript doesn't know how to do this automatically
const uploadedFiles = request.files as Express.Multer.File[]

// Loop through the uploaded files & add their type and URL to a payload for the response
const filesPayload: Attachment[] = []
for ( const file of uploadedFiles ) filesPayload.push( {
Expand Down

0 comments on commit 74f80c6

Please sign in to comment.