From b9ce221757bac70c7010bfaa331fca3109ed16cc Mon Sep 17 00:00:00 2001 From: Nikhil Dange Date: Mon, 1 Apr 2024 22:44:44 -0700 Subject: [PATCH 1/3] temporary fixing query --- repositories/FeedbackRepository.ts | 16 ++++++++++++++-- services/FeedbackService.ts | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/repositories/FeedbackRepository.ts b/repositories/FeedbackRepository.ts index fbaa8fe8..2e3d5bc1 100644 --- a/repositories/FeedbackRepository.ts +++ b/repositories/FeedbackRepository.ts @@ -15,8 +15,20 @@ export class FeedbackRepository extends BaseRepository { return this.getBaseFindQuery({}).where({ uuid }).getOne(); } - public async getAllFeedbackForUser(user: UserModel): Promise { - return this.getBaseFindQuery({}).where({ user }).getMany(); + // temporary fix for getting feedback for a user for an event + public async getStandardUserFeedback(user: UserModel, options: FeedbackSearchOptions): Promise { + let query = this.getBaseFindQuery(options); + query = query.andWhere('feedback.user = :user', { user: user.uuid }); + + if (options.event) { + query = query.andWhere('feedback.event = :event', { event: options.event }); + } + + return query.getMany(); + } + + public async getAllFeedbackForUser(user: UserModel, options: FeedbackSearchOptions): Promise { + return this.getBaseFindQuery(options).where({ user }).getMany(); } public async upsertFeedback(feedback: FeedbackModel, diff --git a/services/FeedbackService.ts b/services/FeedbackService.ts index 12e23654..f8d5f059 100644 --- a/services/FeedbackService.ts +++ b/services/FeedbackService.ts @@ -25,7 +25,7 @@ export default class FeedbackService { .map((fb) => fb.getPublicFeedback()); } - const userFeedback = await feedbackRepository.getAllFeedbackForUser(user); + const userFeedback = await feedbackRepository.getStandardUserFeedback(user, options); return userFeedback.map((fb) => fb.getPublicFeedback()); }); } From 10c8460a9c2a9cd605b2aef280a34f87378fc540 Mon Sep 17 00:00:00 2001 From: Nikhil Dange Date: Mon, 1 Apr 2024 22:59:58 -0700 Subject: [PATCH 2/3] fixed query --- repositories/FeedbackRepository.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/repositories/FeedbackRepository.ts b/repositories/FeedbackRepository.ts index 2e3d5bc1..32490e65 100644 --- a/repositories/FeedbackRepository.ts +++ b/repositories/FeedbackRepository.ts @@ -15,15 +15,8 @@ export class FeedbackRepository extends BaseRepository { return this.getBaseFindQuery({}).where({ uuid }).getOne(); } - // temporary fix for getting feedback for a user for an event public async getStandardUserFeedback(user: UserModel, options: FeedbackSearchOptions): Promise { let query = this.getBaseFindQuery(options); - query = query.andWhere('feedback.user = :user', { user: user.uuid }); - - if (options.event) { - query = query.andWhere('feedback.event = :event', { event: options.event }); - } - return query.getMany(); } From cbe9de19ee31e7d3d9ca4ff12ae7658dbafcceab Mon Sep 17 00:00:00 2001 From: Nikhil Dange Date: Mon, 1 Apr 2024 23:18:09 -0700 Subject: [PATCH 3/3] better query --- repositories/FeedbackRepository.ts | 3 +++ tests/feedback.test.ts | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/repositories/FeedbackRepository.ts b/repositories/FeedbackRepository.ts index 32490e65..aa6250d4 100644 --- a/repositories/FeedbackRepository.ts +++ b/repositories/FeedbackRepository.ts @@ -15,8 +15,11 @@ export class FeedbackRepository extends BaseRepository { return this.getBaseFindQuery({}).where({ uuid }).getOne(); } + // temporary fix for getting feedback for a user for an event public async getStandardUserFeedback(user: UserModel, options: FeedbackSearchOptions): Promise { let query = this.getBaseFindQuery(options); + query = query.andWhere('feedback.user = :user', { user: user.uuid }); + return query.getMany(); } diff --git a/tests/feedback.test.ts b/tests/feedback.test.ts index 2c826eed..f2516307 100644 --- a/tests/feedback.test.ts +++ b/tests/feedback.test.ts @@ -164,7 +164,7 @@ describe('feedback submission', () => { const feedbackController = ControllerFactory.feedback(conn); await feedbackController.submitFeedback(buildFeedbackRequest(feedback1), member1); await feedbackController.submitFeedback(buildFeedbackRequest(feedback2), member2); - const user1Feedback = await feedbackController.getFeedback({}, member1); + const user1Feedback = await feedbackController.getFeedback({ user: member1.uuid }, member1); expect(user1Feedback.feedback).toHaveLength(1);