diff --git a/server/src/subscriber/subscriber.controller.ts b/server/src/subscriber/subscriber.controller.ts index b9ef8299..0d6c7026 100644 --- a/server/src/subscriber/subscriber.controller.ts +++ b/server/src/subscriber/subscriber.controller.ts @@ -4,9 +4,6 @@ import { SubscriberService } from "./subscriber.service"; import { Request } from "express"; import validateEmail from "../_utils/validate-email"; -const PAUSE_BETWEEN_CHECKS = 3000; -const CHECKS_BEFORE_FAIL = 10; - @Controller() export class SubscriberController { apiKey = ""; @@ -53,26 +50,8 @@ export class SubscriberController { return; } - // Now we keep checking to make sure the import was successful - const importConfirmation = await this.subscriberService.checkCreate(request.body.email, response, 0, CHECKS_BEFORE_FAIL, PAUSE_BETWEEN_CHECKS, this.list) - - if(importConfirmation.isError && (importConfirmation.code === 408)) { - response.status(408).send({ - status: "error", - error: `Was not able to receive confirmation user information was updated in within ${PAUSE_BETWEEN_CHECKS * CHECKS_BEFORE_FAIL / 1000} seconds`, - }) - return; - } else if (importConfirmation.isError) { - response.status(importConfirmation.code).send({ - status: "error", - error: importConfirmation.message - }) - return; - } - response.status(200).send({ status: "success", - user: importConfirmation[0].body.result[request.body.email] }) return; diff --git a/server/src/subscriber/subscriber.service.ts b/server/src/subscriber/subscriber.service.ts index 3cd7c368..d82a6768 100644 --- a/server/src/subscriber/subscriber.service.ts +++ b/server/src/subscriber/subscriber.service.ts @@ -1,6 +1,8 @@ import { Injectable, Res } from "@nestjs/common"; import { ConfigService } from "../config/config.service"; import { Client } from "@sendgrid/client"; +const crypto = require('crypto'); + type HttpMethod = 'get'|'GET'|'post'|'POST'|'put'|'PUT'|'patch'|'PATCH'|'delete'|'DELETE'; @@ -43,7 +45,7 @@ export class SubscriberService { method: 'PUT', body: { "list_ids": [list], - "contacts": [{"email": email}] + "contacts": [{"email": email, "anonymous_id": crypto.randomUUID()}] } } @@ -56,26 +58,4 @@ export class SubscriberService { return {isError: true, ...error}; } } - - async checkCreate(email: string, @Res() response, counter: number = 0, checksBeforeFail: number, pauseBetweenChecks: number, list: string) { - if(counter >= checksBeforeFail) { - return { isError: true, code: 408 } - } - - await delay(pauseBetweenChecks); - - const existingUser = await this.findByEmail(email); - - if(![200, 404].includes(existingUser.code)) { - console.error(existingUser.code, existingUser.message); - return { isError: true, code: existingUser.code, message: existingUser.message } - } - - if(existingUser[0] && existingUser[0].body.result[email].contact["list_ids"].includes(list)) { - // Success! - return { isError: false, code: 200, ...existingUser }; - } - - return await this.checkCreate(email, response, counter + 1, checksBeforeFail, pauseBetweenChecks, list); - } }