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

hicommonwealth / commonwealth / 12913607989

22 Jan 2025 05:21PM UTC coverage: 47.273% (-0.4%) from 47.698%
12913607989

Pull #10529

github

web-flow
Merge 3e0cc764b into 2dceaabc4
Pull Request #10529: Add contest bot webhook

1359 of 3231 branches covered (42.06%)

Branch coverage included in aggregate %.

7 of 61 new or added lines in 6 files covered. (11.48%)

39 existing lines in 10 files now uncovered.

2697 of 5349 relevant lines covered (50.42%)

36.14 hits per line

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

84.85
/libs/model/src/user/GetUserProfile.query.ts
1
import { InvalidInput, type Query } from '@hicommonwealth/core';
2
import * as schemas from '@hicommonwealth/schemas';
3
import { Op } from 'sequelize';
4
import { z } from 'zod';
5
import { models } from '../database';
6
import { mustExist } from '../middleware/guards';
7

8
export function GetUserProfile(): Query<typeof schemas.GetUserProfile> {
9
  return {
5✔
10
    ...schemas.GetUserProfile,
11
    auth: [],
12
    secure: false,
13
    body: async ({ actor, payload }) => {
14
      const user_id = payload.userId ?? actor.user?.id;
5✔
15
      if (!user_id) throw new InvalidInput('Missing user id');
5!
16

17
      const user = await models.User.findOne({
5✔
18
        where: { id: user_id },
19
        attributes: [
20
          'profile',
21
          'referred_by_address',
22
          'referral_count',
23
          'referral_eth_earnings',
24
          'xp_points',
25
        ],
26
      });
27

28
      mustExist('User', user);
5✔
29

30
      const addresses = await models.Address.findAll({
5✔
31
        where: { user_id },
32
        include: [
33
          {
34
            model: models.Community,
35
            required: true,
36
            where: { active: true },
37
            attributes: ['id', 'base', 'ss58_prefix'],
38
          },
39
        ],
40
      });
41

42
      const addressIds = [...new Set(addresses.map((a) => a.id!))];
9✔
43
      const communityIds = [...new Set(addresses.map((a) => a.community_id!))];
9✔
44

45
      const totalUpvotes = await models.Reaction.count({
5✔
46
        where: { address_id: { [Op.in]: addressIds } },
47
      });
48

49
      const threads = await models.Thread.findAll({
5✔
50
        where: {
51
          address_id: { [Op.in]: addressIds },
52
          community_id: { [Op.in]: communityIds },
53
        },
54
        include: [{ model: models.Address, as: 'Address' }],
55
      });
56

57
      const comments = await models.Comment.findAll({
5✔
58
        where: { address_id: { [Op.in]: addressIds } },
59
        include: [
60
          { model: models.Address, as: 'Address' },
61
          {
62
            model: models.Thread,
63
            required: true,
64
            attributes: ['community_id'],
65
            where: { community_id: { [Op.in]: communityIds } },
66
          },
67
        ],
68
      });
69

70
      const commentThreadIds = [
5✔
71
        ...new Set(comments.map((c) => c.thread_id, 10)),
6✔
72
      ];
73
      const commentThreads = await models.Thread.findAll({
5✔
74
        where: { id: { [Op.in]: commentThreadIds } },
75
      });
76

77
      const profileTags = await models.ProfileTags.findAll({
5✔
78
        where: { user_id },
79
        include: [{ model: models.Tags }],
80
      });
81

82
      return {
5✔
83
        userId: user_id!,
84
        profile: user!.profile,
85
        totalUpvotes,
86
        addresses: addresses.map((a) => {
87
          const address = a.toJSON();
9✔
88
          // ensure Community is present in typed response
89
          return { ...address, Community: address.Community! } as z.infer<
9✔
90
            typeof schemas.UserProfileAddressView
91
          >;
92
        }),
93
        threads: threads.map(
94
          (t) => t.toJSON() as z.infer<typeof schemas.ThreadView>,
3✔
95
        ),
96
        comments: comments.map((c) => {
97
          const comment = {
6✔
98
            ...c.toJSON(),
99
            user_id: c.Address!.user_id!,
100
            address: c.Address!.address!,
101
            last_active: c.Address!.last_active!,
102
            Thread: undefined,
103
            search: undefined,
104
            community_id: c.Thread!.community_id,
105
          };
106
          return comment as z.infer<typeof schemas.CommentView>;
6✔
107
        }),
108
        commentThreads: commentThreads.map(
109
          (c) => c.toJSON() as z.infer<typeof schemas.ThreadView>,
3✔
110
        ),
111
        isOwner: actor.user?.id === user_id,
112
        // ensure Tag is present in typed response
UNCOV
113
        tags: profileTags.map((t) => ({ id: t.Tag!.id!, name: t.Tag!.name })),
×
114
        referred_by_address: user!.referred_by_address,
115
        referral_count: user!.referral_count ?? 0,
5!
116
        referral_eth_earnings: user!.referral_eth_earnings ?? 0,
5!
117
        xp_points: user!.xp_points ?? 0,
5!
118
      };
119
    },
120
  };
121
}
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