Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into sandino/video-subtitles-in-public…
Browse files Browse the repository at this point in the history
…-folder

# Conflicts:
#	functions/src/cron/first-payout-email/index.ts
  • Loading branch information
mkue committed May 28, 2024
2 parents f152941 + ebffa12 commit 78563eb
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 26 deletions.
47 changes: 31 additions & 16 deletions functions/src/cron/first-payout-email/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { logger } from 'firebase-functions';
import { onSchedule } from 'firebase-functions/v2/scheduler';
import { DateTime } from 'luxon';
import { FirestoreAdmin } from '../../../../shared/src/firebase/admin/FirestoreAdmin';
import { toFirebaseAdminTimestamp } from '../../../../shared/src/firebase/admin/utils';
import { FirstPayoutEmailTemplateData, SendgridMailClient } from '../../../../shared/src/sendgrid/SendgridMailClient';
import { Contribution, CONTRIBUTION_FIRESTORE_PATH } from '../../../../shared/src/types/contribution';
import { CONTRIBUTION_FIRESTORE_PATH, Contribution } from '../../../../shared/src/types/contribution';
import { LanguageCode } from '../../../../shared/src/types/language';
import { User, USER_FIRESTORE_PATH } from '../../../../shared/src/types/user';
import { USER_FIRESTORE_PATH, User } from '../../../../shared/src/types/user';
import { toDateTime } from '../../../../shared/src/utils/date';

export const getFirstPayoutEmailReceivers = async (
Expand Down Expand Up @@ -61,21 +62,35 @@ export const getFirstPayoutEmailReceivers = async (
).flat();
};

// Run on the 16th of every month at 00:00
export default onSchedule('0 18 16 * *', async () => {
// TODO: change back to '0 0 16 * *
// Run on the 16th of every month at 15:00 UTC
export default onSchedule('0 15 16 * *', async () => {
let message: string = '';
const sendgridClient = new SendgridMailClient(process.env.SENDGRID_API_KEY!);
const firestoreAdmin = new FirestoreAdmin();
try {
const firestoreAdmin = new FirestoreAdmin();
const now = DateTime.now();
const fromDate = DateTime.fromObject({ year: now.year, month: now.month - 1, day: 16, hour: 0 }, { zone: 'utc' });
const toDate = DateTime.fromObject({ year: now.year, month: now.month, day: 16, hour: 0 }, { zone: 'utc' });
const firstPayoutEmailReceivers = await getFirstPayoutEmailReceivers(firestoreAdmin, fromDate, toDate);

const now = DateTime.now();
const fromDate = DateTime.fromObject({ year: now.year, month: now.month - 1, day: 16, hour: 0 }, { zone: 'utc' });
const toDate = DateTime.fromObject({ year: now.year, month: now.month, day: 16, hour: 0 }, { zone: 'utc' });
const firstPayoutEmailReceivers = await getFirstPayoutEmailReceivers(firestoreAdmin, fromDate, toDate);
await Promise.all(
firstPayoutEmailReceivers.map(async (entry) => {
const { email, language, templateData } = entry;
await sendgridClient.sendFirstPayoutEmail(email, language, templateData);
}),
);

await Promise.all(
firstPayoutEmailReceivers.map(async (entry) => {
const { email, language, templateData } = entry;
await sendgridClient.sendFirstPayoutEmail(email, language, templateData);
}),
);
message = `Successfully sent first payout emails to ${firstPayoutEmailReceivers.length} users`;
logger.info(message);
} catch (error) {
message = `Failed to send first payout emails: ${error}`;
logger.error(message);
} finally {
sendgridClient.send({
to: 'dev@socialincome.org',
from: 'hello@socialincome.org',
subject: 'First payout email cron job',
text: message,
});
}
});
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion shared/locales/de/website-about-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@
"board-member": "Vorstandsmitglied",
"software-development": "Softwareentwicklung",
"app-development": "App-Entwicklung",
"impact-measurement": "Impact Measurement"
"impact-measurement": "Impact Measurement",
"fundraising": "Fundraising"
},
"groups": {
"staff": {
Expand Down
3 changes: 2 additions & 1 deletion shared/locales/en/website-about-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@
"software-development": "Software Development",
"app-development": "App Development",
"impact-measurement": "Impact Measurement",
"strategy": "Strategy"
"strategy": "Strategy",
"fundraising": "Fundraising"
},
"groups": {
"staff": {
Expand Down
1 change: 1 addition & 0 deletions shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"dependencies": {
"@mailchimp/mailchimp_marketing": "^3.0.80",
"@sendgrid/mail": "^8.1.1",
"axios": "^1.6.8",
"firebase-admin": "^12.0.0",
"handlebars": "^4.7.8",
Expand Down
4 changes: 2 additions & 2 deletions shared/src/sendgrid/SendgridMailClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ export class SendgridMailClient extends MailService {
}

sendFirstPayoutEmail = async (email: string, language: LanguageCode, data: FirstPayoutEmailTemplateData) => {
let templateId = '';
let templateId;
if (language === 'de') {
templateId = 'd-3146eb9ee2054b28b22376113eb96ca9';
} else {
templateId = 'd-4e616d721b0240509f468c1e5ff22e6d';
}
await this.send({
to: email,
from: { name: 'Social Income', email: 'hello@socialincome.org' },
from: { name: 'Aurélie Schmiedlin', email: 'auerlie@socialincome.org' },
templateId,
dynamicTemplateData: data,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function Sdg({ lang }: { lang: WebsiteLanguage }) {
<SdgCard
title={translator.t('section-6.card-1.title')}
description={translator.t('section-6.card-1.description')}
paragraphs={[translator.t('section-6.card-2.paragraph-1')]}
paragraphs={[translator.t('section-6.card-1.paragraph-1')]}
/>
<SdgCard
title={translator.t('section-6.card-2.title')}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import lorenzoImage from '@/app/[lang]/[region]/(website)/about-us/(assets)/lore
import mabelImage from '@/app/[lang]/[region]/(website)/about-us/(assets)/mabel.jpeg';
import mariatuImage from '@/app/[lang]/[region]/(website)/about-us/(assets)/mariatu.jpg';
import marionImage from '@/app/[lang]/[region]/(website)/about-us/(assets)/marion.jpeg';
import matthewImage from '@/app/[lang]/[region]/(website)/about-us/(assets)/matthew.jpeg';
import michaelImage from '@/app/[lang]/[region]/(website)/about-us/(assets)/michael.jpeg';
import mikolajImage from '@/app/[lang]/[region]/(website)/about-us/(assets)/mikolaj.jpeg';
import patrikImage from '@/app/[lang]/[region]/(website)/about-us/(assets)/patrik.jpeg';
Expand Down Expand Up @@ -72,13 +73,11 @@ const groups: Group[] = [
{ name: 'Mikołaj Demkow', role: 'app-development', image: mikolajImage },
{ name: 'Verena Zaiser', role: 'app-development', image: verenaImage },
{ name: 'András Heé', role: 'software-development', image: andrasImage },
{ name: 'Carlos Badilla', role: 'impact-measurement', image: carlosImage },
{ name: 'Larissa dos Santos Lima', role: 'communications', image: larissaImage },
{ name: 'Carlos Badilla', role: 'fundraising', image: carlosImage },
{ name: 'Larissa dos Santos Lima', role: 'fundraising', image: larissaImage },
{ name: 'Pranav Chatur', role: 'software-development', image: pranavImage },
{ name: 'René Stalder', role: 'software-development', image: reneImage },
{ name: 'Simon Bühler', role: 'communications', image: simonImage },
{ name: 'Sarvesh Dwivedi', role: 'software-development', image: sarveshImage },
{ name: 'Thomas Brenner', role: 'software-development', image: thomasImage },
{ name: 'Matthew Roberts', role: 'communications', image: matthewImage },
],
},
{
Expand All @@ -105,6 +104,9 @@ const groups: Group[] = [
{ name: 'Sarah Mekni', role: 'strategy', image: sarahImage },
{ name: 'Lorenzo Garovi', role: 'strategy', image: lorenzoImage },
{ name: 'Anna-Lina Müller', role: 'strategy', image: annalinaImage },
{ name: 'Simon Bühler', role: 'communications', image: simonImage },
{ name: 'René Stalder', role: 'software-development', image: reneImage },
{ name: 'Sarvesh Dwivedi', role: 'software-development', image: sarveshImage },
],
},
];
Expand Down

0 comments on commit 78563eb

Please sign in to comment.