• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hicommonwealth / commonwealth / 13114288911

03 Feb 2025 01:12PM UTC coverage: 47.128% (-0.09%) from 47.216%
13114288911

push

github

web-flow
Merge pull request #10776 from hicommonwealth/malik.10732.detailed-view-for-quests

Detailed view for quests

1384 of 3297 branches covered (41.98%)

Branch coverage included in aggregate %.

6 of 15 new or added lines in 2 files covered. (40.0%)

2702 of 5373 relevant lines covered (50.29%)

36.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/libs/model/src/user/GetRandomResourceIds.query.ts
1
import { type Query } from '@hicommonwealth/core';
2
import * as schemas from '@hicommonwealth/schemas';
3
import { QueryTypes } from 'sequelize';
4
import { z } from 'zod';
5
import { models } from '../database';
6

7
export function GetRandomResourceIds(): Query<
8
  typeof schemas.GetRandomResourceIds
9
> {
NEW
10
  return {
×
11
    ...schemas.GetRandomResourceIds,
12
    auth: [],
13
    secure: true,
14
    body: async ({ payload, actor }) => {
NEW
15
      const { exclude_joined_communities, cursor, limit } = payload;
×
16

NEW
17
      const sql = `
×
18
        ${exclude_joined_communities ? 'WITH UserJoinedCommunities AS (SELECT community_id as id FROM "Addresses" where user_id = :user_id)' : ''}
×
19
        SELECT 
20
          C.id as community_id, 
21
          T.id as thread_id, 
22
          COM.id as comment_id,
23
          COUNT(*) OVER() AS total_count
24
        FROM "Communities" C
25
          LEFT JOIN "Threads" T ON T.community_id = C.id
26
          LEFT JOIN "Comments" COM ON T.id = COM.thread_id
27
        WHERE 
28
          C.active IS true 
29
          AND C.lifetime_thread_count > 0
30
          AND T.id IS NOT NULL
31
          AND COM.id IS NOT NULL
32
          AND T.deleted_at IS NULL
33
          AND COM.deleted_at IS NULL
34
          AND T.marked_as_spam_at IS NULL
35
          AND COM.marked_as_spam_at IS NULL
36
          ${exclude_joined_communities ? 'AND C.id NOT IN (SELECT id FROM UserJoinedCommunities)' : ''}
×
37
        ORDER BY random()
38
        LIMIT :limit;
39
      `;
40

NEW
41
      const offset = (cursor - 1) * limit;
×
42

NEW
43
      const randomResourceIds = await models.sequelize.query<
×
44
        z.infer<typeof schemas.RandomResourceIdsView> & {
45
          total_count: number;
46
        }
47
      >(sql, {
48
        replacements: {
49
          limit,
50
          offset,
51
          user_id: actor.user.id,
52
        },
53
        type: QueryTypes.SELECT,
54
      });
55

NEW
56
      const sanitizedRandomResourceIds = randomResourceIds.map((x) => {
×
57
        // eslint-disable-next-line @typescript-eslint/no-unused-vars
NEW
58
        const { total_count, ...rest } = x;
×
NEW
59
        return rest;
×
60
      });
61

NEW
62
      return schemas.buildPaginatedResponse(
×
63
        sanitizedRandomResourceIds,
64
        randomResourceIds?.length
×
65
          ? parseInt(`${randomResourceIds!.at(0)!.total_count}`)
66
          : 0,
67
        { ...payload, offset },
68
      );
69
    },
70
  };
71
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc