From 6064c27facf8a6e1c42f0def153058db262d93ad Mon Sep 17 00:00:00 2001 From: KShervington Date: Mon, 9 Dec 2024 19:14:55 -0500 Subject: [PATCH] removed submission-related code --- .../src/controllers/submission.controller.ts | 36 ----------- .../src/interfaces/submission.interface.ts | 9 --- apps/backend/src/routes/submission.route.ts | 18 ------ apps/backend/src/server.ts | 3 +- docs/api.md | 60 ------------------- 5 files changed, 1 insertion(+), 125 deletions(-) delete mode 100644 apps/backend/src/controllers/submission.controller.ts delete mode 100644 apps/backend/src/interfaces/submission.interface.ts delete mode 100644 apps/backend/src/routes/submission.route.ts diff --git a/apps/backend/src/controllers/submission.controller.ts b/apps/backend/src/controllers/submission.controller.ts deleted file mode 100644 index 6d58144..0000000 --- a/apps/backend/src/controllers/submission.controller.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { NextFunction, Request, Response } from 'express'; -import { Container } from 'typedi'; -import { OpenaiService } from '@/services/openai.service'; -import { Submission } from '@/interfaces/submission.interface'; -import { HttpException } from '@/exceptions/HttpException'; -import { CaptchaService } from '@/services/captcha.service'; - -export class SubmissionController { - public openai = Container.get(OpenaiService); - public captcha = Container.get(CaptchaService); - - public submitReceipt = async (req: Request, res: Response, next: NextFunction): Promise => { - try { - const body: Omit = req.body; - - if (!(await this.captcha.validateCaptcha(body.captcha))) { - throw new HttpException(400, 'Invalid captcha. Please try again.'); - } - - const submissionRequest: Submission = { - ...body, - timestamp: Date.now(), - }; - - const validationResult = await this.openai.validateImage(body.image); - - if (validationResult == undefined || !('validityFactor' in (validationResult as object))) { - throw new HttpException(500, 'Error validating image'); - } - - res.status(200).json({ validation: validationResult }); - } catch (error) { - next(error); - } - }; -} diff --git a/apps/backend/src/interfaces/submission.interface.ts b/apps/backend/src/interfaces/submission.interface.ts deleted file mode 100644 index 73082c3..0000000 --- a/apps/backend/src/interfaces/submission.interface.ts +++ /dev/null @@ -1,9 +0,0 @@ -export interface Submission { - _id?: string; - round?: number; - address: string; - captcha: string; - timestamp: number; - image?: string; - deviceID?: string; -} diff --git a/apps/backend/src/routes/submission.route.ts b/apps/backend/src/routes/submission.route.ts deleted file mode 100644 index 730a77b..0000000 --- a/apps/backend/src/routes/submission.route.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Router } from 'express'; -import { Routes } from '@interfaces/routes.interface'; -import { SubmissionController } from '@/controllers/submission.controller'; -import { ValidationMiddleware } from '@/middlewares/validation.middleware'; -import { SubmitDto } from '@/dtos/submission.dto'; - -export class SubmissionRoute implements Routes { - public router = Router(); - public submission = new SubmissionController(); - - constructor() { - this.initializeRoutes(); - } - - private initializeRoutes() { - this.router.post(`/submitReceipt`, ValidationMiddleware(SubmitDto), this.submission.submitReceipt); - } -} diff --git a/apps/backend/src/server.ts b/apps/backend/src/server.ts index b55e08c..7839b53 100644 --- a/apps/backend/src/server.ts +++ b/apps/backend/src/server.ts @@ -1,7 +1,6 @@ import { App } from '@/app'; import { ValidateEnv } from '@utils/validateEnv'; import { initializeOpenAI } from './utils/initializeOpenAI'; -import { SubmissionRoute } from './routes/submission.route'; import { UserRoute } from './routes/users.route'; import { ProductRoute } from './routes/products.route'; import { WalletRoute } from './routes/wallet.route'; @@ -11,6 +10,6 @@ ValidateEnv(); export const openAIHelper = initializeOpenAI(); -const app = new App([new SubmissionRoute(), new UserRoute(), new ProductRoute(), new WalletRoute(), new PurchaseRoute()]); +const app = new App([new UserRoute(), new ProductRoute(), new WalletRoute(), new PurchaseRoute()]); app.listen(); diff --git a/docs/api.md b/docs/api.md index 7d826aa..19f3982 100644 --- a/docs/api.md +++ b/docs/api.md @@ -900,63 +900,3 @@ Response: "message": "Purchase history retrieved" } ``` - ---- - -## Submissions - -**POST** _/submitReceipt_ - -Submit a receipt for processing and validation. - -| Parameter | Type | Description | -| --------- | :------: | ------------------------------------------------------- | -| image | `string` | Base64 encoded image of the receipt | -| captcha | `string` | Captcha verification token | -| timestamp | `number` | Automatically added server-side timestamp of submission | - -**Response** - -Returns the validation result for the submitted receipt. - -| Key | Type | Description | -| ---------- | :------: | ---------------------------------------- | -| validation | `object` | Object containing the validation results | - -**Example** - -Request: - -```http -POST /submitReceipt -``` - -Request Body: - -```json -{ - "image": "base64_encoded_image_data", - "captcha": "captcha_verification_token" -} -``` - -Response: - -```json -{ - "validation": { - "validityFactor": 0.95, - "details": { - "isValid": true, - "confidence": "high" - } - } -} -``` - -**Error Responses** - -| Status Code | Description | -| ----------- | ---------------------- | -| 400 | Invalid captcha | -| 500 | Error validating image |