Skip to content

Commit

Permalink
Merge pull request #508 from chaynHQ/develop
Browse files Browse the repository at this point in the history
Merge Develop onto Main
  • Loading branch information
annarhughes authored Jul 4, 2024
2 parents 0224744 + e376454 commit f32b31e
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 8 deletions.
24 changes: 24 additions & 0 deletions src/entities/session-feedback.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Column, Entity, JoinTable, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
import { FEEDBACK_TAGS_ENUM } from '../utils/constants';
import { BaseBloomEntity } from './base.entity';
import { SessionEntity } from './session.entity';

@Entity({ name: 'session_feedback' })
export class SessionFeedbackEntity extends BaseBloomEntity {
@PrimaryGeneratedColumn('uuid', { name: 'sessionFeedbackId' })
sessionFeedbackId: string;

@Column()
sessionId: string;
@ManyToOne(() => SessionEntity, (sessionEntity) => sessionEntity.sessionUser, {
onDelete: 'CASCADE',
})
@JoinTable({ name: 'session', joinColumn: { name: 'sessionId' } })
session: SessionEntity;

@Column()
feedbackTags: FEEDBACK_TAGS_ENUM;

@Column()
feedbackDescription: string;
}
16 changes: 16 additions & 0 deletions src/migrations/1719668310816-bloom-backend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class BloomBackend1719668310816 implements MigrationInterface {
name = 'BloomBackend1719668310816'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE "session_feedback" ("createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "sessionFeedbackId" uuid NOT NULL DEFAULT uuid_generate_v4(), "sessionId" uuid NOT NULL, "feedbackTags" character varying NOT NULL, "feedbackDescription" character varying NOT NULL, CONSTRAINT "PK_fa9bf9afa42e7a30230cf243090" PRIMARY KEY ("sessionFeedbackId"))`);
await queryRunner.query(`ALTER TABLE "session_feedback" ADD CONSTRAINT "FK_a0567dbf6bd30cf4bd05b110a17" FOREIGN KEY ("sessionId") REFERENCES "session"("sessionId") ON DELETE CASCADE ON UPDATE NO ACTION`);
}

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

}
4 changes: 4 additions & 0 deletions src/typeorm.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { PartnerAccessEntity } from './entities/partner-access.entity';
import { PartnerAdminEntity } from './entities/partner-admin.entity';
import { PartnerFeatureEntity } from './entities/partner-feature.entity';
import { PartnerEntity } from './entities/partner.entity';
import { SessionFeedbackEntity } from './entities/session-feedback.entity';
import { SessionUserEntity } from './entities/session-user.entity';
import { SessionEntity } from './entities/session.entity';
import { SubscriptionUserEntity } from './entities/subscription-user.entity';
Expand Down Expand Up @@ -46,6 +47,7 @@ import { bloomBackend1698136145516 } from './migrations/1698136145516-bloom-back
import { bloomBackend1706174260018 } from './migrations/1706174260018-bloom-backend';
import { BloomBackend1718300621138 } from './migrations/1718300621138-bloom-backend';
import { BloomBackend1718728423454 } from './migrations/1718728423454-bloom-backend';
import { BloomBackend1719668310816 } from './migrations/1719668310816-bloom-backend';

config();
const configService = new ConfigService();
Expand Down Expand Up @@ -83,6 +85,7 @@ export const dataSourceOptions = {
SubscriptionEntity,
SubscriptionUserEntity,
TherapySessionEntity,
SessionFeedbackEntity,
],
migrations: [
bloomBackend1637704119795,
Expand Down Expand Up @@ -114,6 +117,7 @@ export const dataSourceOptions = {
bloomBackend1706174260018,
BloomBackend1718300621138,
BloomBackend1718728423454,
BloomBackend1719668310816,
],
subscribers: [],
ssl: isProduction || isStaging,
Expand Down
6 changes: 3 additions & 3 deletions src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ export class UserController {
@Get('/me')
@UseGuards(FirebaseAuthGuard)
async getUserByFirebaseId(@Req() req: Request): Promise<GetUserDto> {
const user = req['userEntity'];
this.userService.updateUser({ lastActiveAt: new Date() }, user.id);
return user;
const user = req['user'];
this.userService.updateUser({ lastActiveAt: new Date() }, user.user.id);
return user as GetUserDto;
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ export enum SIMPLYBOOK_ACTION_ENUM {
COMPLETED_BOOKING = 'COMPLETED_BOOKING', // currently not in use as no webhook available - could be updated in cron job
}

export enum FEEDBACK_TAGS_ENUM {
RELATABLE = 'relatable',
USEFUL = 'useful',
INSPIRING = 'inspiring',
TOO_LONG = 'too long',
TOO_COMPLICATED = 'too complicated',
NOT_USEFUL = 'not useful',
}

export enum STORYBLOK_STORY_STATUS_ENUM {
PUBLISHED = 'published',
UNPUBLISHED = 'unpublished',
Expand Down
4 changes: 3 additions & 1 deletion src/utils/serviceUserProfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ export const createCompleteMailchimpUserProfile = (user: UserEntity): ListMember
};

export const serializePartnersString = (partnerAccesses: PartnerAccessEntity[]) => {
return partnerAccesses?.map((pa) => pa.partner.name.toLowerCase()).join('; ') || '';
const partnersNames = partnerAccesses?.map((pa) => pa.partner.name.toLowerCase());
const partnersString = partnersNames ? [...new Set(partnersNames)].join('; ') : '';
return partnersString;
};

const serializeCrispPartnerSegments = (partners: PartnerEntity[]) => {
Expand Down
16 changes: 12 additions & 4 deletions src/webhooks/webhooks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class WebhooksService {
},
});

updateServiceUserProfilesTherapy([...partnerAccesses], user.email);
updateServiceUserProfilesTherapy(partnerAccesses, user.email);

this.logger.log(
`Update therapy session webhook function COMPLETED for ${action} - ${user.email} - ${booking_code} - userId ${user_id}`,
Expand Down Expand Up @@ -243,9 +243,17 @@ export class WebhooksService {
await this.partnerAccessRepository.save(partnerAccess);
const therapySession = await this.therapySessionRepository.save(serializedTherapySession);

partnerAccess.therapySession.push(therapySession);
updateServiceUserProfilesTherapy(partnerAccesses, user.email);

const updatedPartnerAccesses = await this.partnerAccessRepository.find({
where: {
userId: user.id,
active: true,
featureTherapy: true,
},
relations: {
therapySession: true,
},
});
updateServiceUserProfilesTherapy(updatedPartnerAccesses, user.email);
return therapySession;
} catch (err) {
const error = `newPartnerAccessTherapy - error saving new therapy session and partner access - email ${user.email} userId ${user.id} - ${err}`;
Expand Down

0 comments on commit f32b31e

Please sign in to comment.