2021-08-27 21:09:45 +00:00
|
|
|
import { resolver } from "blitz";
|
|
|
|
import { z } from "zod";
|
|
|
|
|
|
|
|
import appLogger from "../../../integrations/logger";
|
|
|
|
import { addSubscriber } from "../../../integrations/mailchimp";
|
2021-08-30 15:05:20 +00:00
|
|
|
import { executeWebhook } from "../../../integrations/discord";
|
2021-08-27 21:09:45 +00:00
|
|
|
|
|
|
|
const logger = appLogger.child({ mutation: "join-waitlist" });
|
|
|
|
|
|
|
|
const bodySchema = z.object({
|
|
|
|
email: z.string().email(),
|
|
|
|
});
|
|
|
|
|
2021-08-30 15:05:20 +00:00
|
|
|
export default resolver.pipe(resolver.zod(bodySchema), async ({ email }) => {
|
2021-08-27 21:09:45 +00:00
|
|
|
try {
|
|
|
|
await addSubscriber(email);
|
2021-08-30 15:05:20 +00:00
|
|
|
await executeWebhook({
|
|
|
|
id: "881915196245950485",
|
|
|
|
token: "woZmauH3x-qY0mzIn--66NsrAFCJFvFaYrKDCMgfemVQBzdm86GhiowMOnZ_PezXtSV4",
|
|
|
|
content: `\`${email}\` just joined Shellphone's waitlist`,
|
|
|
|
});
|
2021-08-27 21:09:45 +00:00
|
|
|
} catch (error: any) {
|
|
|
|
logger.error(error.response?.data);
|
|
|
|
|
|
|
|
if (error.response?.data.title !== "Member Exists") {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|