Skip to content

Commit

Permalink
Merge pull request #59 from Giveth/staging
Browse files Browse the repository at this point in the history
Next release
  • Loading branch information
mohammadranjbarz authored May 21, 2023
2 parents 9daf207 + c6f4dc0 commit ad68ca4
Show file tree
Hide file tree
Showing 13 changed files with 438 additions and 116 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI-CD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 16.14.2
node-version: 18.14.0
- name: Install dependencies
run: npm ci
- name: Run linter
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16.16.0
v18.14.0
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#https://hub.docker.com/_/node?tab=tags&page=1
FROM node:16.14.2-alpine3.15
FROM node:18.14.0

WORKDIR /usr/src/app

Expand Down
90 changes: 90 additions & 0 deletions migrations/1681206838965-changeCancelProjectNotificationCopies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
import { getNotificationTypeByEventName } from '../src/repositories/notificationTypeRepository';
import { NOTIFICATION_TYPE_NAMES } from '../src/types/general';

export class changeCancelProjectNotificationCopies1681206838965
implements MigrationInterface
{
private async updateNotificationType(
eventName: string,
data: {
htmlTemplate?: any;
content?: string;
},
) {
const notificationType = await getNotificationTypeByEventName(eventName);
if (!notificationType) {
return;
}
notificationType.htmlTemplate = data.htmlTemplate;
notificationType.content = data.content;
await notificationType.save();
}

public async up(queryRunner: QueryRunner): Promise<void> {
if (
process.env.NODE_ENV === 'test' ||
process.env.NODE_ENV === 'development'
) {
// Running these migrations in test and development environments would make the tests fail
// because the notification types are not created in the test database
// In future we should use raw SQL queries to update the notification types
return;
}
await this.updateNotificationType(
NOTIFICATION_TYPE_NAMES.PROJECT_CANCELLED_OWNER,
{
htmlTemplate: [
{
type: 'p',
content: 'Your project ',
},
{
type: 'a',
content: '$projectTitle',
href: '$projectLink',
},
{
type: 'p',
content:
' has been canceled by an admin. More information can be found in our ',
},
{
type: 'a',
content: 'terms of service',
href: 'https://giveth.io/tos',
},
{
type: 'p',
content: '.',
},
],
content:
'Your project {project name} has been canceled by an admin. More information can be found in our {terms of service}.',
},
);

await this.updateNotificationType(
NOTIFICATION_TYPE_NAMES.PROJECT_CANCELLED_SUPPORTED,
{
htmlTemplate: [
{
type: 'a',
content: '$projectTitle',
href: '$projectLink',
},
{
type: 'p',
content: ' which you supported, has been canceled by an admin.',
},
],
content:
'{project name} which you supported, has been canceled by an admin.',
},
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
//
}
}
161 changes: 161 additions & 0 deletions migrations/1682242459196-seedNotificationTypeForProjectGetNewRank.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
import {
NotificationType,
SCHEMA_VALIDATORS_NAMES,
} from '../src/entities/notificationType';
import { MICRO_SERVICES, THIRD_PARTY_EMAIL_SERVICES } from '../src/utils/utils';
import {
NOTIFICATION_CATEGORY,
NOTIFICATION_TYPE_NAMES,
} from '../src/types/general';
import { NOTIFICATION_CATEGORY_GROUPS } from '../src/entities/notificationSetting';
import { SegmentEvents } from '../src/services/segment/segmentAnalyticsSingleton';

// https://github.com/Giveth/notification-center/issues/6 , https://gist.github.com/MohammadPCh/24434d50bc9ccd9b74905c271ee05482
// icons https://gist.github.com/MohammadPCh/31e2b750dd9aa54edb21dcc6e7332efb
export const GivethNotificationTypes = [
{
name: NOTIFICATION_TYPE_NAMES.PROJECT_HAS_A_NEW_RANK,
description: NOTIFICATION_TYPE_NAMES.PROJECT_HAS_A_NEW_RANK,
microService: MICRO_SERVICES.givethio,
category: NOTIFICATION_CATEGORY.PROJECT_RELATED,
icon: '',
categoryGroup: NOTIFICATION_CATEGORY_GROUPS.PROJECT_NEW_RANK,
schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_HAS_A_NEW_RANK,
emailNotifierService: null,
emailNotificationId: null,
pushNotifierService: null,
title: NOTIFICATION_TYPE_NAMES.PROJECT_HAS_A_NEW_RANK,
htmlTemplate: [
{
type: 'p',
content: 'Your project ',
},
{
type: 'a',
content: '$projectTitle',
href: '$projectLink',
},
{
type: 'p',
content: ' has a new rank.',
},
],
content: 'Your project {project name} has a new rank.',
},
{
name: NOTIFICATION_TYPE_NAMES.PROJECT_HAS_RISEN_IN_THE_RANK,
description: NOTIFICATION_TYPE_NAMES.PROJECT_HAS_RISEN_IN_THE_RANK,
microService: MICRO_SERVICES.givethio,
category: NOTIFICATION_CATEGORY.PROJECT_RELATED,
icon: '',
categoryGroup: NOTIFICATION_CATEGORY_GROUPS.PROJECT_NEW_RANK,
schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_HAS_RISEN_IN_THE_RANK,
emailNotifierService: null,
emailNotificationId: null,
pushNotifierService: null,
title: NOTIFICATION_TYPE_NAMES.PROJECT_HAS_RISEN_IN_THE_RANK,
htmlTemplate: [
{
type: 'p',
content: 'Your project ',
},
{
type: 'a',
content: '$projectTitle',
href: '$projectLink',
},
{
type: 'p',
content: ' has risen in the rank.',
},
],
content: 'Your project {project name} has has risen in the rank.',
},
{
name: NOTIFICATION_TYPE_NAMES.YOUR_PROJECT_GOT_A_RANK,
description: NOTIFICATION_TYPE_NAMES.YOUR_PROJECT_GOT_A_RANK,
microService: MICRO_SERVICES.givethio,
category: NOTIFICATION_CATEGORY.PROJECT_RELATED,
icon: '',
categoryGroup: NOTIFICATION_CATEGORY_GROUPS.PROJECT_NEW_RANK,
schemaValidator: SCHEMA_VALIDATORS_NAMES.YOUR_PROJECT_GOT_A_RANK,
emailNotifierService: null,
emailNotificationId: null,
pushNotifierService: null,
title: NOTIFICATION_TYPE_NAMES.YOUR_PROJECT_GOT_A_RANK,
htmlTemplate: [
{
type: 'p',
content: 'Your project ',
},
{
type: 'a',
content: '$projectTitle',
href: '$projectLink',
},
{
type: 'p',
content: ' got a rank.',
},
],
content: 'Your project {project name} got a rank.',
},

// This just for grouping and showing on setting page
{
name: 'New Rank',
title: 'New Rank',
description: 'Notify me when my project has a new rank.',
showOnSettingPage: true,
emailDefaultValue: false,
webDefaultValue: true,
isEmailEditable: false,
categoryGroup: NOTIFICATION_CATEGORY_GROUPS.PROJECT_NEW_RANK,
isGroupParent: true,
microService: MICRO_SERVICES.givethio,
category: NOTIFICATION_CATEGORY.PROJECT_RELATED,
},
];

export class seedNotificationTypeForProjectGetNewRank1682242459196
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
// Giveth IO Notifications
await queryRunner.manager.save(NotificationType, GivethNotificationTypes);

// Fetch the notificationType id for 'New Rank'
const result = await queryRunner.query(
`SELECT id FROM "notification_type" WHERE "categoryGroup" = 'projectNewRank';`,
);
for (const row of result) {
await queryRunner.query(`
INSERT INTO "notification_setting" (
"allowNotifications",
"allowEmailNotification",
"allowDappPushNotification",
"notificationTypeId",
"userAddressId",
"createdAt",
"updatedAt"
)
SELECT
true, -- For these notificationTypes, allowNotifications is true
false, -- For these notificationTypes, allowNotifications is true
true, -- For these notificationTypes, allowNotifications is true
${row.id}, -- New Rank notificationType id
"user_address"."id", -- UserAddress id
NOW(), -- Current timestamp for createdAt
NOW() -- Current timestamp for updatedAt
FROM user_address;
`);
}
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DELETE FROM notification_type WHERE "categoryGroup" = 'projectNewRank';`,
);
}
}
Loading

0 comments on commit ad68ca4

Please sign in to comment.