Skip to content

Commit

Permalink
Merge pull request #373 from chaynHQ/develop
Browse files Browse the repository at this point in the history
Merge Develop onto Main
  • Loading branch information
annarhughes committed Jan 8, 2024
2 parents 5c547dd + 8d1cd1e commit fe2ed58
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 108 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/.ci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Bloom Backend CI Pipeline

on:
push:
branches: [develop, staging, main]
pull_request:
branches: [develop, staging, main]
branches: [develop, main]
push:
branches: [develop]

jobs:
build:
Expand Down
62 changes: 30 additions & 32 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"
name: 'CodeQL'

on:
push:
branches: [ "develop", main, staging ]
branches: [develop, main]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "develop" ]
branches: [develop, main]
schedule:
- cron: '25 5 * * 5'

Expand All @@ -32,41 +31,40 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
language: ['javascript']
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.


# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh
# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
8 changes: 4 additions & 4 deletions .github/workflows/newrelic-release-tracking.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: New Relic Release Tracking

on:
release:
types: [published]
push:
branches: [main]

jobs:
Expand All @@ -11,13 +11,13 @@ jobs:
steps:
# This step builds a var with the release tag value to use later
- name: Set Release Version from Tag
run: echo "RELEASE_VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
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/[email protected]
with:
apiKey: ${{ secrets.NEW_RELIC_API_KEY }}
region: 'EU'
guid: ${{ secrets.NEW_RELIC_DEPLOYMENT_ENTITY_GUID }}
version: '${{ env.RELEASE_VERSION }}'
version: '${{ env.COMMIT_REF }}'
user: '${{ github.actor }}'
4 changes: 4 additions & 0 deletions src/webhooks/dto/story.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ export class StoryDto {
@IsOptional()
@IsNumber()
space_id?: number;

@IsOptional()
@IsNumber()
full_slug?: string;
}
2 changes: 1 addition & 1 deletion src/webhooks/webhooks.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ describe('WebhooksService', () => {
expect.assertions(1);

const body = {
action: STORYBLOK_STORY_STATUS_ENUM.DELETED,
action: STORYBLOK_STORY_STATUS_ENUM.PUBLISHED,
story_id: mockSession.storyblokId,
text: '',
};
Expand Down
167 changes: 99 additions & 68 deletions src/webhooks/webhooks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ import { PartnerAccessEntity } from '../entities/partner-access.entity';
import { PartnerAccessRepository } from '../partner-access/partner-access.repository';
import { SessionRepository } from '../session/session.repository';
import { UserRepository } from '../user/user.repository';
import { CAMPAIGN_TYPE, SIMPLYBOOK_ACTION_ENUM, storyblokToken } from '../utils/constants';
import {
CAMPAIGN_TYPE,
SIMPLYBOOK_ACTION_ENUM,
STORYBLOK_STORY_STATUS_ENUM,
storyblokToken,
} from '../utils/constants';
import { StoryDto } from './dto/story.dto';
import { EmailCampaignRepository } from './email-campaign/email-campaign.repository';
import { TherapySessionRepository } from './therapy-session.repository';
Expand Down Expand Up @@ -457,86 +462,112 @@ export class WebhooksService {
const action = data.action;
const story_id = data.story_id;

let story;
if (action === STORYBLOK_STORY_STATUS_ENUM.PUBLISHED) {
let story;

const Storyblok = new StoryblokClient({
accessToken: storyblokToken,
cache: {
clear: 'auto',
type: 'memory',
},
});
const Storyblok = new StoryblokClient({
accessToken: storyblokToken,
cache: {
clear: 'auto',
type: 'memory',
},
});

try {
const {
data: { story: storyblokData },
} = await Storyblok.get(`cdn/stories/${story_id}`);
story = storyblokData;
} catch (error) {
throw new HttpException(error, HttpStatus.NOT_FOUND);
}
try {
const {
data: { story: storyblokData },
} = await Storyblok.get(`cdn/stories/${story_id}`);
story = storyblokData;
} catch (error) {
throw new HttpException(error, HttpStatus.NOT_FOUND);
}

if (!story) {
throw new HttpException('STORY NOT FOUND', HttpStatus.NOT_FOUND);
}
if (!story) {
throw new HttpException('STORY NOT FOUND', HttpStatus.NOT_FOUND);
}

const storyData = {
name: story.name,
slug: story.full_slug,
status: action,
storyblokId: Number(story.id),
storyblokUuid: story.uuid,
};
try {
if (story.content?.component === 'Course') {
let course = await this.courseRepository.findOne({
storyblokId: story.id,
});
const storyData = {
name: story.name,
slug: story.full_slug,
status: action,
storyblokId: story_id,
storyblokUuid: story.uuid,
};
try {
if (story.content?.component === 'Course') {
let course = await this.courseRepository.findOne({
storyblokId: story_id,
});

if (!!course) {
course.status = action;
course.slug = story.full_slug;
} else {
course = this.courseRepository.create(storyData);
}
course.name = story.content?.name;
course = await this.courseRepository.save(course);
if (!!course) {
course.status = action;
course.slug = story.full_slug;
} else {
course = this.courseRepository.create(storyData);
}
course.name = story.content?.name;
course = await this.courseRepository.save(course);

await this.coursePartnerService.updateCoursePartners(
story.content?.included_for_partners,
course.id,
);
return course;
} else if (
story.content?.component === 'Session' ||
story.content?.component === 'session_iba'
) {
const course = await this.courseRepository.findOne({
storyblokUuid: story.content.course,
});
await this.coursePartnerService.updateCoursePartners(
story.content?.included_for_partners,
course.id,
);
return course;
} else if (
story.content?.component === 'Session' ||
story.content?.component === 'session_iba'
) {
const course = await this.courseRepository.findOne({
storyblokUuid: story.content.course,
});

if (!course.id) {
throw new HttpException('COURSE NOT FOUND', HttpStatus.NOT_FOUND);
}

if (!course.id) {
throw new HttpException('COURSE NOT FOUND', HttpStatus.NOT_FOUND);
const session = await this.sessionRepository.findOne({
storyblokId: story_id,
});

const newSession = !!session
? {
...session,
status: action,
slug: story.full_slug,
name: story.name,
course: course,
courseId: course.id,
}
: this.sessionRepository.create({ ...storyData, ...{ courseId: course.id } });
return await this.sessionRepository.save(newSession);
}
} catch (error) {
throw error;
}
} else if (
action === STORYBLOK_STORY_STATUS_ENUM.UNPUBLISHED ||
action === STORYBLOK_STORY_STATUS_ENUM.DELETED
) {
// Story was unpublished or deleted so cant be fetched to check story type (Course or Session)
// Try to find course with matching story_id first
const course = await this.courseRepository.findOne({
storyblokId: story_id,
});

if (!!course) {
course.status = action;
return await this.courseRepository.save(course);
} else if (!course) {
// No course found, try finding session instead
const session = await this.sessionRepository.findOne({
storyblokId: story.id,
storyblokId: story_id,
});

const newSession = !!session
? {
...session,
status: action,
slug: story.full_slug,
name: story.name,
course: course,
courseId: course.id,
}
: this.sessionRepository.create({ ...storyData, ...{ courseId: course.id } });
return await this.sessionRepository.save(newSession);
if (!!session) {
session.status = action;
return await this.sessionRepository.save(session);
}
}
} catch (error) {
throw error;
}
}

Expand Down

0 comments on commit fe2ed58

Please sign in to comment.