Skip to content

Commit

Permalink
Merge pull request #586 from chaynHQ/develop
Browse files Browse the repository at this point in the history
Merge Develop onto Main
  • Loading branch information
annarhughes authored Oct 28, 2024
2 parents 8d97ec6 + 636b56c commit 4af82b7
Show file tree
Hide file tree
Showing 27 changed files with 779 additions and 989 deletions.
21 changes: 11 additions & 10 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
### Issue link / number:
### Resolves #enter-issue-number

### What changes did you make?
### What changes did you make and why did you make them?

### Why did you make the changes?
### Did you run tests? Share screenshot of results:

### Did you run tests?
### How did you find us? (GitHub, Google search, social media, etc.):

<!---IMPORTANT NOTE ABOUT RUNNING TESTS: ->
<!---ABOUT RUNNING TESTS :->
- Directions for running tests are in the README.md.
- Tests are not required to pass.
- Run unit tests
- Run integration tests if required for contribution.
- Some tests may require multiple runs before success.
- Some test failures may not be due to your contribution and can be ignored.
- If tests fail without resolution, please let us know here.
- Directions for running tests are in the README.md
- Some test failures may not be due to your contribution and can be ignored. We are always upgrading testing performance.
<!--- PR CHECKLIST: PLEASE REMOVE BEFORE SUBMITTING —>
<!--- PR CHECKLIST: —>
Before submitting, check that you have completed the following tasks:
- [ ] Answered the questions above.
- [ ] Read Chayn's Contributing Guidelines in the CONTRIBUTING.md file.
- [ ] Enabled "Allow edits and access to secrets by maintainers" on this PR.
- [ ] If applicable, include images in the description.
After submitting, please be available for discussion. Thank you!
28 changes: 0 additions & 28 deletions .github/workflows/dependabot-open-issues.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/newrelic-release-tracking.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
run: echo "COMMIT_REF=${{ github.ref_name }}" >> $GITHUB_ENV
# This step creates a new Change Tracking Marker
- name: New Relic Application Deployment Marker
uses: newrelic/deployment-marker-action@v2.5.0
uses: newrelic/deployment-marker-action@v2.5.1
with:
apiKey: ${{ secrets.NEW_RELIC_API_KEY }}
region: 'EU'
Expand Down
125 changes: 43 additions & 82 deletions CONTRIBUTING.md

Large diffs are not rendered by default.

231 changes: 117 additions & 114 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
- .:/app

db:
image: postgres:14-alpine
image: postgres:16
container_name: bloom-local-db
restart: unless-stopped
ports:
Expand Down
34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,56 +30,56 @@
},
"dependencies": {
"@mailchimp/mailchimp_marketing": "^3.0.80",
"@nestjs/axios": "^3.0.2",
"@nestjs/common": "^10.3.10",
"@nestjs/axios": "^3.0.3",
"@nestjs/common": "^10.4.6",
"@nestjs/config": "^3.2.3",
"@nestjs/core": "^10.3.6",
"@nestjs/platform-express": "^10.4.1",
"@nestjs/core": "^10.4.4",
"@nestjs/platform-express": "^10.4.6",
"@nestjs/swagger": "^7.4.0",
"@nestjs/terminus": "^10.2.3",
"@nestjs/typeorm": "^10.0.2",
"axios": "^1.7.4",
"axios": "^1.7.7",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"date-fns": "^3.6.0",
"dotenv": "^16.4.5",
"firebase": "^10.10.0",
"firebase-admin": "^12.2.0",
"lodash": "^4.17.21",
"newrelic": "^11.17.0",
"newrelic": "^12.5.1",
"pg": "^8.11.5",
"pg-connection-string": "^2.6.4",
"reflect-metadata": "^0.2.1",
"rimraf": "^6.0.1",
"rollbar": "^2.26.4",
"rxjs": "^7.8.1",
"storyblok-js-client": "^6.7.1",
"storyblok-js-client": "^6.9.2",
"typeorm": "^0.3.20"
},
"devDependencies": {
"@eslint/js": "^9.8.0",
"@eslint/js": "^9.11.1",
"@golevelup/ts-jest": "^0.5.0",
"@nestjs/cli": "^10.3.2",
"@nestjs/schematics": "^10.1.3",
"@nestjs/testing": "^10.3.10",
"@nestjs/schematics": "^10.1.4",
"@nestjs/testing": "^10.4.1",
"@types/date-fns": "^2.6.0",
"@types/express": "^4.17.21",
"@types/jest": "^29.5.12",
"@types/jest": "^29.5.13",
"@types/lodash": "^4.17.7",
"@types/node": "^20.12.5",
"@types/node": "^22.8.1",
"@types/supertest": "^6.0.2",
"eslint": "^9.0.0",
"eslint": "^9.9.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-prettier": "^5.2.1",
"jest": "^29.7.0",
"prettier": "^3.3.3",
"supertest": "^7.0.0",
"ts-jest": "^29.2.4",
"ts-jest": "^29.2.5",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.4.5",
"typescript-eslint": "^7.17.0"
"typescript": "^5.5.4",
"typescript-eslint": "^8.11.0"
},
"engines": {
"node": "20.x",
Expand Down
14 changes: 5 additions & 9 deletions seed-local-db.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
#!/usr/bin/env bash

#Create Time Stamp
DATE=`date "+%Y%m%d"`

TIMESTAMP=`date "+%Y%m%d-%H%M%S"`

set -e

#Backup Remote database
curl `heroku pg:backups public-url --app bloom-backend-staging` > bloom_$TIMESTAMP.dump
heroku pg:backups:capture --app bloom-backend-staging
heroku pg:backups:download --app bloom-backend-staging

#Load backup into local database
docker exec -i bloom-local-db pg_restore -U postgres -d bloom < bloom_$TIMESTAMP.dump
docker exec -i bloom-local-db pg_restore -U postgres -d bloom < latest.dump

rm latest.dump
5 changes: 1 addition & 4 deletions src/api/crisp/crisp-api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AxiosResponse } from 'axios';
import { Logger } from '../../logger/logger';
import { crispToken, crispWebsiteId } from '../../utils/constants';
import apiCall from '../apiCalls';
import {
Expand All @@ -18,8 +17,6 @@ const headers = {
'-ContentType': 'application/json',
};

const logger = new Logger('UserService');

export const createCrispProfile = async (
newPeopleProfile: CrispProfileBase,
): Promise<AxiosResponse<NewCrispProfileBaseResponse>> => {
Expand Down Expand Up @@ -105,7 +102,7 @@ export const deleteCrispProfile = async (email: string) => {
headers,
});
} catch (error) {
logger.error(`Delete crisp profile API call failed: ${error}`);
throw new Error(`Delete crisp profile API call failed: ${error}`);
}
};

Expand Down
5 changes: 4 additions & 1 deletion src/api/mailchimp/mailchimp-api.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import mailchimp from '@mailchimp/mailchimp_marketing';
import { createHash } from 'crypto';
import { mailchimpApiKey, mailchimpAudienceId, mailchimpServerPrefix } from 'src/utils/constants';
import { Logger } from '../../logger/logger';
import {
ListMember,
ListMemberPartial,
MAILCHIMP_MERGE_FIELD_TYPES,
UpdateListMemberRequest,
} from './mailchimp-api.interfaces';

const logger = new Logger('MailchimpAPI');

mailchimp.setConfig({
apiKey: mailchimpApiKey,
server: mailchimpServerPrefix,
Expand Down Expand Up @@ -107,7 +110,7 @@ export const deleteMailchimpProfile = async (email: string) => {
try {
return await mailchimp.lists.deleteListMember(mailchimpAudienceId, getEmailMD5Hash(email));
} catch (error) {
throw new Error(`Delete mailchimp profile API call failed: ${error}`);
logger.warn(`Delete mailchimp profile API call failed: ${error}`);
}
};

Expand Down
3 changes: 3 additions & 0 deletions src/entities/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export class UserEntity extends BaseBloomEntity {
@Column({ type: 'timestamptz', nullable: true })
lastActiveAt: Date; // set each time user record is fetched

@Column({ type: 'timestamptz', nullable: true })
deletedAt: Date; // set when the deleteUser method is called

@OneToMany(() => PartnerAccessEntity, (partnerAccess) => partnerAccess.user, { cascade: true })
partnerAccess: PartnerAccessEntity[];

Expand Down
14 changes: 14 additions & 0 deletions src/migrations/1722295564731-bloom-backend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class BloomBackend1722295564731 implements MigrationInterface {
name = 'BloomBackend1722295564731'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "user" ADD "deletedAt" TIMESTAMP WITH TIME ZONE`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "user" DROP COLUMN "deletedAt"`);
}

}
1 change: 1 addition & 0 deletions src/partner-admin/partner-admin-auth.guard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { PartnerAdminAuthGuard } from './partner-admin-auth.guard';

const userEntity: UserEntity = {
updatedAt: null,
deletedAt: null,
createdAt: new Date(),
firebaseUid: '123',
id: 'userid',
Expand Down
2 changes: 1 addition & 1 deletion src/partner-admin/super-admin-auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class SuperAdminAuthGuard implements CanActivate {
);
}
try {
const user = await this.userRepository.findOneBy({ firebaseUid: userUid });
const user = await this.userRepository.findOneByOrFail({ firebaseUid: userUid });
request['userEntity'] = user;
return !!user.isSuperAdmin && user.email.indexOf('@chayn.co') !== -1;
} catch (error) {
Expand Down
8 changes: 4 additions & 4 deletions src/session-user/session-user.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Body, Controller, Post, Req, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { Request } from 'express';
import { GetUserDto } from 'src/user/dtos/get-user.dto';
import {UserEntity} from '../entities/user.entity';
import { ControllerDecorator } from 'src/utils/controller.decorator';
import { FirebaseAuthGuard } from '../firebase/firebase-auth.guard';
import { UpdateSessionUserDto } from './dtos/update-session-user.dto';
Expand All @@ -22,7 +22,7 @@ export class SessionUserController {
@UseGuards(FirebaseAuthGuard)
async createSessionUser(@Req() req: Request, @Body() createSessionUserDto: UpdateSessionUserDto) {
return await this.sessionUserService.createSessionUser(
req['user'] as GetUserDto,
req['userEntity'] as UserEntity,
createSessionUserDto,
);
}
Expand All @@ -35,7 +35,7 @@ export class SessionUserController {
@UseGuards(FirebaseAuthGuard)
async complete(@Req() req: Request, @Body() updateSessionUserDto: UpdateSessionUserDto) {
return await this.sessionUserService.setSessionUserCompleted(
req['user'] as GetUserDto,
req['userEntity'] as UserEntity,
updateSessionUserDto,
true,
);
Expand All @@ -50,7 +50,7 @@ export class SessionUserController {
@UseGuards(FirebaseAuthGuard)
async incomplete(@Req() req: Request, @Body() updateSessionUserDto: UpdateSessionUserDto) {
return await this.sessionUserService.setSessionUserCompleted(
req['user'] as GetUserDto,
req['userEntity'] as UserEntity,
updateSessionUserDto,
false,
);
Expand Down
5 changes: 2 additions & 3 deletions src/session-user/session-user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { CourseEntity } from '../entities/course.entity';
import { SessionUserEntity } from '../entities/session-user.entity';
import { Logger } from '../logger/logger';
import { SessionService } from '../session/session.service';
import { GetUserDto } from '../user/dtos/get-user.dto';
import { STORYBLOK_STORY_STATUS_ENUM } from '../utils/constants';
import { formatCourseUserObject, formatCourseUserObjects } from '../utils/serialize';
import { SessionUserDto } from './dtos/session-user.dto';
Expand Down Expand Up @@ -86,7 +85,7 @@ export class SessionUserService {
});
}

public async createSessionUser({ user }: GetUserDto, { storyblokId }: UpdateSessionUserDto) {
public async createSessionUser(user: UserEntity, { storyblokId }: UpdateSessionUserDto) {
const session = await this.sessionService.getSessionByStoryblokId(storyblokId);

if (!session) {
Expand Down Expand Up @@ -132,7 +131,7 @@ export class SessionUserService {
}

public async setSessionUserCompleted(
{ user }: GetUserDto,
user : UserEntity,
{ storyblokId }: UpdateSessionUserDto,
completed: boolean,
) {
Expand Down
39 changes: 39 additions & 0 deletions src/subscription-user/dto/get-subscription-user.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { ApiProperty } from '@nestjs/swagger';
import { Expose } from 'class-transformer';
import { IsDefined, IsNotEmpty, IsOptional, IsString } from 'class-validator';

@Expose()
export class GetSubscriptionUserDto {
@ApiProperty()
@IsString()
@IsDefined()
@IsNotEmpty()
id: string;

@ApiProperty()
@IsString()
@IsDefined()
@IsNotEmpty()
subscriptionId: string;

@ApiProperty()
@IsString()
@IsDefined()
@IsNotEmpty()
@Expose()
subscriptionName: string;

@ApiProperty()
@IsString()
@IsDefined()
@IsNotEmpty()
subscriptionInfo: string;

@ApiProperty()
@IsDefined()
createdAt: Date;

@ApiProperty()
@IsOptional()
cancelledAt: Date | null;
}
Loading

0 comments on commit 4af82b7

Please sign in to comment.