import statusCode from "../utils/statusCodes"; import { Response } from "express"; import { RoomType } from "../mails/message/saveMessage"; import { getRoomType } from "../db/message/saveMessage-db"; import { getRoomOwner } from "../db/Room-db"; import emailManager from "../mails/EmailManager"; import MailBuilder from "../mails/utils/mailBuilder"; export default class Room { // todo change name static async response(body, res: Response) { const { user, roomId, text, html } = body; console.log(body) const roomType = (await getRoomType(roomId))[0].room_type; if (roomType === RoomType.DM) { const ownerEmail = (await getRoomOwner(roomId))[0].email; const mailBuilder = new MailBuilder(); mailBuilder.from(user).to(ownerEmail).text(text).html(html); emailManager.getSmtp(user).sendMail(mailBuilder.message); // send new msg to recipient of dm } else if (roomType === RoomType.GROUP || roomType === RoomType.THREAD) { // get all cc and to from of previous message and add them } else { res.status(statusCode.FORBIDDEN).send({ error: "Cannot add a new message in a room or a channel." }); } } }