From 7bdc1b8b79a28425ae4c402defed9f7900f4ae58 Mon Sep 17 00:00:00 2001 From: hozayves Date: Tue, 14 May 2024 20:52:37 +0200 Subject: [PATCH] [finishes 187354275] chat on the App to ask for some information publicly --- package.json | 3 + public/index.html | 199 ++++++++++++++++++ src/controllers/chatController.ts | 7 + .../migrations/20240514132443-create-chats.js | 19 ++ src/routes/userRoute.ts | 2 + 5 files changed, 230 insertions(+) create mode 100644 public/index.html create mode 100644 src/controllers/chatController.ts create mode 100644 src/database/migrations/20240514132443-create-chats.js diff --git a/package.json b/package.json index 10b04590..12782eda 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,8 @@ "pg-hstore": "^2.3.4", "randomstring": "^1.3.0", "sequelize": "^6.37.2", + "socket.io": "^4.7.5", + "socket.io-client": "^4.7.5", "swagger-ui-express": "^5.0.0", "uuid": "^9.0.1", "winston": "^3.13.0", @@ -67,6 +69,7 @@ "@types/passport-google-oauth20": "^2.0.14", "@types/randomstring": "^1.3.0", "@types/sequelize": "^4.28.20", + "@types/socket.io-client": "^3.0.0", "@types/supertest": "^6.0.2", "@types/swagger-jsdoc": "^6.0.4", "@types/swagger-ui-express": "^4.1.6", diff --git a/public/index.html b/public/index.html new file mode 100644 index 00000000..4c7b479e --- /dev/null +++ b/public/index.html @@ -0,0 +1,199 @@ + + + + + + Socket.IO chat + + + + + +
+
+

+
+ +
+

+
+
+
    +
    +
    + +
    +
    +
    +
    + + + + \ No newline at end of file diff --git a/src/controllers/chatController.ts b/src/controllers/chatController.ts new file mode 100644 index 00000000..eeab5836 --- /dev/null +++ b/src/controllers/chatController.ts @@ -0,0 +1,7 @@ +import { Request, Response } from 'express'; +import { join } from 'path'; + +export const chatApplication = (req: Request, res: Response) => { + const filePath = join(__dirname, '../../public/index.html'); + res.sendFile(filePath); +}; diff --git a/src/database/migrations/20240514132443-create-chats.js b/src/database/migrations/20240514132443-create-chats.js new file mode 100644 index 00000000..5aa8cd16 --- /dev/null +++ b/src/database/migrations/20240514132443-create-chats.js @@ -0,0 +1,19 @@ +'use strict'; + +import sequelize from 'sequelize'; + +/** @type {import('sequelize-cli').Migration} */ +module.exports = { + async up(queryInterface, Sequelize) { + await queryInterface.createTable('Chat', { + id: { + type: Sequelize.UUID, + primaryKey: true, + allowNull: false, + defaultValue: sequelize.UUIDV4, + }, + }); + }, + + async down(queryInterface, Sequelize) {}, +}; diff --git a/src/routes/userRoute.ts b/src/routes/userRoute.ts index d3a0c268..923e9396 100644 --- a/src/routes/userRoute.ts +++ b/src/routes/userRoute.ts @@ -16,6 +16,7 @@ import multerUpload from '../helpers/multer'; import { checkUserRoles, isAuthenticated } from '../middlewares/authMiddlewares'; import { isCheckedOTP } from '../middlewares/otpAuthMiddleware'; import { verifyOTP } from '../controllers/authController'; +import { chatApplication } from '../controllers/chatController'; const router = Router(); @@ -30,5 +31,6 @@ router.post('/resend-verify', resendVerifyLink); router.put('/deactivate/:userId', isAuthenticated, deactivateUserAccount); router.put('/activate/:userId', isAuthenticated, checkUserRoles('admin'), activateUserAccount); router.patch('/enable2fa', isAuthenticated, checkUserRoles('seller'), enable2FA); +router.get('/chat', chatApplication); export default router;