diff --git a/node/src/api/image/image.controller.ts b/node/src/api/image/image.controller.ts deleted file mode 100644 index 972c9c3..0000000 --- a/node/src/api/image/image.controller.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { Response, Request } from 'express'; -import { createImage, findImageById } from '../../models/image'; -import { HTTP_STATUS } from '../../constants'; - -/** - * Firebase API controllers, logic for endpoint routes. - * @author Ibrahim Almalki - */ - -// TODO: JSDOC - -// Create image -export const handleCreateImage = async (req: Request, res: Response) => { - try { - const { imageEncoded } = req.body; - const image = await createImage(imageEncoded); - - res.status(HTTP_STATUS.SUCCESS).json({ image }); - } catch (error) { - console.error('Error creating image:', error); - res - .status(HTTP_STATUS.INTERNAL_SERVER_ERROR) - .json({ error: 'Failed to create image' }); - } -}; - -const validateId = (id: string, res: Response): id is string => { - if (id === undefined) { - res.status(HTTP_STATUS.ERROR).json({ error: 'NO ID PROVIDED' }); - return false; - } - return true; -}; - -const notFoundError = (res: Response) => - res.status(HTTP_STATUS.ERROR).json({ error: 'image not found' }); - -// Get image -export const handleFindImageById = async (req: Request, res: Response) => { - try { - const imageId = req.body.id; // The comment ID parameter is in the body. - if (!validateId(imageId, res)) return; - - const image = await findImageById(imageId as string); - - if (image) { - res.status(HTTP_STATUS.SUCCESS).json({ image }); - } else { - return notFoundError(res); - } - } catch (error) { - console.error('Error finding image by ID:', error); - res - .status(HTTP_STATUS.INTERNAL_SERVER_ERROR) - .json({ error: 'Failed to find image' }); - } -}; diff --git a/node/src/api/image/image.route.ts b/node/src/api/image/image.route.ts deleted file mode 100644 index c6805fa..0000000 --- a/node/src/api/image/image.route.ts +++ /dev/null @@ -1,18 +0,0 @@ -import express from 'express'; -import { handleCreateImage, handleFindImageById } from './image.controller'; - -/** - * Defines image routes. - * @authors Ibrahim Almalki - */ - -// The express router -const router = express.Router(); - -// POST create a new Image -router.post('/createImage', handleCreateImage); - -// GET Image by ID -router.get('/getImage', handleFindImageById); - -export default router; diff --git a/node/src/app.ts b/node/src/app.ts index d066108..3d31049 100644 --- a/node/src/app.ts +++ b/node/src/app.ts @@ -17,7 +17,6 @@ import boardRoutes from './api/board/board.route'; import authRoutes from './api/auth/auth.route'; import sfuRoutes from './api/sfu/sfu.route'; import tenancyRoutes from './api/tenancy/tenancy.route'; -import imageRoutes from './api/image/image.route'; const mainLogger = new Logger('MainModule', LOG_LEVEL); const port = 3005; @@ -41,7 +40,6 @@ app.use('/board', boardRoutes); app.use('/auth', authRoutes); app.use('/sfu', sfuRoutes); app.use('/tenancy', tenancyRoutes); -app.use('/image', imageRoutes); server.listen(port, () => { mainLogger.info(`Example app listening on port ${port}.`); diff --git a/node/src/models/image.ts b/node/src/models/image.ts deleted file mode 100644 index 2a28194..0000000 --- a/node/src/models/image.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { - FastFire, - FastFireCollection, - FastFireField, - FastFireDocument, -} from 'fastfire'; -import { generateRandId } from '../utils/misc'; - -/** - * Defines image class. - * @authors Ibrahim Almalki - */ - -//TODO: add createdAt and updatedAt -@FastFireCollection('Image') -export class Image extends FastFireDocument { - @FastFireField({ required: true }) - uid!: string; - @FastFireField({ required: true }) - imageEncoded!: string; - @FastFireField({ required: true }) - createdAt!: Date; -} - -// Function to create an image -export async function createImage(imageEncoded: string) { - const uid = generateRandId(); - const createdAt = new Date().toUTCString(); - return await FastFire.create( - Image, - { - uid, - imageEncoded, - createdAt, - }, - uid, - ); -} - -// Function to find a image by ID -export const findImageById = async (imageId: string) => - FastFire.findById(Image, imageId);