-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fixed notification issue * Added flyer notification * Added flyer notification * Updated Organization and Flyer models * Updated test cases * Added getFlyersByCategorySlug query * Update query description * Inline notification calls * Add createFlyer mutation * `deleteFlyer` mutation (#103) * Add deleteFlyer mutation * Address PR comments * Update utils.ts * Update FlyerRepo.ts
- Loading branch information
Showing
5 changed files
with
199 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { MiddlewareFn } from 'type-graphql'; | ||
import { Context } from 'vm'; | ||
import utils from '../utils'; | ||
|
||
const FlyerUploadErrorInterceptor: MiddlewareFn<Context> = async ({ args, context }, next) => { | ||
try { | ||
// Upload image to our upload service | ||
context.imageURL = await utils.uploadImage(args.imageB64); | ||
return await next(); | ||
} catch (err) { | ||
throw new Error('An error occured while uploading the flyer image.'); | ||
} | ||
}; | ||
|
||
export default { FlyerUploadErrorInterceptor }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import fetch from 'node-fetch-commonjs'; | ||
|
||
interface UploadResponse { | ||
success: boolean; | ||
data: string; | ||
} | ||
|
||
/** | ||
* Upload an image to our servers | ||
* | ||
* @param imageB64 the base64 string to upload | ||
* @returns the URl representing the image | ||
*/ | ||
const uploadImage = async (imageB64: string): Promise<string> => { | ||
// Upload image via a POST request | ||
const imagePayload = { | ||
bucket: process.env.UPLOAD_BUCKET, | ||
image: `data:image/png;base64,${imageB64}`, | ||
}; | ||
const response = await fetch(`${process.env.UPLOAD_SERVICE_URL}/upload/`, { | ||
method: 'POST', | ||
body: JSON.stringify(imagePayload), | ||
}); | ||
|
||
const responseData = (await response.json()) as UploadResponse; | ||
return responseData.data; | ||
}; | ||
|
||
/** | ||
* Remove an image from AppDev servers | ||
* | ||
* @param imageURL the image URL to remove | ||
* @returns true if the deletion was successful; otherwise false | ||
*/ | ||
const removeImage = async (imageURL: string): Promise<boolean> => { | ||
// Delete image via a POST request | ||
const payload = { | ||
bucket: process.env.UPLOAD_BUCKET, | ||
image_url: imageURL, | ||
}; | ||
const response = await fetch(`${process.env.UPLOAD_SERVICE_URL}/remove/`, { | ||
method: 'POST', | ||
body: JSON.stringify(payload), | ||
}); | ||
|
||
const responseData = (await response.json()) as UploadResponse; | ||
if (!responseData.success) { | ||
console.log(`Removing an image from our servers failed with image URL: ${imageURL}`); | ||
} | ||
return responseData.success; | ||
}; | ||
|
||
export default { removeImage, uploadImage }; |