done
This commit is contained in:
parent
c01f5c1d25
commit
c8f77ad783
35
src/app/api/notary/MailchimpController.ts
Normal file
35
src/app/api/notary/MailchimpController.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import { Response, Request } from "express";
|
||||||
|
import { Controller, Post } from "@ControllerPattern/index";
|
||||||
|
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||||
|
import { Service } from "typedi";
|
||||||
|
import authHandler from "@App/middlewares/AuthHandler";
|
||||||
|
import MailchimpService from "@Services/common/MailchimpService/MailchimpService";
|
||||||
|
|
||||||
|
|
||||||
|
@Controller()
|
||||||
|
@Service()
|
||||||
|
export default class MailchimpController extends ApiController {
|
||||||
|
constructor(private mailchimpService: MailchimpService) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Create a new customer
|
||||||
|
*/
|
||||||
|
@Post("/api/v1/notary/mailchimp", [authHandler])
|
||||||
|
protected async post(req: Request, response: Response) {
|
||||||
|
try {
|
||||||
|
//init IUser resource with request body values
|
||||||
|
const email = req.body.email;
|
||||||
|
|
||||||
|
//call service to get prisma entity
|
||||||
|
const responseCall = await this.mailchimpService.addToMailchimpList(email);
|
||||||
|
|
||||||
|
//success
|
||||||
|
this.httpCreated(response, responseCall);
|
||||||
|
} catch (error) {
|
||||||
|
this.httpInternalError(response, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -54,6 +54,7 @@ import StripeController from "./api/admin/StripeController";
|
|||||||
import StripeWebhooks from "@Common/webhooks/stripeWebhooks";
|
import StripeWebhooks from "@Common/webhooks/stripeWebhooks";
|
||||||
import RulesGroupsController from "./api/admin/RulesGroupsController";
|
import RulesGroupsController from "./api/admin/RulesGroupsController";
|
||||||
import NotesController from "./api/customer/NotesController";
|
import NotesController from "./api/customer/NotesController";
|
||||||
|
import MailchimpController from "./api/notary/MailchimpController";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description This allow to declare all controllers used in the application
|
* @description This allow to declare all controllers used in the application
|
||||||
@ -116,5 +117,6 @@ export default {
|
|||||||
Container.get(StripeWebhooks);
|
Container.get(StripeWebhooks);
|
||||||
Container.get(RulesGroupsController);
|
Container.get(RulesGroupsController);
|
||||||
Container.get(NotesController);
|
Container.get(NotesController);
|
||||||
|
Container.get(MailchimpController);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -160,6 +160,9 @@ export class BackendVariables {
|
|||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
public readonly IDNOT_PROD_BASE_URL!: string;
|
public readonly IDNOT_PROD_BASE_URL!: string;
|
||||||
|
|
||||||
|
@IsNotEmpty()
|
||||||
|
public readonly MAILCHIMP_KEY!: string;
|
||||||
|
|
||||||
public constructor() {
|
public constructor() {
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
this.DATABASE_PORT = process.env["DATABASE_PORT"]!;
|
this.DATABASE_PORT = process.env["DATABASE_PORT"]!;
|
||||||
@ -214,6 +217,7 @@ export class BackendVariables {
|
|||||||
this.STRIPE_UNLIMITED_SUBSCRIPTION_PRICE_ID = process.env["STRIPE_UNLIMITED_SUBSCRIPTION_PRICE_ID"]!;
|
this.STRIPE_UNLIMITED_SUBSCRIPTION_PRICE_ID = process.env["STRIPE_UNLIMITED_SUBSCRIPTION_PRICE_ID"]!;
|
||||||
this.STRIPE_UNLIMITED_ANNUAL_SUBSCRIPTION_PRICE_ID = process.env["STRIPE_UNLIMITED_ANNUAL_SUBSCRIPTION_PRICE_ID"]!;
|
this.STRIPE_UNLIMITED_ANNUAL_SUBSCRIPTION_PRICE_ID = process.env["STRIPE_UNLIMITED_ANNUAL_SUBSCRIPTION_PRICE_ID"]!;
|
||||||
this.IDNOT_PROD_BASE_URL = process.env["IDNOT_PROD_BASE_URL"]!;
|
this.IDNOT_PROD_BASE_URL = process.env["IDNOT_PROD_BASE_URL"]!;
|
||||||
|
this.MAILCHIMP_KEY = process.env["MAILCHIMP_KEY"]!;
|
||||||
}
|
}
|
||||||
public async validate(groups?: string[]) {
|
public async validate(groups?: string[]) {
|
||||||
const validationOptions = groups ? { groups } : undefined;
|
const validationOptions = groups ? { groups } : undefined;
|
||||||
|
@ -115,29 +115,23 @@ export default class MailchimpService extends BaseService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// private async addToMailchimpList(email: string) {
|
public async addToMailchimpList(email: string) {
|
||||||
// const MAILCHIMP_API_KEY = "3fa54304bc766dfd0b8043a827b28a3a-us17"
|
const MAILCHIMP_API_KEY = this.variables.MAILCHIMP_KEY;
|
||||||
// const data = {
|
const data = {
|
||||||
// email_address: email,
|
email_address: email,
|
||||||
// status: 'subscribed'
|
status: 'subscribed'
|
||||||
// };
|
};
|
||||||
|
|
||||||
// const response = await fetch(`https://us17.api.mailchimp.com/3.0/lists/6ea48f811d/members`, {
|
const response = await fetch(`https://us17.api.mailchimp.com/3.0/lists/6ea48f811d/members`, {
|
||||||
// method: 'POST',
|
method: 'POST',
|
||||||
// headers: {
|
headers: {
|
||||||
// 'Authorization': `apikey ${MAILCHIMP_API_KEY}`,
|
'Authorization': `apikey ${MAILCHIMP_API_KEY}`,
|
||||||
// 'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
// },
|
},
|
||||||
// body: JSON.stringify(data)
|
body: JSON.stringify(data)
|
||||||
// });
|
});
|
||||||
|
|
||||||
// const json = await response.json();
|
return response.json();
|
||||||
|
|
||||||
// if (response.status === 200) {
|
}
|
||||||
// res.json({ message: 'Successfully subscribed!' });
|
|
||||||
// } else {
|
|
||||||
// res.json({ message: 'Failed to subscribe.' });
|
|
||||||
// }
|
|
||||||
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user