From 1d660aa8a461c15146d2276efc43bc8cf8c20c41 Mon Sep 17 00:00:00 2001 From: rotorsoft Date: Tue, 4 Mar 2025 07:39:38 -0500 Subject: [PATCH 1/2] fix queries --- libs/model/src/quest/GetQuests.query.ts | 2 +- libs/model/src/user/GetXps.query.ts | 28 ++++++++++--------------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/libs/model/src/quest/GetQuests.query.ts b/libs/model/src/quest/GetQuests.query.ts index 9aa879d64b4..98ffee3e1c3 100644 --- a/libs/model/src/quest/GetQuests.query.ts +++ b/libs/model/src/quest/GetQuests.query.ts @@ -75,7 +75,7 @@ export function GetQuests(): Query { FROM "Quests" as Q LEFT JOIN "QuestActionMetas" QAS on QAS.quest_id = Q.id - ${filterConditions.length > 0 ? `WHERE ${filterConditions.join(' AND ')}` : ''} + ${filterConditions.length > 0 ? `WHERE Q.id > 0 AND ${filterConditions.join(' AND ')}` : ''} GROUP BY Q.id ORDER BY Q.${order} ${direction} LIMIT :limit OFFSET :offset diff --git a/libs/model/src/user/GetXps.query.ts b/libs/model/src/user/GetXps.query.ts index 8163f4e1742..d12018b729c 100644 --- a/libs/model/src/user/GetXps.query.ts +++ b/libs/model/src/user/GetXps.query.ts @@ -30,23 +30,17 @@ export function GetXps(): Query { as: 'quest_action_meta', required: true, where: event_name ? { event_name } : {}, - include: community_id - ? [ - { - model: models.Quest, - required: true, - attributes: ['id', 'name'], - where: { community_id, ...(quest_id && { id: quest_id }) }, - }, - ] - : [ - { - model: models.Quest, - required: true, - attributes: ['id', 'name'], - ...(quest_id && { where: { id: quest_id } }), - }, - ], + include: [ + { + model: models.Quest, + required: true, + attributes: ['id', 'name'], + where: { + ...(community_id && { community_id }), + ...(quest_id ? { id: quest_id } : { id: { [Op.gt]: 0 } }), + }, + }, + ], }, ]; From ab852a010c02742ecd3e0bb16c3daf9d68ffcdbd Mon Sep 17 00:00:00 2001 From: rotorsoft Date: Tue, 4 Mar 2025 07:51:37 -0500 Subject: [PATCH 2/2] fix test --- libs/model/test/user/user-lifecycle.spec.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/libs/model/test/user/user-lifecycle.spec.ts b/libs/model/test/user/user-lifecycle.spec.ts index 9837ba54596..89db2010d05 100644 --- a/libs/model/test/user/user-lifecycle.spec.ts +++ b/libs/model/test/user/user-lifecycle.spec.ts @@ -472,12 +472,12 @@ describe('User lifecycle', () => { }); it('should query previous xp logs', async () => { - // 9 events + // 8 events (skipping negative system quest id) const xps1 = await query(GetXps(), { actor: admin, payload: {}, }); - expect(xps1!.length).to.equal(9); + expect(xps1!.length).to.equal(8); xps1?.forEach((xp) => { expect(xp.quest_id).to.be.a('number'); expect(xp.quest_action_meta_id).to.be.a('number'); @@ -493,12 +493,12 @@ describe('User lifecycle', () => { expect(xp.event_name).to.equal('CommentUpvoted'); }); - // 5 events after first CommentUpvoted + // 4 events after first CommentUpvoted const xps3 = await query(GetXps(), { actor: admin, payload: { from: xps2!.at(-1)!.created_at }, }); - expect(xps3!.length).to.equal(5); + expect(xps3!.length).to.equal(4); // 4 events for member (ThreadCreated and CommentUpvoted) const xps4 = await query(GetXps(), { @@ -511,16 +511,14 @@ describe('User lifecycle', () => { .be.true; }); - // 2 events for new actor (joining and sign up flow completed) + // 1 event for new actor (joining) const xps5 = await query(GetXps(), { actor: admin, payload: { user_id: new_actor.user.id }, }); - expect(xps5!.length).to.equal(2); + expect(xps5!.length).to.equal(1); xps5?.forEach((xp) => { - expect( - ['SignUpFlowCompleted', 'CommunityJoined'].includes(xp.event_name), - ).to.be.true; + expect(['CommunityJoined'].includes(xp.event_name)).to.be.true; }); // 3 CommentCreated events for admin