mirror of
https://github.com/filecoin-project/slate.git
synced 2024-09-11 22:07:08 +03:00
adding sendgrid contacts update functions
This commit is contained in:
parent
5563574dc3
commit
4e5f1d2d67
@ -95,10 +95,12 @@ import pruneVerifications from "~/node_common/data/methods/prune-verifications";
|
||||
// NOTE(jim):
|
||||
// one-offs
|
||||
import createOrphan from "~/node_common/data/methods/create-orphan";
|
||||
import getAllSendgridContacts from "~/node_common/data/methods/get-all-sendgrid-contacts";
|
||||
|
||||
export {
|
||||
// NOTE(jim): One-offs
|
||||
createOrphan,
|
||||
getAllSendgridContacts,
|
||||
// NOTE(jim): User operations
|
||||
createUser,
|
||||
updateUserById,
|
||||
|
33
node_common/data/methods/get-all-sendgrid-contacts.js
Normal file
33
node_common/data/methods/get-all-sendgrid-contacts.js
Normal file
@ -0,0 +1,33 @@
|
||||
import * as Serializers from "~/node_common/serializers";
|
||||
import { runQuery } from "~/node_common/data/utilities";
|
||||
|
||||
export default async () => {
|
||||
return await runQuery({
|
||||
label: "GET_ALL_SENDGRID_CONTACTS",
|
||||
queryFn: async (DB) => {
|
||||
let query = await DB.select("id", "username", "email").from("users").whereNotNull("email");
|
||||
|
||||
if (!query || query.error) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let formatted = query.map((user) => {
|
||||
return {
|
||||
email: user.email,
|
||||
custom_fields: {
|
||||
w4_T: user.id,
|
||||
w5_T: user.username,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
return JSON.parse(JSON.stringify(formatted));
|
||||
},
|
||||
errorFn: async (e) => {
|
||||
return {
|
||||
error: true,
|
||||
decorator: "GET_ALL_SENDGRID_CONTACTS",
|
||||
};
|
||||
},
|
||||
});
|
||||
};
|
35
scripts/sendgrid-update.js
Normal file
35
scripts/sendgrid-update.js
Normal file
@ -0,0 +1,35 @@
|
||||
import "isomorphic-fetch";
|
||||
|
||||
import * as Logging from "~/common/logging";
|
||||
import * as Data from "~/node_common/data";
|
||||
|
||||
async function updateSendgridFields() {
|
||||
let customFields = { name: "username", field_type: "Text" };
|
||||
const fieldsResponse = await fetch("https://api.sendgrid.com/v3/marketing/field_definitions", {
|
||||
method: "POST",
|
||||
headers: new Headers({
|
||||
Authorization: `Bearer ${process.env.SENDGRID_API_KEY}`,
|
||||
"content-type": "application/json",
|
||||
}),
|
||||
body: JSON.stringify(customFields),
|
||||
});
|
||||
console.log(fieldsResponse);
|
||||
let json = await fieldsResponse.json();
|
||||
console.log(json);
|
||||
}
|
||||
|
||||
async function updateSendgridContacts() {
|
||||
let contacts = await Data.getAllSendgridContacts();
|
||||
let data = { contacts };
|
||||
const response = await fetch("https://api.sendgrid.com/v3/marketing/contacts", {
|
||||
method: "PUT",
|
||||
headers: new Headers({
|
||||
Authorization: `Bearer ${process.env.SENDGRID_API_KEY}`,
|
||||
"content-type": "application/json",
|
||||
}),
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
console.log(response);
|
||||
let json = await response.json();
|
||||
console.log(json);
|
||||
}
|
Loading…
Reference in New Issue
Block a user