Skip to content

Commit 8b38d4f

Browse files
Merge branch 're/manual-van-optout' into re/VAN_auto_opt_out
2 parents b4d391b + e2a3df9 commit 8b38d4f

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

src/server/api/schema.js

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import _ from "lodash";
66
import { gzip, makeTree, getHighestRole } from "../../lib";
77
import { capitalizeWord, groupCannedResponses } from "./lib/utils";
88
import httpRequest from "../lib/http-request";
9-
import ownedPhoneNumber from "./lib/owned-phone-number";
109

1110
import { getIngestMethod } from "../../extensions/contact-loaders";
1211
import {
@@ -82,6 +81,7 @@ import { Jobs } from "../../workers/job-processes";
8281
import { Tasks } from "../../workers/tasks";
8382

8483
const uuidv4 = require("uuid").v4;
84+
const Van = require("../../extensions/action-handlers/ngpvan-action.js");
8585

8686
// This function determines whether a field was requested
8787
// in a graphql query. Each graphql resolver receives a fourth parameter,
@@ -1292,7 +1292,7 @@ const rootMutations = {
12921292
}
12931293
}
12941294
return finalContacts;
1295-
},
1295+
}, //
12961296
createOptOut: async (
12971297
_,
12981298
{ optOut, campaignContactId, noReply },
@@ -1342,7 +1342,45 @@ const rootMutations = {
13421342
const newContact = cacheableData.campaignContact.updateCacheForOptOut(
13431343
contact
13441344
);
1345-
return newContact;
1345+
1346+
if (!await Van.available(organization)) return newContact;
1347+
1348+
// Checking that contact contains a vanId
1349+
// If not, return and skip next steps
1350+
try {
1351+
const c = JSON.stringify(contact.customFiels);
1352+
if (c?.VanID === undefined) return newContact;
1353+
} catch (exception) {
1354+
console.log(exception);
1355+
return newContact;
1356+
}
1357+
1358+
console.log(
1359+
`createOptOut VAN ${contact.cell}`
1360+
);
1361+
1362+
const body = {
1363+
"canvassContext": {
1364+
"inputTypeId": 11,
1365+
"phone": {
1366+
"dialingPrefix": "1",
1367+
"phoneNumber": contact.cell,
1368+
"smsOptInStatus": "O"
1369+
}
1370+
},
1371+
"resultCodeId": 205
1372+
};
1373+
1374+
try {
1375+
// I am assuming here that contact has vanID.
1376+
// will need to test
1377+
await Van.postCanvassResponse(contact, organization, body);
1378+
console.log(`canvasOptOut VAN success ${contact.cell}`)
1379+
} catch (e) {
1380+
console.log(`Error opting out ${contact.cell}: ${e}`);
1381+
} finally {
1382+
return newContact;
1383+
}
13461384
},
13471385
deleteQuestionResponses: async (
13481386
_,

0 commit comments

Comments
 (0)