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

GEWIS / sudosos-backend / 25753937432

12 May 2026 09:17AM UTC coverage: 88.117% (-1.0%) from 89.089%
25753937432

push

github

web-flow
chore(deps): fix missing dependencies for running docs:dev (#911)

3925 of 4574 branches covered (85.81%)

Branch coverage included in aggregate %.

20093 of 22683 relevant lines covered (88.58%)

1125.83 hits per line

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

92.73
/src/controller/transaction-summary-controller.ts
1
/**
1✔
2
 *  SudoSOS back-end API service.
3
 *  Copyright (C) 2026 Study association GEWIS
4
 *
5
 *  This program is free software: you can redistribute it and/or modify
6
 *  it under the terms of the GNU Affero General Public License as published
7
 *  by the Free Software Foundation, either version 3 of the License, or
8
 *  (at your option) any later version.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU Affero General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU Affero General Public License
16
 *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
 *
18
 *  @license
19
 */
1✔
20

21
/**
1✔
22
 * This is the module page of the transaction summaries.
23
 * Not that this module has been created in very strict time constraints,
24
 * so its implementation is very minimal.
25
 * https://github.com/GEWIS/sudosos-backend/pull/415
26
 *
27
 * @module transaction-summaries
28
 */
1✔
29

30
import { Response } from 'express';
31
import log4js, { Logger } from 'log4js';
32
import BaseController, { BaseControllerOptions } from './base-controller';
33
import Policy from './policy';
34
import { RequestWithToken } from '../middleware/token-middleware';
35
import TransactionSummaryService from '../service/transaction-summary-service';
36
import { ContainerSummaryResponse } from './response/transaction-summary-response';
37

38
export default class TransactionSummaryController extends BaseController {
1✔
39
  private logger: Logger = log4js.getLogger('TransactionSummaryController');
1✔
40

41
  public constructor(options: BaseControllerOptions) {
1✔
42
    super(options);
2✔
43
    this.configureLogger(this.logger);
2✔
44
  }
2✔
45

46
  public getPolicy(): Policy {
1✔
47
    return {
2✔
48
      '/container/:id(\\d+)': {
2✔
49
        GET: {
2✔
50
          policy: async (req) => this.roleManager.can(req.token.roles, 'get', 'all', 'Transaction', ['*']),
2✔
51
          handler: this.getSingleContainerSummary.bind(this),
2✔
52
        },
2✔
53
      },
2✔
54
    };
2✔
55
  }
2✔
56

57
  /**
1✔
58
   * GET /transactions/summary/container/{id}
59
   * @summary Returns a summary of all purchases within a container
60
   * @operationId getSingleContainerSummary
61
   * @tags transactionSummaries - Operations of the transaction summary controller
62
   * @security JWT
63
   * @deprecated - Hotfix for Feestcafé "De BAC" - 70s Disco Edition. Do not use for anything else. https://github.com/GEWIS/sudosos-backend/pull/415
64
   * @param {integer} id.path.required - The ID of the container
65
   * @return {Array<ContainerSummaryResponse>} 200 - The requested summary
66
   * @return {string} 404 - Not found error
67
   * @return {string} 500 - Internal server error
68
   */
1✔
69
  public async getSingleContainerSummary(req: RequestWithToken, res: Response): Promise<void> {
1✔
70
    const { id: rawId } = req.params;
2✔
71
    this.logger.trace('Get single container summary of container', rawId, ', by user', req.token.user);
2✔
72

73
    try {
2✔
74
      const id = Number(rawId);
2✔
75
      const { summaries, totals } = await new TransactionSummaryService().getContainerSummary({ containerId: id });
2✔
76
      if (summaries.length === 0) {
2✔
77
        // This also causes a 404 if the container exists, but no transactions have been made.
1✔
78
        // However, this is a won't fix for now (because time)
1✔
79
        // https://github.com/GEWIS/sudosos-backend/pull/415
1✔
80
        res.status(404).json('Container not found.');
1✔
81
        return;
1✔
82
      }
1✔
83

84
      const records = summaries.map((s) => TransactionSummaryService.toContainerSummaryRecord(s));
1✔
85
      const response: ContainerSummaryResponse = {
1✔
86
        summaries: records,
1✔
87
        totalInclVat: totals.totalInclVat.toObject(),
1✔
88
        amountOfProducts: totals.amountOfProducts,
1✔
89
      };
1✔
90

91
      res.status(200).json(response);
1✔
92
    } catch (e) {
2!
93
      res.status(500).send('Internal server error.');
×
94
      this.logger.error(e);
×
95
    }
×
96
  }
2✔
97
}
1✔
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