Skip to content

Commit

Permalink
Merge pull request #88 from Giveth/staging
Browse files Browse the repository at this point in the history
Release 2024-04-29 Recurring donations improvements
  • Loading branch information
mohammadranjbarz authored Apr 29, 2024
2 parents f9beecd + 1e91c47 commit 2eaff62
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 1 deletion.
51 changes: 51 additions & 0 deletions migrations/1713834025817-addGroupParentSuperFluid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { MigrationInterface, QueryRunner } from "typeorm"
import { NOTIFICATION_CATEGORY } from '../src/types/general';
import { NotificationType } from '../src/entities/notificationType';
import { MICRO_SERVICES } from '../src/utils/utils';
import { NOTIFICATION_CATEGORY_GROUPS } from '../src/entities/notificationSetting';

export const superFluidNotificationTypes = [
{
isGlobal: false,
isGroupParent: true,
showOnSettingPage: true,
webDefaultValue: true,
emailDefaultValue: true,
isEmailEditable: true,
isWebEditable: true,
name: 'Stream balance warnings',
description: 'Notify me when any of my Stream Balances are running low',
microService: MICRO_SERVICES.givethio,
category: NOTIFICATION_CATEGORY.SUPPORTED_PROJECTS,
schemaValidator: null,
emailNotifierService: null,
emailNotificationId: null,
pushNotifierService: null,
categoryGroup: NOTIFICATION_CATEGORY_GROUPS.SUPERFLUID,
title: 'Stream balance warnings',
},
]

export class addGroupParentSuperFluid1713834025817 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';
`)).map((i: any) => i.id);
await queryRunner.query(
`UPDATE notification_type
SET "showOnSettingPage" = false, "emailDefaultValue" = true, "category" = '${NOTIFICATION_CATEGORY.SUPPORTED_PROJECTS}'
WHERE id IN (${notificationTypeIds.join(", ")})`
);
await queryRunner.manager.save(
NotificationType,
superFluidNotificationTypes,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DELETE FROM notification_type WHERE "categoryGroup" = 'superfluid' AND "name" = 'Stream Balance Warnings';`,
);
}
}
40 changes: 40 additions & 0 deletions migrations/1713883053900-addSuperFluidParentToAllUsers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { MigrationInterface, QueryRunner } from "typeorm"

export class addSuperFluidParentToAllUsers1713883053900 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
// Fetch the notificationTypeIds for the "superfluid" parent
const notificationTypeId = (await queryRunner.query(`
SELECT "id" FROM "notification_type" WHERE "categoryGroup" = 'superfluid' AND "isGroupParent" = true;
`)).map((i: any) => i.id)[0];

// Fetch all unique userAddressIds
const userAddressIds = await queryRunner.query(`
SELECT "id" FROM "user_address";
`);

// For each userAddressId, insert a new row
for (const { id } of userAddressIds) {
await queryRunner.query(`
INSERT INTO "notification_setting" (
"allowNotifications",
"allowEmailNotification",
"allowDappPushNotification",
"notificationTypeId",
"userAddressId"
) VALUES (true, true, true, ${notificationTypeId}, ${id});
`);
}
}

public async down(queryRunner: QueryRunner): Promise<void> {
// Fetch the notificationTypeIds for the "superfluid" categoryGroup
const notificationTypeId = await queryRunner.query(`
SELECT "id" FROM "notification_type" WHERE "categoryGroup" = 'superfluid' AND "isGroupParent" = true;
`);
const id = notificationTypeId.map((nt: { id: number; }) => nt.id)[0]
// Delete the rows with the fetched notificationTypeId for all userAddressIds
await queryRunner.query(`
DELETE FROM "notification_setting" WHERE "notificationTypeId" = ${id};
`);
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"prettify": "prettier --write '**/*.ts*'",
"db:migrate:run:local": "NODE_ENV=development npx typeorm-ts-node-esm migration:run -d ./src/dataSource.ts ",
"db:migrate:run:local": "NODE_ENV=development npx typeorm-ts-node-commonjs migration:run -d ./src/dataSource.ts ",
"db:migrate:run:staging": "NODE_ENV=staging npx typeorm-ts-node-esm migration:run -d ./src/dataSource.ts ",
"db:migrate:revert:local": "NODE_ENV=development npx typeorm-ts-node-esm migration:revert -d ./src/dataSource.ts ",
"db:migrate:run:test": "NODE_ENV=test npx typeorm-ts-node-esm migration:run -d ./src/dataSource.ts ",
Expand Down

0 comments on commit 2eaff62

Please sign in to comment.