@stamhoofd/backend 2.138.2 → 2.140.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +17 -17
- package/src/crons/fake-settlements.test.ts +165 -0
- package/src/crons/fake-settlements.ts +117 -0
- package/src/crons/index.ts +1 -0
- package/src/endpoints/auth/CreateTokenEndpoint.ts +5 -2
- package/src/endpoints/auth/ForgotPasswordEndpoint.test.ts +45 -0
- package/src/endpoints/auth/ForgotPasswordEndpoint.ts +2 -23
- package/src/endpoints/auth/MFA.security.test.ts +76 -1
- package/src/endpoints/auth/MFA.test.ts +187 -3
- package/src/endpoints/auth/VerifyEmailEndpoint.ts +15 -1
- package/src/endpoints/organization/dashboard/balance-items/GetBalanceItemBreakdownEndpoint.test.ts +543 -0
- package/src/endpoints/organization/dashboard/balance-items/GetBalanceItemBreakdownEndpoint.ts +78 -0
- package/src/endpoints/organization/dashboard/balance-items/GetBalanceItemEndpoint.ts +3 -1
- package/src/endpoints/organization/dashboard/payments/GetPaymentBreakdownEndpoint.test.ts +1095 -0
- package/src/endpoints/organization/dashboard/payments/GetPaymentBreakdownEndpoint.ts +111 -0
- package/src/endpoints/organization/dashboard/payments/GetPaymentsEndpoint.ts +3 -79
- package/src/endpoints/organization/dashboard/webshops/PatchWebshopOrdersEndpoint.ts +1 -1
- package/src/endpoints/organization/shared/GetPaymentEndpoint.ts +3 -1
- package/src/endpoints/organization/webshops/PlaceOrderEndpoint.ts +1 -1
- package/src/excel-loaders/balance-item-payments.ts +145 -0
- package/src/excel-loaders/index.ts +1 -0
- package/src/excel-loaders/payments.ts +45 -37
- package/src/helpers/StripeInvoicer.ts +1 -1
- package/src/helpers/TwoFactorHelper.ts +91 -9
- package/src/helpers/breakdownRelations.ts +48 -0
- package/src/helpers/getNextPageRequest.ts +24 -0
- package/src/helpers/streamForBreakdown.test.ts +107 -0
- package/src/helpers/streamForBreakdown.ts +104 -0
- package/src/services/DocumentRenderService.test.ts +72 -1
- package/src/services/PasswordForgotService.ts +31 -1
- package/src/services/PaymentService.ts +9 -1
- package/src/services/SSOService.ts +14 -1
- package/src/sql-filters/balance-item-payments-root.ts +48 -0
- package/src/sql-filters/balance-items.ts +55 -0
- package/src/sql-filters/orders.ts +6 -2
- package/src/sql-filters/payment-settlement.test.ts +68 -0
- package/src/sql-filters/payment-settlement.ts +43 -0
- package/src/sql-filters/payments.ts +93 -31
- package/src/sql-sorters/balance-item-payments.ts +32 -0
- package/tests/filters/orders.test.ts +635 -0
- package/tests/helpers/ExportSlice.ts +71 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
|
|
2
|
+
import type { Organization, User } from '@stamhoofd/models';
|
|
3
|
+
import { Token } from '@stamhoofd/models';
|
|
4
|
+
import type { StamhoofdFilter } from '@stamhoofd/structures';
|
|
5
|
+
import { ExcelExportType, LimitedFilteredRequest, SortItemDirection } from '@stamhoofd/structures';
|
|
6
|
+
import { ExportToExcelEndpoint } from '../../src/endpoints/global/files/ExportToExcelEndpoint.js';
|
|
7
|
+
import { Context } from '../../src/helpers/Context.js';
|
|
8
|
+
import { testServer } from './TestServer.js';
|
|
9
|
+
|
|
10
|
+
// Registers the balance item payment export, which is what a row that holds a part of its objects is
|
|
11
|
+
// written out with
|
|
12
|
+
import '../../src/excel-loaders/balance-item-payments.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Reads what the balance item payment export of a filter comes down to, from inside a request so it
|
|
16
|
+
* runs in the same scope an export runs in.
|
|
17
|
+
*/
|
|
18
|
+
class ExportSliceEndpoint extends Endpoint<Record<string, never>, undefined, undefined, undefined> {
|
|
19
|
+
result = { count: 0, price: 0 };
|
|
20
|
+
|
|
21
|
+
constructor(private readonly sliceFilter: StamhoofdFilter, private readonly search: string | null) {
|
|
22
|
+
super();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
protected doesMatch(): [true, Record<string, never>] {
|
|
26
|
+
return [true, {}];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async handle() {
|
|
30
|
+
await Context.setOrganizationScope();
|
|
31
|
+
await Context.authenticate();
|
|
32
|
+
|
|
33
|
+
const loader = ExportToExcelEndpoint.loaders.get(ExcelExportType.BalanceItemPayments)!;
|
|
34
|
+
const data = await loader.fetch(new LimitedFilteredRequest({
|
|
35
|
+
filter: this.sliceFilter,
|
|
36
|
+
search: this.search,
|
|
37
|
+
limit: 100,
|
|
38
|
+
sort: [{ key: 'id', order: SortItemDirection.ASC }],
|
|
39
|
+
}));
|
|
40
|
+
|
|
41
|
+
// Only the first page is added up, so a fixture that outgrows it would silently assert too little
|
|
42
|
+
expect(data.next).toBeUndefined();
|
|
43
|
+
|
|
44
|
+
const rows = data.results as { balanceItemPayment: { price: number } }[];
|
|
45
|
+
|
|
46
|
+
this.result = {
|
|
47
|
+
count: rows.length,
|
|
48
|
+
price: rows.reduce((total, row) => total + row.balanceItemPayment.price, 0),
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return new Response(undefined);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* How many balance item payments a filter selects, and what they are worth together.
|
|
57
|
+
*/
|
|
58
|
+
export async function exportSlice({ organization, user, filter, search = null }: { organization: Organization; user: User; filter: StamhoofdFilter; search?: string | null }) {
|
|
59
|
+
const token = await Token.createToken(user);
|
|
60
|
+
|
|
61
|
+
const request = Request.get({
|
|
62
|
+
path: '/exports/balance-item-payments',
|
|
63
|
+
host: organization.getApiHost(),
|
|
64
|
+
headers: { authorization: 'Bearer ' + token.accessToken },
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const endpoint = new ExportSliceEndpoint(filter, search);
|
|
68
|
+
await testServer.test(endpoint, request);
|
|
69
|
+
|
|
70
|
+
return endpoint.result;
|
|
71
|
+
}
|