From a469966c88602777d266eedff9db26641c98d0d4 Mon Sep 17 00:00:00 2001 From: Ibrahim Almalki Date: Sat, 24 Feb 2024 19:40:00 -0500 Subject: [PATCH] remove image db table --- node/src/api/image/image.controller.ts | 57 -------------------------- node/src/api/image/image.route.ts | 18 -------- node/src/app.ts | 2 - node/src/models/image.ts | 42 ------------------- 4 files changed, 119 deletions(-) delete mode 100644 node/src/api/image/image.controller.ts delete mode 100644 node/src/api/image/image.route.ts delete mode 100644 node/src/models/image.ts 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);