From f969d7d6e112ccb743693fda6ee52cad7137f48f Mon Sep 17 00:00:00 2001 From: Anna Hughes Date: Wed, 3 Jul 2024 17:27:22 +0100 Subject: [PATCH 1/3] fix: service profiles therapy data (#507) --- src/utils/serviceUserProfiles.ts | 4 +++- src/webhooks/webhooks.service.ts | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/utils/serviceUserProfiles.ts b/src/utils/serviceUserProfiles.ts index 805847dc..86fcb0d2 100644 --- a/src/utils/serviceUserProfiles.ts +++ b/src/utils/serviceUserProfiles.ts @@ -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[]) => { diff --git a/src/webhooks/webhooks.service.ts b/src/webhooks/webhooks.service.ts index 84bd74e8..62f7f925 100644 --- a/src/webhooks/webhooks.service.ts +++ b/src/webhooks/webhooks.service.ts @@ -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}`, @@ -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}`; From 789e943ed4b861f224e4af92e03fa4ba0c2063eb Mon Sep 17 00:00:00 2001 From: Conor Kirby <67641390+ckirby19@users.noreply.github.com> Date: Thu, 4 Jul 2024 11:25:44 +0100 Subject: [PATCH 2/3] Added session-feedback entity and migration (#501) --- src/entities/session-feedback.entity.ts | 24 +++++++++++++++++++ src/migrations/1719668310816-bloom-backend.ts | 16 +++++++++++++ src/typeorm.config.ts | 4 ++++ src/utils/constants.ts | 9 +++++++ 4 files changed, 53 insertions(+) create mode 100644 src/entities/session-feedback.entity.ts create mode 100644 src/migrations/1719668310816-bloom-backend.ts diff --git a/src/entities/session-feedback.entity.ts b/src/entities/session-feedback.entity.ts new file mode 100644 index 00000000..af2a0870 --- /dev/null +++ b/src/entities/session-feedback.entity.ts @@ -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; +} diff --git a/src/migrations/1719668310816-bloom-backend.ts b/src/migrations/1719668310816-bloom-backend.ts new file mode 100644 index 00000000..9627e7d0 --- /dev/null +++ b/src/migrations/1719668310816-bloom-backend.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class BloomBackend1719668310816 implements MigrationInterface { + name = 'BloomBackend1719668310816' + + public async up(queryRunner: QueryRunner): Promise { + 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 { + await queryRunner.query(`ALTER TABLE "session_feedback" DROP CONSTRAINT "FK_a0567dbf6bd30cf4bd05b110a17"`); + await queryRunner.query(`DROP TABLE "session_feedback"`); + } + +} diff --git a/src/typeorm.config.ts b/src/typeorm.config.ts index 1c256b31..c1482034 100644 --- a/src/typeorm.config.ts +++ b/src/typeorm.config.ts @@ -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'; @@ -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(); @@ -83,6 +85,7 @@ export const dataSourceOptions = { SubscriptionEntity, SubscriptionUserEntity, TherapySessionEntity, + SessionFeedbackEntity, ], migrations: [ bloomBackend1637704119795, @@ -114,6 +117,7 @@ export const dataSourceOptions = { bloomBackend1706174260018, BloomBackend1718300621138, BloomBackend1718728423454, + BloomBackend1719668310816, ], subscribers: [], ssl: isProduction || isStaging, diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 644cfff5..38071726 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -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', From e37645424c85afcf8f39ab4c3609a078d3b1092d Mon Sep 17 00:00:00 2001 From: Anna Hughes Date: Thu, 4 Jul 2024 15:33:39 +0100 Subject: [PATCH 3/3] fix: user me return object (#511) --- src/user/user.controller.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/user/user.controller.ts b/src/user/user.controller.ts index c8ca69e9..ca531617 100644 --- a/src/user/user.controller.ts +++ b/src/user/user.controller.ts @@ -45,9 +45,9 @@ export class UserController { @Get('/me') @UseGuards(FirebaseAuthGuard) async getUserByFirebaseId(@Req() req: Request): Promise { - 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; } /**