import query from '../server-utils/query.js';
import { declareHandler } from '../server-utils/routesHandler.js';

/**
 * This file contains route handlers for all our landing pages
 *
 * Any route handlers that we need to have pertaining to experimental landing pages
 * should go here.
 */

export const vstSignup = declareHandler({
  func: async (req, res) => {
    const { email } = req.body;
    if (!email) return res.send({ success: false });
    await query(
      `
        INSERT INTO waiting_list_signups (email) SELECT $1
        WHERE NOT EXISTS (
            SELECT * FROM waiting_list_signups WHERE email = $1
        );
    `,
      [email]
    );
    res.send({ success: true });
  },
});
