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

hicommonwealth / commonwealth / 13771462677

10 Mar 2025 05:56PM UTC coverage: 45.189% (-0.06%) from 45.252%
13771462677

push

github

web-flow
Merge pull request #11344 from hicommonwealth/tim/fix-getTransactions-rollbar

Fix `GetTransactions`

1313 of 3225 branches covered (40.71%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

11 existing lines in 2 files now uncovered.

2519 of 5255 relevant lines covered (47.94%)

38.41 hits per line

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

82.76
/libs/model/src/quest/UpdateQuest.command.ts
1
import { Command } from '@hicommonwealth/core';
2
import * as schemas from '@hicommonwealth/schemas';
3
import { models } from '../database';
4
import { isSuperAdmin } from '../middleware';
5
import {
6
  mustBeValidDateRange,
7
  mustExist,
8
  mustNotBeStarted,
9
  mustNotExist,
10
} from '../middleware/guards';
11
import { getDelta } from '../utils';
12

13
export function UpdateQuest(): Command<typeof schemas.UpdateQuest> {
14
  return {
15
    ...schemas.UpdateQuest,
16
    auth: [isSuperAdmin],
11✔
17
    secure: true,
18
    body: async ({ payload }) => {
19
      const {
20
        quest_id,
21
        name,
22
        description,
23
        community_id,
24
        image_url,
25
        start_date,
26
        end_date,
27
        max_xp_to_end,
28
        action_metas,
29
      } = payload;
30

31
      const quest = await models.Quest.findOne({ where: { id: quest_id } });
11✔
32
      mustExist(`Quest with id "${quest_id}`, quest);
33

11✔
34
      if (name) {
11✔
35
        const existingName = await models.Quest.findOne({
36
          where: { community_id: community_id ?? null, name },
11✔
37
          attributes: ['id'],
1✔
38
        });
1!
39
        mustNotExist(
40
          `Quest named "${name}" in community "${community_id}"`,
41
          existingName,
1✔
42
        );
43
      }
44

45
      mustNotBeStarted(start_date ?? quest.start_date);
46
      mustBeValidDateRange(
47
        start_date ?? quest.start_date,
10✔
48
        end_date ?? quest.end_date,
9✔
49
      );
18✔
50

17✔
51
      if (action_metas) {
52
        const c_id = community_id || quest.community_id;
53
        await Promise.all(
9!
54
          action_metas.map(async (action_meta) => {
9✔
55
            if (action_meta.content_id) {
9✔
56
              // make sure content_id exists
57
              const [content, id] = action_meta.content_id.split(':'); // this has been validated by the schema
17✔
58
              if (content === 'thread') {
59
                const thread = await models.Thread.findOne({
1✔
60
                  where: c_id ? { id: +id, community_id: c_id } : { id: +id },
1!
UNCOV
61
                });
×
62
                mustExist(`Thread with id "${id}"`, thread);
×
63
              } else if (content === 'comment') {
UNCOV
64
                const comment = await models.Comment.findOne({
×
65
                  where: { id: +id },
1!
66
                  include: c_id
1✔
67
                    ? [
68
                        {
1!
69
                          model: models.Thread,
70
                          attributes: ['community_id'],
71
                          required: true,
72
                          where: { community_id: c_id },
73
                        },
74
                      ]
75
                    : [],
76
                });
77
                mustExist(`Comment with id "${id}"`, comment);
78
              }
79
            }
1✔
80
          }),
81
        );
82
      }
83

84
      await models.sequelize.transaction(async (transaction) => {
85
        if (action_metas?.length) {
86
          // clean existing action_metas
8✔
87
          await models.QuestActionMeta.destroy({
8!
88
            where: { quest_id },
89
            transaction,
8✔
90
          });
91
          // create new action_metas
92
          await models.QuestActionMeta.bulkCreate(
93
            action_metas.map((action_meta) => ({
94
              ...action_meta,
8✔
95
              quest_id,
16✔
96
            })),
97
          );
98
        }
99

100
        const delta = getDelta(quest, {
101
          name,
102
          description,
8✔
103
          community_id,
104
          image_url,
105
          start_date,
106
          end_date,
107
          max_xp_to_end,
108
        });
109
        if (Object.keys(delta).length)
110
          await models.Quest.update(delta, {
111
            where: { id: quest_id },
8✔
112
            transaction,
1✔
113
          });
114
      });
115

116
      const updated = await models.Quest.findOne({
117
        where: { id: quest_id },
118
        include: { model: models.QuestActionMeta, as: 'action_metas' },
8✔
119
      });
120
      return updated!.toJSON();
121
    },
122
  };
8✔
123
}
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