Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/gap 2152 v2 notifications service #59

Merged
merged 71 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
43e862c
Seperated notification service into helpers, grants and saved searches
ryan-tco Oct 13, 2023
2881ac4
Fix existing tests with new user sub
ryan-tco Oct 13, 2023
76e0c30
Made helper methods generic. Added batching to Grant Notifications
ryan-tco Oct 13, 2023
b83abaf
Added batching to saved search notifications
ryan-tco Oct 13, 2023
8324805
Made several functions generic
ryan-tco Oct 13, 2023
2fbd13d
Updated import
ryan-tco Oct 13, 2023
ff79b70
Created v2 NotificationsService
ryan-tco Oct 13, 2023
8268e8b
Added migration. Injected new controller with module.
ryan-tco Oct 16, 2023
b7f36cb
Notification service created.
ryan-tco Oct 16, 2023
13c2e71
Undefined emails
ryan-tco Oct 16, 2023
9022e56
Adds unsubscribe service/controller/module
ryan-tco Oct 18, 2023
e9f38a1
update schema
john-tco Oct 18, 2023
6e8e6ef
fix unsubscribe modules
john-tco Oct 18, 2023
3c70609
Amend buildUnsubscribeUrl, replaces jwt url with unsubscribeReference id
john-tco Oct 18, 2023
6ecd44f
adds fallback
john-tco Oct 18, 2023
59fd8aa
fix schema, types
john-tco Oct 18, 2023
aab94bc
Fixed structure
ryan-tco Oct 19, 2023
064beb6
Fix failing tests
ryan-tco Oct 19, 2023
961c5f2
Fix grant service
ryan-tco Oct 19, 2023
2e0bf62
Added duplication check to unsubscribe table
ryan-tco Oct 19, 2023
113a294
filter out users with no sub
john-tco Oct 19, 2023
016efa9
filter out users with no sub (in saved search)
john-tco Oct 19, 2023
6403a03
Adds delete to unsubscribe
ryan-tco Oct 19, 2023
7fba907
resolve develop conflicts
john-tco Oct 19, 2023
12ace40
backup-infer-commit
john-tco Oct 19, 2023
530806d
resolve develop conflicts
john-tco Oct 19, 2023
c5a9051
rm
john-tco Oct 19, 2023
ca0978e
infer type from unsubscribe ref data, refactor v1 notifications jwt -…
john-tco Oct 19, 2023
c0ff0e0
add migration file
john-tco Oct 19, 2023
19b206d
revert ormconfig changes
john-tco Oct 19, 2023
2011ca4
revert package changes
john-tco Oct 19, 2023
7a372e5
formatting
john-tco Oct 19, 2023
fb8d3c3
rm
john-tco Oct 19, 2023
ef44b21
reset lockfile
john-tco Oct 19, 2023
a981d65
fix tests
john-tco Oct 19, 2023
94cce3d
Added decryption to user-service response and necessary module changes
ryan-tco Oct 20, 2023
a6c6f9c
Fixed unsubsribe url decrypt. Fixed bad parsing of null in repositori…
ryan-tco Oct 20, 2023
e244022
misc saved search fixes, use new env var
john-tco Oct 20, 2023
e0cdab7
amend imports
john-tco Oct 20, 2023
aa28077
rm
john-tco Oct 20, 2023
85e52db
rm
john-tco Oct 20, 2023
b010ff9
refactor query - use default args
john-tco Oct 20, 2023
0df3936
add scheduler tests
john-tco Oct 23, 2023
3587e40
refactor scheduler funcs
john-tco Oct 23, 2023
7a9cd69
bump nv (pipeline fix)
john-tco Oct 23, 2023
d2c3495
update lockfile
john-tco Oct 23, 2023
030d7aa
clear cache && yarn
john-tco Oct 23, 2023
f7e3c30
Added decrypt
ryan-tco Oct 23, 2023
a9a7a3d
Added unsubscribe tests
ryan-tco Oct 24, 2023
6063d74
Change auth header
ryan-tco Oct 24, 2023
8809f80
Notifications service uses binding
ryan-tco Oct 24, 2023
4a570f8
revert nvm changes
john-tco Oct 24, 2023
610c9da
revert and fix cursed bind commit
john-tco Oct 24, 2023
d0fd172
Update src/notifications/v2/notifications.helper.ts
john-tco Oct 24, 2023
f37d429
revert yarn lock
john-tco Oct 24, 2023
1ab853b
use arrow
john-tco Oct 24, 2023
f1ec7a1
REFACTOR delete unsubscribe reference using existing methods
john-tco Oct 24, 2023
55296a2
add spooky ignore_node step so we can set version berry without error
john-tco Oct 24, 2023
da31a73
YARN_IGNORE_NODE=1 before install too
john-tco Oct 24, 2023
e0218b6
yarn 4.0
ryan-tco Oct 24, 2023
39f8e5e
action update
ryan-tco Oct 24, 2023
8f51f8a
Action update
ryan-tco Oct 24, 2023
4129d23
fix tests after refactor
john-tco Oct 24, 2023
4f545fd
merge develop
john-tco Oct 24, 2023
abb58f2
readd yarn cjs
john-tco Oct 24, 2023
9b8d6bf
fix yarnrc
john-tco Oct 24, 2023
c286936
repush lockfile
john-tco Oct 24, 2023
36b4a7d
resolve conflicts
john-tco Oct 25, 2023
53e6427
fix env name
ryan-tco Oct 25, 2023
86dfa8f
logging change
ryan-tco Oct 25, 2023
15041a7
await email.servicesend
ryan-tco Oct 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.14.0
16.14.0
Empty file modified .yarn/releases/yarn-3.6.0.cjs
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
yarnPath: .yarn/releases/yarn-3.6.0.cjs
nodeLinker: node-modules
nodeLinker: node-modules
4 changes: 4 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import { SubscriptionModule } from './subscription/subscription.module';
import { User } from './user/user.entity';
import { UserModule } from './user/user.module';
import { HealthCheckModule } from './healthCheck/healthCheck.module';
import { v2NotificationsModule } from './notifications/v2/v2notifications.module';
import { Unsubscribe } from './notifications/v2/unsubscribe/unsubscribe.entity';
@Module({
imports: [
TypeOrmModule.forRootAsync({
Expand All @@ -35,6 +37,7 @@ import { HealthCheckModule } from './healthCheck/healthCheck.module';
Subscription,
User,
Newsletter,
Unsubscribe,
SavedSearch,
SavedSearchNotification,
],
Expand All @@ -53,6 +56,7 @@ import { HealthCheckModule } from './healthCheck/healthCheck.module';
SchedulerModule,
EmailModule,
NotificationsModule,
v2NotificationsModule,
SearchModule,
ContentfulModule,
EncryptionModule,
Expand Down
4 changes: 0 additions & 4 deletions src/contentful/contentful.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export class ContentfulService {
}

async updateEntries(contentIds: string[], update: KeyValueMap) {
console.log('updating entries');
const entries = await this.contentfulManagementClient.entry.getMany({
query: {
'sys.id[in]': contentIds.join(','),
Expand All @@ -64,7 +63,6 @@ export class ContentfulService {
...entry.fields,
...update,
};
console.log(entry);

const updateResponse =
await this.contentfulManagementClient.entry.update(
Expand All @@ -74,14 +72,12 @@ export class ContentfulService {
entry,
);

console.log('entry updated');
await this.contentfulManagementClient.entry.publish(
{
entryId: entry.sys.id,
},
{ sys: updateResponse.sys, fields: {} },
);
console.log('entry published');
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/migration/1697725143044-addUnsubscribeReferenceTable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {MigrationInterface, QueryRunner} from "typeorm";

export class addUnsubscribeReferenceTable1697725143044 implements MigrationInterface {
name = 'addUnsubscribeReferenceTable1697725143044'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE "unsubscribe" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "subscriptionId" character varying, "newsletterId" character varying, "savedSearchId" integer, "userId" integer, CONSTRAINT "PK_994fd32a0285bbf2fd462a8601d" PRIMARY KEY ("id"))`);
await queryRunner.query(`ALTER TABLE "unsubscribe" ADD CONSTRAINT "FK_f051628403f51d0b0e11c1aabf4" FOREIGN KEY ("userId") REFERENCES "gap_user"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "unsubscribe" DROP CONSTRAINT "FK_f051628403f51d0b0e11c1aabf4"`);
await queryRunner.query(`DROP TABLE "unsubscribe"`);
}

}
11 changes: 11 additions & 0 deletions src/newsletter/newsletter.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { NewsletterController } from './newsletter.controller';
import { Newsletter, NewsletterType } from './newsletter.entity';
import { NewsletterService } from './newsletter.service';
import { Response } from 'express';
import { UnsubscribeService } from '../notifications/v2/unsubscribe/unsubscribe.service';
import { Unsubscribe } from '../notifications/v2/unsubscribe/unsubscribe.entity';
import { TypeOrmModule } from '@nestjs/typeorm';

describe('NewsletterController', () => {
let newsletterController: NewsletterController;
Expand Down Expand Up @@ -33,6 +36,12 @@ describe('NewsletterController', () => {
deleteByEmailAddressAndType: mockDeleteByEmailAndType,
},
},
{
provide: UnsubscribeService,
useValue: {
Connection: jest.fn(),
},
},
],
}).compile();

Expand Down Expand Up @@ -189,6 +198,7 @@ describe('NewsletterController', () => {
'[email protected]',
NewsletterType.NEW_GRANTS,
response as Response,
{},
);
expect(mockDeleteByEmailAndType).toBeCalledTimes(1);
expect(mockDeleteByEmailAndType).toBeCalledWith(
Expand All @@ -210,6 +220,7 @@ describe('NewsletterController', () => {
'[email protected]',
NewsletterType.NEW_GRANTS,
response as Response,
{},
);
expect(mockDeleteByEmailAndType).toBeCalledTimes(1);
expect(mockDeleteByEmailAndType).toBeCalledWith(
Expand Down
21 changes: 20 additions & 1 deletion src/newsletter/newsletter.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ import {
Param,
Body,
Res,
Query,
} from '@nestjs/common';
import { NewsletterService } from './newsletter.service';
import { Response } from 'express';
import { NewsletterType } from './newsletter.entity';
import { UnsubscribeService } from '../notifications/v2/unsubscribe/unsubscribe.service';

@Controller('newsletters')
export class NewsletterController {
constructor(private newsletterService: NewsletterService) {}
constructor(
private newsletterService: NewsletterService,
private unsubscribeService: UnsubscribeService,
) {}

@Get()
async findAll() {
Expand Down Expand Up @@ -57,11 +62,25 @@ export class NewsletterController {
@Param('plainTextEmailAddress') plainTextEmailAddress: string,
@Param('newsletterType') type: NewsletterType,
@Res() response: Response,
@Query() query: { unsubscribeReference?: string },
) {
const result = await this.newsletterService.deleteByEmailAddressAndType(
plainTextEmailAddress,
type,
);
if (query?.unsubscribeReference) {
await this.unsubscribeService
.deleteOneById(query.unsubscribeReference)
.catch((error: unknown) => {
console.error(
`Failed to unsubscribe from unsubscribeReference:
${
query.unsubscribeReference
}. error:${JSON.stringify(error)}`,
);
});
}

result == 0 ? response.status(404) : response.status(204);

response.send();
Expand Down
12 changes: 9 additions & 3 deletions src/newsletter/newsletter.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ import { NewsletterController } from './newsletter.controller';
import { Newsletter } from './newsletter.entity';
import { NewsletterService } from './newsletter.service';
import { HashModule } from '../hash/hash.module';
import { UserModule } from 'src/user/user.module';
import { UserModule } from '../user/user.module';
import { Unsubscribe } from '../notifications/v2/unsubscribe/unsubscribe.entity';
import { UnsubscribeService } from '../notifications/v2/unsubscribe/unsubscribe.service';

@Module({
imports: [TypeOrmModule.forFeature([Newsletter]), HashModule, UserModule],
providers: [NewsletterService],
imports: [
TypeOrmModule.forFeature([Newsletter, Unsubscribe]),
HashModule,
UserModule,
],
providers: [NewsletterService, UnsubscribeService],
exports: [NewsletterService],
controllers: [NewsletterController],
})
Expand Down
15 changes: 14 additions & 1 deletion src/notifications/notifications.module.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TypeOrmModule } from '@nestjs/typeorm';
import { Module } from '@nestjs/common';
import { NewsletterModule } from 'src/newsletter/newsletter.module';
import { SavedSearchModule } from 'src/saved_search/saved_search.module';
Expand All @@ -7,18 +8,30 @@ import { EmailModule } from '../email/email.module';
import { GrantModule } from '../grant/grant.module';
import { SubscriptionModule } from '../subscription/subscription.module';
import { NotificationsService } from './notifications.service';
import { NotificationsHelper } from './v2/notifications.helper';
import { Unsubscribe } from './v2/unsubscribe/unsubscribe.entity';
import { UnsubscribeService } from './v2/unsubscribe/unsubscribe.service';
import { UnsubscribeModule } from './v2/unsubscribe/unsubscribe.module';
import { EncryptionServiceV2 } from 'src/encryption/encryptionV2.service';

@Module({
imports: [
TypeOrmModule.forFeature([Unsubscribe]),
SubscriptionModule,
EmailModule,
GrantModule,
ContentfulModule,
NewsletterModule,
SavedSearchModule,
UnsubscribeModule,
SavedSearchNotificationModule,
],
providers: [NotificationsService],
providers: [
NotificationsService,
UnsubscribeService,
NotificationsHelper,
EncryptionServiceV2,
],
exports: [NotificationsService],
})
export class NotificationsModule {}
Loading