-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from Giveth/staging
Superfluid emails
- Loading branch information
Showing
8 changed files
with
288 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
import { NOTIFICATION_CATEGORY_GROUPS } from '../src/entities/notificationSetting'; | ||
import { NOTIFICATION_CATEGORY } from '../src/types/general'; | ||
import { MICRO_SERVICES } from '../src/utils/utils'; | ||
import { | ||
NotificationType, | ||
SCHEMA_VALIDATORS_NAMES, | ||
} from '../src/entities/notificationType'; | ||
|
||
export const superFluidNotificationTypes = [ | ||
{ | ||
name: 'One month left in stream balance', | ||
description: 'Stream balance of underlying token will run out in 1 month', | ||
microService: MICRO_SERVICES.givethio, | ||
category: NOTIFICATION_CATEGORY.GENERAL, | ||
icon: '', | ||
schemaValidator: SCHEMA_VALIDATORS_NAMES.SUPERFLUID, | ||
emailNotifierService: null, | ||
emailNotificationId: null, | ||
pushNotifierService: null, | ||
categoryGroup: NOTIFICATION_CATEGORY_GROUPS.SUPERFLUID, | ||
title: 'One Month Left in Stream Balance', | ||
htmlTemplate: [ | ||
{ | ||
type: 'p', | ||
content: 'Your Stream Balance of ', | ||
}, | ||
{ | ||
type: 'p', | ||
content: '$tokenSymbol', | ||
}, | ||
{ | ||
type: 'p', | ||
content: ' on ', | ||
}, | ||
{ | ||
type: 'p', | ||
content: '$networkName', | ||
}, | ||
{ | ||
type: 'p', | ||
content: ' will run out in 1 month, ', | ||
}, | ||
{ | ||
type: 'a', | ||
content: 'top-up here.', | ||
href: '$recurringDonationTab', // Actual link goes here | ||
}, | ||
], | ||
}, | ||
{ | ||
name: 'One week left in stream balance', | ||
description: 'Stream balance of underlying token will run out in 1 week', | ||
microService: MICRO_SERVICES.givethio, | ||
category: NOTIFICATION_CATEGORY.GENERAL, | ||
icon: '', | ||
schemaValidator: SCHEMA_VALIDATORS_NAMES.SUPERFLUID, | ||
emailNotifierService: null, | ||
emailNotificationId: null, | ||
pushNotifierService: null, | ||
categoryGroup: NOTIFICATION_CATEGORY_GROUPS.SUPERFLUID, | ||
title: 'One Week Left in Stream Balance', | ||
htmlTemplate: [ | ||
{ | ||
type: 'p', | ||
content: 'Your Stream Balance of ', | ||
}, | ||
{ | ||
type: 'p', | ||
content: '$tokenSymbol', | ||
}, | ||
{ | ||
type: 'p', | ||
content: ' on ', | ||
}, | ||
{ | ||
type: 'p', | ||
content: '$networkName', | ||
}, | ||
{ | ||
type: 'p', | ||
content: ' will run out in 1 week, ', | ||
}, | ||
{ | ||
type: 'a', | ||
content: 'top-up here.', | ||
href: '$recurringDonationTab', // Actual link goes here | ||
}, | ||
], | ||
}, | ||
{ | ||
name: 'Stream balance depleted', | ||
description: 'Stream balance in token has run out of funds', | ||
microService: MICRO_SERVICES.givethio, | ||
category: NOTIFICATION_CATEGORY.GENERAL, | ||
icon: '', | ||
schemaValidator: SCHEMA_VALIDATORS_NAMES.SUPERFLUID, | ||
emailNotifierService: null, | ||
emailNotificationId: null, | ||
pushNotifierService: null, | ||
categoryGroup: NOTIFICATION_CATEGORY_GROUPS.SUPERFLUID, | ||
title: 'Stream Balance Depleted', | ||
htmlTemplate: [ | ||
{ | ||
type: 'p', | ||
content: 'Your Stream Balance in ', | ||
}, | ||
{ | ||
type: 'p', | ||
content: '$tokenSymbol', | ||
}, | ||
{ | ||
type: 'p', | ||
content: ' on ', | ||
}, | ||
{ | ||
type: 'p', | ||
content: '$networkName', | ||
}, | ||
{ | ||
type: 'p', | ||
content: | ||
' has run out of funds, subsequently some of your recurring donations have ended. ', | ||
}, | ||
{ | ||
type: 'a', | ||
content: 'Manage your Recurring Donations', | ||
href: '$recurringDonationTab', // Actual link goes here | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
export class addSuperfluidNotifications1711607882826 | ||
implements MigrationInterface | ||
{ | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.manager.save( | ||
NotificationType, | ||
superFluidNotificationTypes, | ||
); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`DELETE FROM notification_type WHERE "categoryGroup" = 'superfluid';`, | ||
); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
migrations/1712683625687-addSuperFluidNotificationForAllUsers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { MigrationInterface, QueryRunner } from "typeorm" | ||
|
||
export class addSuperFluidNotificationForAllUsers1712683625687 implements MigrationInterface { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
// Fetch the notificationTypeIds for the "superfluid" categoryGroup | ||
const notificationTypeIds = await queryRunner.query(` | ||
SELECT "id" FROM "notification_type" WHERE "categoryGroup" = 'superfluid'; | ||
`); | ||
|
||
// Fetch all unique userAddressIds | ||
const userAddressIds = await queryRunner.query(` | ||
SELECT DISTINCT "userAddressId" FROM "notification_setting"; | ||
`); | ||
|
||
// For each userAddressId, insert a new row for each notificationTypeId | ||
for (const { userAddressId } of userAddressIds) { | ||
for (const { id: notificationTypeId } of notificationTypeIds) { | ||
await queryRunner.query(` | ||
INSERT INTO "notification_setting" ( | ||
"allowNotifications", | ||
"allowEmailNotification", | ||
"allowDappPushNotification", | ||
"notificationTypeId", | ||
"userAddressId" | ||
) VALUES (true, true, true, ${notificationTypeId}, ${userAddressId}); | ||
`); | ||
} | ||
} | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
// Fetch the notificationTypeIds for the "superfluid" categoryGroup | ||
const notificationTypeIds = await queryRunner.query(` | ||
SELECT "id" FROM "notification_type" WHERE "categoryGroup" = 'superfluid'; | ||
`); | ||
|
||
// Convert fetched rows to a list of IDs for the IN clause | ||
const ids = notificationTypeIds.map((nt: { id: any; }) => nt.id).join(', '); | ||
|
||
// Delete the rows with the fetched notificationTypeIds for all userAddressIds | ||
await queryRunner.query(` | ||
DELETE FROM "notification_setting" WHERE "notificationTypeId" IN (${ids}); | ||
`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters