Initial commit

This commit is contained in:
Torsten Schulz
2024-07-17 22:24:56 +02:00
commit 3880a265eb
126 changed files with 10959 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
import { getMessages as getMessagesService, findMatch, registerUser as registerUserService, addMessage, endChat } from '../services/chatService.js';
export const getMessages = (req, res) => {
const { to, from } = req.body;
const messages = getMessagesService(to, from);
res.status(200).json(messages);
};
export const findRandomChatMatch = (req, res) => {
const { genders, age, id } = req.body;
const match = findMatch(genders, age, id);
if (match) {
res.status(200).json({ status: 'matched', user: match });
} else {
res.status(200).json({ status: 'waiting' });
}
};
export const registerUser = (req, res) => {
const { gender, age } = req.body;
const userId = registerUserService(gender, age);
res.status(200).json({ id: userId });
};
export const sendMessage = (req, res) => {
const from = req.body.from;
const to = req.body.to;
const text = req.body.text;
const message = addMessage(from, to, text);
res.status(200).json(message);
};
export const removeUser = (req, res) => {
const { id } = req.body;
removeUserService(id);
res.sendStatus(200);
};
export const stopChat = (req, res) => {
const { id } = req.body;
endChat(id);
res.sendStatus(200);
}