Skip to content

Commit

Permalink
Next Release Aug 2024 (#122)
Browse files Browse the repository at this point in the history
* add eslint

* add eslint

* add eslint

* add eslint

* fix eslint errors

* remove lock file

* fix eslint errors

* Change date schema to be compatible with ortto schema

* Fix unit test based on changes

* Fix lint errors

* Fix lint errors

* change main-pipeline

* feat: change GivethNotificationTypes seed

* fix: remove brake line

* change Dockerfile

* change Dockerfile to use yarn

* remove userId from notify reward amount ortto request

* add email to payload for notify reward

* Fix tests for notify reward

* fix: create migration to change givbacks notification

* Change scripts to use ts-node for running migrations

* Add tsconfig-paths module to application

* ensure dataSource initialize before running migrations

* Update packages

* Use the previous version of ts

* Allow ts to resolve json modules

* Run pretest scripts before test migrations

* Make pretest scripts stand alone

* Revert changes on pre-test-scripts.ts

* remove pre-test-scripts from migration commands

* downgrade typeorm version to fix migration execution

* run migrations using scripts

* Upgrade typeorm version again

* add create test database step to the staging-pipeline.yml

* add wait for database step to the staging-pipeline.yml

* change database port in the staging-pipeline.yml

* change database name in the staging-pipeline.yml and remove redundant steps

* change database name in the main-pipeline.yml

* add migration for create Qacc third party

* support Qacc on Ortto

* Add Qacc to microServices

---------

Co-authored-by: Ramin <raminramazanpour@gmail.com>
Co-authored-by: ali ebrahimi <aliebrahimi2079@gmail.com>
Co-authored-by: Reshzera <reoshiro13@gmail.com>
Co-authored-by: Ali Ebrahimi <65724329+ae2079@users.noreply.github.com>
Co-authored-by: Rafael E. Oshiro <46092730+Reshzera@users.noreply.github.com>
Co-authored-by: Amin Latifi <a.latifi.al@gmail.com>
  • Loading branch information
7 people authored Aug 28, 2024
1 parent f6e4fe6 commit 6ae372d
Show file tree
Hide file tree
Showing 61 changed files with 8,378 additions and 18,904 deletions.
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

26 changes: 0 additions & 26 deletions .eslintrc.js

This file was deleted.

16 changes: 10 additions & 6 deletions .github/workflows/main-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: givethio
POSTGRES_DB: notification-center
options: >-
--health-cmd pg_isready
--health-interval 10s
Expand All @@ -43,15 +43,15 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 18.14.0
node-version: 20.14.0
- name: Install dependencies
run: npm ci
run: yarn install
- name: Run linter
run: npm run lint
run: yarn lint
- name: Run migrations
run: npm run db:migrate:run:test
run: yarn db:migrate:run:test
- name: Run tests
run: npm run test
run: yarn test

publish:
needs: test
Expand All @@ -60,6 +60,10 @@ jobs:
steps:
- name: Check out the repo
uses: actions/checkout@v2
- name: Install Yarn
run: npm install -g yarn
- name: Install dependencies
run: yarn install
- name: Build image and push to GitHub Packages
uses: docker/build-push-action@v1
with:
Expand Down
21 changes: 15 additions & 6 deletions .github/workflows/staging-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: givethio
POSTGRES_DB: notification-center
options: >-
--health-cmd pg_isready
--health-interval 10s
Expand All @@ -41,15 +41,17 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 18.14.0
node-version: 20.14.0
- name: Install Yarn
run: npm install -g yarn
- name: Install dependencies
run: npm ci
run: yarn install
- name: Run linter
run: npm run lint
run: yarn lint
- name: Run migrations
run: npm run db:migrate:run:test
run: yarn db:migrate:run:test
- name: Run tests
run: npm run test
run: yarn test

publish:
needs: test
Expand All @@ -58,6 +60,13 @@ jobs:
steps:
- name: Check out the repo
uses: actions/checkout@v2

- name: Install Yarn
run: npm install -g yarn

- name: Install dependencies
run: yarn install

- name: Build image and push to GitHub Packages
uses: docker/build-push-action@v1
with:
Expand Down
6 changes: 3 additions & 3 deletions 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:18.14.0
FROM node:20.14.0

WORKDIR /usr/src/app

Expand All @@ -10,7 +10,7 @@ COPY src ./src
COPY migrations ./migrations
COPY test ./test

RUN npm ci
RUN npm i -g pm2
RUN npm run build #It will run prebuild script for generating swagger spec by tsoa as well
RUN yarn install --frozen-lockfile
RUN yarn build #It will run prebuild script for generating swagger spec by tsoa as well
RUN cp -rv public ./dist
1 change: 1 addition & 0 deletions config/example.env
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ REDIS_PASSWORD=

SEGMENT_API_KEY=FAKE_API_KEY
ORTTO_API_KEY=FAKE_API_KEY
QACC_ORTTO_API_KEY=FAKE_API_KEY
ORTTO_ACTIVITY_API=https://api-us.ortto.app/v1/activities/create

#JWT_AUTHORIZATION_ADAPTER=siweMicroservice
Expand Down
76 changes: 76 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import _import from 'eslint-plugin-import';
import unusedImports from 'eslint-plugin-unused-imports';
import { fixupPluginRules } from '@eslint/compat';
import tsParser from '@typescript-eslint/parser';
import js from '@eslint/js';
import { FlatCompat } from '@eslint/eslintrc';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});

export default [
{
ignores: ['node_modules/*', 'dist/*'],
},
...compat.extends(
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
),
{
plugins: {
import: fixupPluginRules(_import),
'unused-imports': unusedImports,
},

languageOptions: {
parser: tsParser,
},

rules: {
'@typescript-eslint/no-explicit-any': 'off',
'unused-imports/no-unused-imports': 'error',
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
},
],

'prettier/prettier': [
'error',
{
arrowParens: 'avoid',
singleQuote: true,
semi: true,
tabWidth: 2,
useTabs: false,
trailingComma: 'all',
'jsdoc-format': false,
endOfLine: 'auto',
},
],

'import/order': [
'error',
{
groups: [
'builtin',
'external',
['internal', 'parent', 'sibling'],
'index',
'object',
'type',
],
},
],
},
},
];
6 changes: 3 additions & 3 deletions migrations/1678175596807-changeNotificationCopies.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
import { MigrationInterface } from 'typeorm';
import { getNotificationTypeByEventName } from '../src/repositories/notificationTypeRepository';
import { NOTIFICATION_TYPE_NAMES } from '../src/types/general';

Expand All @@ -24,7 +24,7 @@ export class changeNotificationCopies1678175596807
await notificationType.save();
}

public async up(queryRunner: QueryRunner): Promise<void> {
public async up(): Promise<void> {
if (
process.env.NODE_ENV === 'test' ||
process.env.NODE_ENV === 'development'
Expand Down Expand Up @@ -339,7 +339,7 @@ export class changeNotificationCopies1678175596807
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
public async down(): Promise<void> {
//
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
import { MigrationInterface } from 'typeorm';
import { getNotificationTypeByEventName } from '../src/repositories/notificationTypeRepository';
import { NOTIFICATION_TYPE_NAMES } from '../src/types/general';

Expand All @@ -21,7 +21,7 @@ export class changeCancelProjectNotificationCopies1681206838965
await notificationType.save();
}

public async up(queryRunner: QueryRunner): Promise<void> {
public async up(): Promise<void> {
if (
process.env.NODE_ENV === 'test' ||
process.env.NODE_ENV === 'development'
Expand Down Expand Up @@ -84,7 +84,7 @@ export class changeCancelProjectNotificationCopies1681206838965
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
public async down(): Promise<void> {
//
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import {
NotificationType,
SCHEMA_VALIDATORS_NAMES,
} from '../src/entities/notificationType';
import { MICRO_SERVICES, THIRD_PARTY_EMAIL_SERVICES } from '../src/utils/utils';
import { MICRO_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
Expand Down
6 changes: 3 additions & 3 deletions migrations/1692698983844-changeNotificationCopies.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
import { MigrationInterface } from 'typeorm';
import { getNotificationTypeByEventName } from '../src/repositories/notificationTypeRepository';
import { NOTIFICATION_TYPE_NAMES } from '../src/types/general';

Expand All @@ -21,7 +21,7 @@ export class changeNotificationCopies1692698983844
await notificationType.save();
}

public async up(queryRunner: QueryRunner): Promise<void> {
public async up(): Promise<void> {
if (
process.env.NODE_ENV === 'test' ||
process.env.NODE_ENV === 'development'
Expand Down Expand Up @@ -85,7 +85,7 @@ export class changeNotificationCopies1692698983844
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
public async down(): Promise<void> {
//
}
}
44 changes: 23 additions & 21 deletions migrations/1712683625687-addSuperFluidNotificationForAllUsers.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import { MigrationInterface, QueryRunner } from "typeorm"
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(`
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(`
// 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(`
// 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",
Expand All @@ -24,22 +26,22 @@ export class addSuperFluidNotificationForAllUsers1712683625687 implements Migrat
"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(`
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(', ');
// 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 the rows with the fetched notificationTypeIds for all userAddressIds
await queryRunner.query(`
DELETE FROM "notification_setting" WHERE "notificationTypeId" IN (${ids});
`);
}
}
}
Loading

0 comments on commit 6ae372d

Please sign in to comment.