import { Request, Response } from "express";
import Stacker from "../middlewares/stacker";
import { GetUserMiddleware } from "../middlewares/user";
import Mail from "../../models/mail";

export const GetContactInfos = Stacker(
   GetUserMiddleware(true, true),
   async (req: Request, res: Response) => {
      let mails = await Promise.all(
         req.user.mails.map((mail) => Mail.findById(mail))
      );

      let contact = {
         mails: mails.filter((e) => !!e),
         phones: req.user.phones,
      };
      res.json({ contact });
   }
);
