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

hicommonwealth / commonwealth / 12796058250

15 Jan 2025 08:00PM UTC coverage: 48.038% (-0.1%) from 48.168%
12796058250

Pull #10529

github

web-flow
Merge e87fef53f into ae253ad15
Pull Request #10529: Add contest bot webhook

1314 of 3052 branches covered (43.05%)

Branch coverage included in aggregate %.

6 of 36 new or added lines in 6 files covered. (16.67%)

1 existing line in 1 file now uncovered.

2592 of 5079 relevant lines covered (51.03%)

34.48 hits per line

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

89.66
/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: ['profile', 'xp_points'],
20
      });
21

22
      mustExist('User', user);
5✔
23

24
      const addresses = await models.Address.findAll({
5✔
25
        where: { user_id },
26
        include: [
27
          {
28
            model: models.Community,
29
            required: true,
30
            where: { active: true },
31
            attributes: ['id', 'base', 'ss58_prefix'],
32
          },
33
        ],
34
      });
35

36
      const addressIds = [...new Set(addresses.map((a) => a.id!))];
9✔
37
      const communityIds = [...new Set(addresses.map((a) => a.community_id!))];
9✔
38

39
      const totalUpvotes = await models.Reaction.count({
5✔
40
        where: { address_id: { [Op.in]: addressIds } },
41
      });
42

43
      const threads = await models.Thread.findAll({
5✔
44
        where: {
45
          address_id: { [Op.in]: addressIds },
46
          community_id: { [Op.in]: communityIds },
47
        },
48
        include: [{ model: models.Address, as: 'Address' }],
49
      });
50

51
      const comments = await models.Comment.findAll({
5✔
52
        where: { address_id: { [Op.in]: addressIds } },
53
        include: [
54
          { model: models.Address, as: 'Address' },
55
          {
56
            model: models.Thread,
57
            required: true,
58
            attributes: ['community_id'],
59
            where: { community_id: { [Op.in]: communityIds } },
60
          },
61
        ],
62
      });
63

64
      const commentThreadIds = [
5✔
65
        ...new Set(comments.map((c) => c.thread_id, 10)),
6✔
66
      ];
67
      const commentThreads = await models.Thread.findAll({
5✔
68
        where: { id: { [Op.in]: commentThreadIds } },
69
      });
70

71
      const profileTags = await models.ProfileTags.findAll({
5✔
72
        where: { user_id },
73
        include: [{ model: models.Tags }],
74
      });
75

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