Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add link to all pingers in emails #2

Merged
merged 2 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions __fixtures__/pinger.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function createPingerFixture(customData = {}) {
'56.992294 24.136619, 56.976394 23.995790, 56.924904 24.005336, 56.889288 24.108467, 56.932211 24.291935, 56.996502 24.245176, 56.992294 24.136619, 56.992294 24.136619',
frequency: 'immediate',
is_premium: true,
unsubscribe_key: 'XXXXXXXX-7eba-11eb-XXXX-663c33f40218',
...customData,
};
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@
},
"lint-staged": {
"*.js": "eslint --cache --fix"
}
},
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
3 changes: 2 additions & 1 deletion src/__snapshots__/process-sqs.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

exports[`process-sqs works with multiple PINGERs w/ multi-invocation frequencies 1`] = `
Object {
"all_pingers_url": "https://pinger.brokalys.com/#/pingers/111111,XXXXXXXX-7eba-11eb-XXXX-663c33f40218",
"area": 45,
"calc_price_per_sqm": 122.32,
"category": "apartment",
Expand All @@ -14,7 +15,7 @@ Object {
"price": 100000,
"rooms": 2,
"type": "sell",
"unsubscribe_url": "https://unsubscribe.brokalys.com/?key=undefined&id=111111",
"unsubscribe_url": "https://unsubscribe.brokalys.com/?key=XXXXXXXX-7eba-11eb-XXXX-663c33f40218&id=111111",
"url": "https://view.brokalys.com/?link=https%3A%2F%2Fbrokalys.com%2F",
}
`;
2 changes: 1 addition & 1 deletion src/__snapshots__/process-summary-queue.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Array [
},
"template_variables": Object {
"DataType": "String",
"StringValue": "{\\"is_premium\\":true,\\"limit_reached\\":false,\\"unsubscribe_url\\":\\"https://unsubscribe.brokalys.com/?key=undefined&id=c8bf6e7b-7eba-11eb-b2a8-663c33f40218\\",\\"properties\\":[[\\"https://brokalys.com/\\",100000,2,45,122.32,\\"https://brokalys.com/#/56.9965,24.245176,18/locate-building\\"],[\\"https://brokalys.com/\\",100000,2,45,122.32,\\"https://brokalys.com/#/56.9965,24.245176,18/locate-building\\"],[\\"https://brokalys.com/\\",100000,2,45,122.32,\\"https://brokalys.com/#/56.9965,24.245176,18/locate-building\\"]]}",
"StringValue": "{\\"is_premium\\":true,\\"limit_reached\\":false,\\"unsubscribe_url\\":\\"https://unsubscribe.brokalys.com/?key=XXXXXXXX-7eba-11eb-XXXX-663c33f40218&id=c8bf6e7b-7eba-11eb-b2a8-663c33f40218\\",\\"all_pingers_url\\":\\"https://pinger.brokalys.com/#/pingers/c8bf6e7b-7eba-11eb-b2a8-663c33f40218,XXXXXXXX-7eba-11eb-XXXX-663c33f40218\\",\\"properties\\":[[\\"https://brokalys.com/\\",100000,2,45,122.32,\\"https://brokalys.com/#/56.9965,24.245176,18/locate-building\\"],[\\"https://brokalys.com/\\",100000,2,45,122.32,\\"https://brokalys.com/#/56.9965,24.245176,18/locate-building\\"],[\\"https://brokalys.com/\\",100000,2,45,122.32,\\"https://brokalys.com/#/56.9965,24.245176,18/locate-building\\"]]}",
},
"to": Object {
"DataType": "String",
Expand Down
5 changes: 3 additions & 2 deletions src/process-sqs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const inside = require('point-in-polygon');
const db = require('./shared/db');
const sns = require('./shared/sns');
const createUnsubscribeLink = require('./shared/unsubscribe-link');
const { unsubscribeLink, allPingersLink } = require('./shared/pinger-link');
const utils = require('./shared/utils');

function parseLocation(location) {
Expand Down Expand Up @@ -109,7 +109,8 @@ exports.run = async (event, context) => {
false,
);

result.unsubscribe_url = createUnsubscribeLink(pinger);
result.unsubscribe_url = unsubscribeLink(pinger);
result.all_pingers_url = allPingersLink(pinger);
result.url = `https://view.brokalys.com/?link=${encodeURIComponent(
result.url,
)}`;
Expand Down
5 changes: 3 additions & 2 deletions src/process-summary-queue.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const db = require('./shared/db');
const generatePingerCharts = require('./shared/generate-pinger-charts');
const sns = require('./shared/sns');
const createUnsubscribeLink = require('./shared/unsubscribe-link');
const { unsubscribeLink, allPingersLink } = require('./shared/pinger-link');
const utils = require('./shared/utils');

const FREE_LIMIT = 100;
Expand Down Expand Up @@ -108,7 +108,8 @@ function sendEmail(context, pinger, properties, heroImgUrl) {
is_premium: pinger.is_premium,
limit_reached: properties.length > propertyLimit,
hero_img_url: heroImgUrl,
unsubscribe_url: createUnsubscribeLink(pinger),
unsubscribe_url: unsubscribeLink(pinger),
all_pingers_url: allPingersLink(pinger),
properties: properties
.splice(0, propertyLimit)
.map((data) => [
Expand Down
2 changes: 1 addition & 1 deletion src/process-summary-queue.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ describe('process-summary-queue', () => {
);
});

test.each(['is_premium', 'unsubscribe_url', 'properties'])(
test.each(['is_premium', 'unsubscribe_url', 'all_pingers_url', 'properties'])(
'adds the required template_variables field: %j',
async (field) => {
db.getPingersByFrequency.mockReturnValue([createPingerFixture()]);
Expand Down
17 changes: 17 additions & 0 deletions src/shared/pinger-link.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function createUnsubscribeLink(pinger) {
return `https://unsubscribe.brokalys.com/?key=${encodeURIComponent(
pinger.unsubscribe_key,
)}&id=${encodeURIComponent(pinger.id_hash)}`;
}

function createAllPingersLink(pinger) {
const id = encodeURIComponent(pinger.id_hash);
const unsubscribeKey = encodeURIComponent(pinger.unsubscribe_key);

return `https://pinger.brokalys.com/#/pingers/${id},${unsubscribeKey}`;
}

module.exports = {
unsubscribeLink: createUnsubscribeLink,
allPingersLink: createAllPingersLink,
};
5 changes: 0 additions & 5 deletions src/shared/unsubscribe-link.js

This file was deleted.

31 changes: 20 additions & 11 deletions src/templates/email.html
Original file line number Diff line number Diff line change
Expand Up @@ -450,24 +450,33 @@
width="100%"
style="margin: auto"
>
<tr>
<td
style="
padding: 20px;
font-family: sans-serif;
font-size: 12px;
line-height: 15px;
text-align: center;
color: #ffffff;
"
>
<tr
style="
border-top: 20px;
font-family: sans-serif;
font-size: 12px;
line-height: 15px;
text-align: center;
color: #ffffff;
"
>
<td>
<a
href="{{ unsubscribe_url }}"
style="color: #ffffff; text-decoration: underline"
>
Atrakstīties
</a>
</td>
<td>
<a
href="{{ all_pingers_url }}"
style="color: #ffffff; text-decoration: underline"
>
Skatīt visus pingerus
</a>
</td>

</tr>
</table>
<!-- Email Footer : END -->
Expand Down
30 changes: 19 additions & 11 deletions src/templates/summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -346,24 +346,32 @@
width="100%"
style="margin: auto"
>
<tr>
<td
style="
padding: 20px;
font-family: sans-serif;
font-size: 12px;
line-height: 15px;
text-align: center;
color: #ffffff;
"
>
<tr
style="
border-top: 20px;
font-family: sans-serif;
font-size: 12px;
line-height: 15px;
text-align: center;
color: #ffffff;
"
>
<td>
<a
href="{{ unsubscribe_url }}"
style="color: #ffffff; text-decoration: underline"
>
Atrakstīties
</a>
</td>
<td>
<a
href="{{ all_pingers_url }}"
style="color: #ffffff; text-decoration: underline"
>
Skatīt visus pingerus
</a>
</td>
</tr>
</table>
<!-- Email Footer : END -->
Expand Down