import { Express } from 'express' import { send as sendEmail } from '../utils/email' export default (server: Express) => { server.post('/api/services/newBusiness', async (req, res) => { const { body } = req const bodyFormatted = { ...body, deliveryDays: body.deliveryDays || 'None', ...body?.options?.create?.reduce( (acc, option, index) => ({ ...acc, [`product #${index} - title`]: option.title, [`product #${index} - title french`]: option.titleFr, [`product #${index} - description`]: option.description, [`product #${index} - description french`]: option.descriptionFr, [`product #${index} - price`]: option.price, [`product #${index} - image`]: option.option?.image?.create?.url || 'None', }), {} ), } await sendEmail({ to: [{ email: 'info@usewilson.com' }], subject: 'New business registered', html: `

                ${Object.keys(bodyFormatted)
                  .map((key) => `${key}: ${JSON.stringify(bodyFormatted[key])}`)
                  .join('

')}

`, }) return res.status(200).send({}) }) }