@stamhoofd/backend 2.39.1 → 2.40.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/eslint.config.mjs +5 -0
- package/index.ts +81 -74
- package/jest.config.cjs +10 -0
- package/migrations.ts +16 -14
- package/package.json +11 -11
- package/src/crons/clear-excel-cache.test.ts +48 -50
- package/src/crons/clear-excel-cache.ts +18 -18
- package/src/crons/setup-steps.ts +2 -2
- package/src/crons.ts +325 -306
- package/src/decoders/StringArrayDecoder.ts +7 -7
- package/src/decoders/StringNullableDecoder.ts +1 -2
- package/src/email-recipient-loaders/members.ts +22 -22
- package/src/endpoints/admin/memberships/ChargeMembershipsEndpoint.ts +8 -9
- package/src/endpoints/admin/memberships/GetChargeMembershipsSummaryEndpoint.ts +39 -40
- package/src/endpoints/admin/organizations/GetOrganizationsCountEndpoint.ts +8 -8
- package/src/endpoints/admin/organizations/GetOrganizationsEndpoint.ts +44 -45
- package/src/endpoints/admin/organizations/PatchOrganizationsEndpoint.ts +58 -57
- package/src/endpoints/auth/CreateAdminEndpoint.ts +48 -45
- package/src/endpoints/auth/CreateTokenEndpoint.test.ts +31 -31
- package/src/endpoints/auth/CreateTokenEndpoint.ts +146 -147
- package/src/endpoints/auth/DeleteTokenEndpoint.ts +7 -7
- package/src/endpoints/auth/DeleteUserEndpoint.ts +15 -15
- package/src/endpoints/auth/ForgotPasswordEndpoint.ts +17 -18
- package/src/endpoints/auth/GetOtherUserEndpoint.ts +9 -10
- package/src/endpoints/auth/GetUserEndpoint.test.ts +32 -35
- package/src/endpoints/auth/GetUserEndpoint.ts +5 -6
- package/src/endpoints/auth/PatchApiUserEndpoint.ts +35 -33
- package/src/endpoints/auth/PatchUserEndpoint.ts +55 -52
- package/src/endpoints/auth/PollEmailVerificationEndpoint.ts +9 -9
- package/src/endpoints/auth/RetryEmailVerificationEndpoint.ts +8 -8
- package/src/endpoints/auth/SignupEndpoint.ts +37 -36
- package/src/endpoints/auth/VerifyEmailEndpoint.ts +29 -28
- package/src/endpoints/global/addresses/SearchRegionsEndpoint.ts +33 -33
- package/src/endpoints/global/addresses/ValidateAddressEndpoint.ts +7 -7
- package/src/endpoints/global/caddy/CheckDomainCertEndpoint.ts +37 -37
- package/src/endpoints/global/email/CreateEmailEndpoint.ts +30 -30
- package/src/endpoints/global/email/GetEmailAddressEndpoint.ts +13 -13
- package/src/endpoints/global/email/GetEmailEndpoint.ts +13 -13
- package/src/endpoints/global/email/ManageEmailAddressEndpoint.ts +16 -16
- package/src/endpoints/global/email/PatchEmailEndpoint.ts +25 -25
- package/src/endpoints/global/events/GetEventsEndpoint.ts +43 -44
- package/src/endpoints/global/events/PatchEventsEndpoint.ts +127 -172
- package/src/endpoints/global/files/ExportToExcelEndpoint.ts +49 -50
- package/src/endpoints/global/files/GetFileCache.ts +13 -13
- package/src/endpoints/global/files/UploadFile.ts +51 -54
- package/src/endpoints/global/files/UploadImage.ts +53 -53
- package/src/endpoints/global/groups/GetGroupsEndpoint.ts +25 -25
- package/src/endpoints/global/members/GetMemberFamilyEndpoint.ts +24 -23
- package/src/endpoints/global/members/GetMembersCountEndpoint.ts +8 -8
- package/src/endpoints/global/members/GetMembersEndpoint.ts +105 -102
- package/src/endpoints/global/members/PatchOrganizationMembersEndpoint.ts +240 -239
- package/src/endpoints/global/organizations/CheckRegisterCodeEndpoint.ts +12 -14
- package/src/endpoints/global/organizations/CreateOrganizationEndpoint.test.ts +32 -33
- package/src/endpoints/global/organizations/CreateOrganizationEndpoint.ts +48 -57
- package/src/endpoints/global/organizations/GetOrganizationFromDomainEndpoint.test.ts +21 -22
- package/src/endpoints/global/organizations/GetOrganizationFromDomainEndpoint.ts +28 -28
- package/src/endpoints/global/organizations/GetOrganizationFromUriEndpoint.ts +18 -18
- package/src/endpoints/global/organizations/SearchOrganizationEndpoint.test.ts +20 -20
- package/src/endpoints/global/organizations/SearchOrganizationEndpoint.ts +17 -17
- package/src/endpoints/global/payments/StripeWebhookEndpoint.ts +81 -75
- package/src/endpoints/global/platform/GetPlatformAdminsEndpoint.ts +14 -14
- package/src/endpoints/global/platform/GetPlatformEnpoint.ts +11 -11
- package/src/endpoints/global/platform/PatchPlatformEnpoint.ts +71 -68
- package/src/endpoints/global/registration/GetPaymentRegistrations.ts +27 -27
- package/src/endpoints/global/registration/GetUserBillingStatusEndpoint.ts +30 -30
- package/src/endpoints/global/registration/GetUserDetailedBillingStatusEndpoint.ts +34 -34
- package/src/endpoints/global/registration/GetUserDocumentsEndpoint.ts +26 -26
- package/src/endpoints/global/registration/GetUserMembersEndpoint.ts +12 -12
- package/src/endpoints/global/registration/PatchUserMembersEndpoint.ts +90 -90
- package/src/endpoints/global/registration/RegisterMembersEndpoint.test.ts +118 -121
- package/src/endpoints/global/registration/RegisterMembersEndpoint.ts +362 -350
- package/src/endpoints/global/registration-periods/GetRegistrationPeriodsEndpoint.ts +8 -9
- package/src/endpoints/global/registration-periods/PatchRegistrationPeriodsEndpoint.ts +21 -21
- package/src/endpoints/global/webshops/GetWebshopFromDomainEndpoint.ts +65 -65
- package/src/endpoints/organization/dashboard/billing/GetOrganizationBillingStatusEndpoint.ts +9 -9
- package/src/endpoints/organization/dashboard/billing/GetOrganizationDetailedBillingStatusEndpoint.ts +14 -14
- package/src/endpoints/organization/dashboard/documents/GetDocumentTemplateXML.ts +17 -17
- package/src/endpoints/organization/dashboard/documents/GetDocumentTemplatesEndpoint.ts +21 -21
- package/src/endpoints/organization/dashboard/documents/GetDocumentsEndpoint.ts +15 -15
- package/src/endpoints/organization/dashboard/documents/PatchDocumentEndpoint.ts +52 -52
- package/src/endpoints/organization/dashboard/documents/PatchDocumentTemplateEndpoint.ts +37 -37
- package/src/endpoints/organization/dashboard/email/CheckEmailBouncesEndpoint.ts +14 -14
- package/src/endpoints/organization/dashboard/email/EmailEndpoint.ts +113 -112
- package/src/endpoints/organization/dashboard/email-templates/GetEmailTemplatesEndpoint.ts +29 -29
- package/src/endpoints/organization/dashboard/email-templates/PatchEmailTemplatesEndpoint.ts +48 -47
- package/src/endpoints/organization/dashboard/mollie/CheckMollieEndpoint.ts +22 -21
- package/src/endpoints/organization/dashboard/mollie/ConnectMollieEndpoint.ts +13 -14
- package/src/endpoints/organization/dashboard/mollie/DisconnectMollieEndpoint.ts +12 -13
- package/src/endpoints/organization/dashboard/mollie/GetMollieDashboardEndpoint.ts +24 -24
- package/src/endpoints/organization/dashboard/nolt/CreateNoltTokenEndpoint.ts +10 -12
- package/src/endpoints/organization/dashboard/organization/GetOrganizationArchivedGroups.ts +14 -14
- package/src/endpoints/organization/dashboard/organization/GetOrganizationDeletedGroups.ts +13 -13
- package/src/endpoints/organization/dashboard/organization/GetOrganizationSSOEndpoint.ts +12 -12
- package/src/endpoints/organization/dashboard/organization/PatchOrganizationEndpoint.test.ts +120 -124
- package/src/endpoints/organization/dashboard/organization/PatchOrganizationEndpoint.ts +172 -173
- package/src/endpoints/organization/dashboard/organization/SetOrganizationDomainEndpoint.ts +88 -89
- package/src/endpoints/organization/dashboard/organization/SetOrganizationSSOEndpoint.ts +12 -12
- package/src/endpoints/organization/dashboard/payments/GetMemberBalanceEndpoint.ts +17 -17
- package/src/endpoints/organization/dashboard/payments/GetPaymentsCountEndpoint.ts +8 -8
- package/src/endpoints/organization/dashboard/payments/GetPaymentsEndpoint.ts +66 -67
- package/src/endpoints/organization/dashboard/payments/PatchBalanceItemsEndpoint.ts +47 -47
- package/src/endpoints/organization/dashboard/payments/PatchPaymentsEndpoint.ts +93 -91
- package/src/endpoints/organization/dashboard/registration-periods/GetOrganizationRegistrationPeriodsEndpoint.ts +16 -17
- package/src/endpoints/organization/dashboard/registration-periods/PatchOrganizationRegistrationPeriodsEndpoint.ts +170 -167
- package/src/endpoints/organization/dashboard/registration-periods/SetupStepReviewEndpoint.ts +25 -24
- package/src/endpoints/organization/dashboard/stripe/ConnectStripeEndpoint.ts +22 -23
- package/src/endpoints/organization/dashboard/stripe/DeleteStripeAccountEndpoint.ts +22 -22
- package/src/endpoints/organization/dashboard/stripe/GetStripeAccountLinkEndpoint.ts +17 -18
- package/src/endpoints/organization/dashboard/stripe/GetStripeAccountsEndpoint.ts +8 -9
- package/src/endpoints/organization/dashboard/stripe/GetStripeLoginLinkEndpoint.ts +17 -18
- package/src/endpoints/organization/dashboard/stripe/UpdateStripeAccountEndpoint.ts +14 -15
- package/src/endpoints/organization/dashboard/users/CreateApiUserEndpoint.ts +19 -19
- package/src/endpoints/organization/dashboard/users/DeleteUserEndpoint.ts +19 -19
- package/src/endpoints/organization/dashboard/users/GetApiUsersEndpoint.ts +14 -14
- package/src/endpoints/organization/dashboard/users/GetOrganizationAdminsEndpoint.ts +12 -12
- package/src/endpoints/organization/dashboard/webshops/CreateWebshopEndpoint.ts +103 -100
- package/src/endpoints/organization/dashboard/webshops/DeleteWebshopEndpoint.ts +11 -12
- package/src/endpoints/organization/dashboard/webshops/GetDiscountCodesEndpoint.ts +15 -15
- package/src/endpoints/organization/dashboard/webshops/GetWebshopOrdersEndpoint.ts +14 -14
- package/src/endpoints/organization/dashboard/webshops/GetWebshopTicketsEndpoint.ts +14 -14
- package/src/endpoints/organization/dashboard/webshops/GetWebshopUriAvailabilityEndpoint.ts +23 -23
- package/src/endpoints/organization/dashboard/webshops/PatchDiscountCodesEndpoint.ts +54 -52
- package/src/endpoints/organization/dashboard/webshops/PatchWebshopEndpoint.ts +84 -81
- package/src/endpoints/organization/dashboard/webshops/PatchWebshopOrdersEndpoint.ts +120 -111
- package/src/endpoints/organization/dashboard/webshops/PatchWebshopTicketsEndpoint.ts +24 -24
- package/src/endpoints/organization/dashboard/webshops/VerifyWebshopDomainEndpoint.ts +18 -18
- package/src/endpoints/organization/shared/ExchangePaymentEndpoint.ts +141 -130
- package/src/endpoints/organization/shared/GetDocumentHtml.ts +25 -25
- package/src/endpoints/organization/shared/GetPaymentEndpoint.ts +18 -18
- package/src/endpoints/organization/shared/auth/GetOrganizationEndpoint.test.ts +36 -37
- package/src/endpoints/organization/shared/auth/GetOrganizationEndpoint.ts +9 -9
- package/src/endpoints/organization/shared/auth/OpenIDConnectCallbackEndpoint.ts +11 -11
- package/src/endpoints/organization/shared/auth/OpenIDConnectStartEndpoint.ts +28 -27
- package/src/endpoints/organization/webshops/CheckWebshopDiscountCodesEndpoint.ts +20 -20
- package/src/endpoints/organization/webshops/GetOrderByPaymentEndpoint.ts +22 -22
- package/src/endpoints/organization/webshops/GetOrderEndpoint.ts +14 -14
- package/src/endpoints/organization/webshops/GetTicketsEndpoint.ts +57 -56
- package/src/endpoints/organization/webshops/GetWebshopEndpoint.test.ts +65 -66
- package/src/endpoints/organization/webshops/GetWebshopEndpoint.ts +18 -17
- package/src/endpoints/organization/webshops/PlaceOrderEndpoint.test.ts +124 -128
- package/src/endpoints/organization/webshops/PlaceOrderEndpoint.ts +154 -145
- package/src/excel-loaders/members.ts +102 -103
- package/src/excel-loaders/payments.ts +155 -156
- package/src/helpers/AddressValidator.test.ts +32 -32
- package/src/helpers/AddressValidator.ts +128 -122
- package/src/helpers/AdminPermissionChecker.ts +339 -236
- package/src/helpers/AuthenticatedStructures.ts +233 -134
- package/src/helpers/BuckarooHelper.ts +134 -134
- package/src/helpers/CheckSettlements.ts +94 -88
- package/src/helpers/Context.ts +87 -86
- package/src/helpers/CookieHelper.ts +23 -22
- package/src/helpers/EmailResumer.ts +10 -10
- package/src/helpers/FileCache.ts +62 -62
- package/src/helpers/ForwardHandler.test.ts +122 -124
- package/src/helpers/ForwardHandler.ts +76 -70
- package/src/helpers/MemberUserSyncer.ts +101 -96
- package/src/helpers/MembershipCharger.ts +69 -69
- package/src/helpers/MembershipHelper.ts +11 -12
- package/src/helpers/OpenIDConnectHelper.ts +85 -82
- package/src/helpers/PeriodHelper.ts +65 -70
- package/src/helpers/StripeHelper.ts +146 -137
- package/src/helpers/StripePayoutChecker.ts +51 -52
- package/src/helpers/ViesHelper.ts +46 -44
- package/src/helpers/fetchToAsyncIterator.ts +14 -14
- package/src/helpers/xlsxAddressTransformerColumnFactory.ts +50 -52
- package/src/middleware/ContextMiddleware.ts +5 -5
- package/src/migrations/1646578856-validate-addresses.ts +6 -9
- package/src/seeds/0000000000-example.ts +3 -5
- package/src/seeds/1715028563-user-permissions.ts +16 -18
- package/src/seeds/1722256498-group-update-occupancy.ts +12 -12
- package/src/seeds/1722344162-sync-member-users.ts +14 -15
- package/src/seeds/1722344162-update-membership.ts +6 -6
- package/src/seeds/1726055544-balance-item-paid.ts +4 -4
- package/src/seeds/1726055545-balance-item-pending.ts +4 -4
- package/src/seeds/1726494419-update-cached-outstanding-balance.ts +16 -16
- package/src/seeds/1726494420-update-cached-outstanding-balance-from-items.ts +12 -12
- package/src/seeds/1726572303-schedule-stock-updates.ts +12 -12
- package/src/seeds/1726847064-setup-steps.ts +16 -0
- package/src/sql-filters/balance-item-payments.ts +7 -7
- package/src/sql-filters/events.ts +14 -14
- package/src/sql-filters/members.ts +96 -96
- package/src/sql-filters/organizations.ts +139 -75
- package/src/sql-filters/payments.ts +28 -28
- package/src/sql-filters/registrations.ts +14 -14
- package/src/sql-sorters/events.ts +25 -25
- package/src/sql-sorters/members.ts +26 -26
- package/src/sql-sorters/organizations.ts +36 -36
- package/src/sql-sorters/payments.ts +26 -26
- package/tests/e2e/stock.test.ts +616 -621
- package/tests/e2e/tickets.test.ts +255 -260
- package/tests/helpers/StripeMocker.ts +177 -179
- package/tests/helpers/TestServer.ts +9 -9
- package/tests/jest.global.setup.ts +14 -13
- package/tests/jest.setup.ts +33 -32
- package/.eslintrc.js +0 -61
- package/jest.config.js +0 -11
- package/src/helpers/SetupStepsUpdater.ts +0 -359
- package/src/seeds/1724076679-setup-steps.ts +0 -16
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { AutoEncoder, Decoder, field, StringDecoder } from
|
|
2
|
-
import { DecodedRequest, Endpoint, Request, Response } from
|
|
3
|
-
import { SimpleError } from
|
|
1
|
+
import { AutoEncoder, Decoder, field, StringDecoder } from '@simonbackx/simple-encoding';
|
|
2
|
+
import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
|
|
3
|
+
import { SimpleError } from '@simonbackx/simple-errors';
|
|
4
4
|
import { Order, Ticket } from '@stamhoofd/models';
|
|
5
|
-
import { TicketOrder, TicketPublic } from
|
|
5
|
+
import { TicketOrder, TicketPublic } from '@stamhoofd/structures';
|
|
6
6
|
|
|
7
|
-
import { Context } from
|
|
7
|
+
import { Context } from '../../../helpers/Context';
|
|
8
8
|
type Params = { id: string };
|
|
9
9
|
|
|
10
10
|
class Query extends AutoEncoder {
|
|
@@ -12,28 +12,28 @@ class Query extends AutoEncoder {
|
|
|
12
12
|
* Get one ticket by the secret of an individual ticket
|
|
13
13
|
*/
|
|
14
14
|
@field({ decoder: StringDecoder, optional: true })
|
|
15
|
-
secret?: string
|
|
15
|
+
secret?: string;
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Get all tickets of a single order if key is not passed.
|
|
19
19
|
* If key is passed, only return a single ticket, but exclude item information
|
|
20
20
|
*/
|
|
21
21
|
@field({ decoder: StringDecoder, optional: true })
|
|
22
|
-
orderId?: string
|
|
22
|
+
orderId?: string;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
type Body = undefined
|
|
26
|
-
type ResponseBody = TicketPublic[] | TicketOrder[]
|
|
25
|
+
type Body = undefined;
|
|
26
|
+
type ResponseBody = TicketPublic[] | TicketOrder[];
|
|
27
27
|
|
|
28
28
|
export class GetTicketsEndpoint extends Endpoint<Params, Query, Body, ResponseBody> {
|
|
29
|
-
queryDecoder = Query as Decoder<Query
|
|
30
|
-
|
|
29
|
+
queryDecoder = Query as Decoder<Query>;
|
|
30
|
+
|
|
31
31
|
protected doesMatch(request: Request): [true, Params] | [false] {
|
|
32
|
-
if (request.method
|
|
32
|
+
if (request.method !== 'GET') {
|
|
33
33
|
return [false];
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
const params = Endpoint.parseParameters(request.url,
|
|
36
|
+
const params = Endpoint.parseParameters(request.url, '/webshop/@id/tickets', { id: String });
|
|
37
37
|
|
|
38
38
|
if (params) {
|
|
39
39
|
return [true, params as Params];
|
|
@@ -42,83 +42,84 @@ export class GetTicketsEndpoint extends Endpoint<Params, Query, Body, ResponseBo
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
async handle(request: DecodedRequest<Params, Query, Body>) {
|
|
45
|
-
const organization = await Context.setOrganizationScope()
|
|
46
|
-
|
|
45
|
+
const organization = await Context.setOrganizationScope();
|
|
46
|
+
|
|
47
47
|
if (request.query.secret) {
|
|
48
|
-
const [ticket] = await Ticket.where({
|
|
49
|
-
secret: request.query.secret,
|
|
48
|
+
const [ticket] = await Ticket.where({
|
|
49
|
+
secret: request.query.secret,
|
|
50
50
|
webshopId: request.params.id,
|
|
51
|
-
organizationId: organization.id
|
|
52
|
-
}, { limit: 1 })
|
|
51
|
+
organizationId: organization.id,
|
|
52
|
+
}, { limit: 1 });
|
|
53
53
|
|
|
54
54
|
if (!ticket || (request.query.orderId && ticket.orderId !== request.query.orderId) || ticket.isDeleted) {
|
|
55
55
|
throw new SimpleError({
|
|
56
|
-
code:
|
|
57
|
-
message:
|
|
58
|
-
human:
|
|
59
|
-
})
|
|
56
|
+
code: 'not_found',
|
|
57
|
+
message: 'Ticket not found',
|
|
58
|
+
human: 'Dit ticket bestaat niet',
|
|
59
|
+
});
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
if (!request.query.orderId) {
|
|
63
63
|
// Include item data
|
|
64
|
-
const order = await Order.getByID(ticket.orderId)
|
|
64
|
+
const order = await Order.getByID(ticket.orderId);
|
|
65
65
|
if (!order || order.webshopId !== request.params.id) {
|
|
66
|
-
console.error(
|
|
66
|
+
console.error('Error: missing order ' + ticket.orderId + ' for ticket ' + ticket.id);
|
|
67
67
|
throw new SimpleError({
|
|
68
|
-
code:
|
|
69
|
-
message:
|
|
70
|
-
human:
|
|
71
|
-
})
|
|
68
|
+
code: 'not_found',
|
|
69
|
+
message: 'Ticket not found',
|
|
70
|
+
human: 'Dit ticket bestaat niet',
|
|
71
|
+
});
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
if (ticket.itemId) {
|
|
75
|
-
const item = order.data.cart.items.find(i => i.id === ticket.itemId)
|
|
76
|
-
|
|
75
|
+
const item = order.data.cart.items.find(i => i.id === ticket.itemId);
|
|
76
|
+
|
|
77
77
|
if (!item) {
|
|
78
|
-
console.error(
|
|
78
|
+
console.error('Error: missing item ' + ticket.itemId + ' for ticket ' + ticket.id);
|
|
79
79
|
throw new SimpleError({
|
|
80
|
-
code:
|
|
81
|
-
message:
|
|
82
|
-
human:
|
|
83
|
-
})
|
|
80
|
+
code: 'not_found',
|
|
81
|
+
message: 'Ticket not found',
|
|
82
|
+
human: 'Dit ticket bestaat niet',
|
|
83
|
+
});
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
return new Response([
|
|
87
87
|
TicketPublic.create({
|
|
88
88
|
...ticket,
|
|
89
|
-
items: [item]
|
|
90
|
-
})
|
|
91
|
-
]);
|
|
92
|
-
|
|
93
|
-
|
|
89
|
+
items: [item],
|
|
90
|
+
}),
|
|
91
|
+
]);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
94
|
return new Response([
|
|
95
95
|
TicketPublic.create({
|
|
96
96
|
...ticket,
|
|
97
|
-
items: order.data.cart.items
|
|
98
|
-
})
|
|
99
|
-
]);
|
|
97
|
+
items: order.data.cart.items,
|
|
98
|
+
}),
|
|
99
|
+
]);
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
return new Response([
|
|
103
|
-
TicketOrder.create(ticket)
|
|
104
|
-
]);
|
|
105
|
-
}
|
|
103
|
+
TicketOrder.create(ticket),
|
|
104
|
+
]);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
106
107
|
if (!request.query.orderId) {
|
|
107
108
|
throw new SimpleError({
|
|
108
|
-
code:
|
|
109
|
-
message:
|
|
110
|
-
})
|
|
109
|
+
code: 'not_found',
|
|
110
|
+
message: 'At least one query parameter expected: secret, orderId',
|
|
111
|
+
});
|
|
111
112
|
}
|
|
112
113
|
|
|
113
|
-
const tickets = await Ticket.where({
|
|
114
|
-
orderId: request.query.orderId,
|
|
114
|
+
const tickets = await Ticket.where({
|
|
115
|
+
orderId: request.query.orderId,
|
|
115
116
|
webshopId: request.params.id,
|
|
116
117
|
organizationId: organization.id,
|
|
117
|
-
deletedAt: null
|
|
118
|
-
})
|
|
118
|
+
deletedAt: null,
|
|
119
|
+
});
|
|
119
120
|
return new Response(
|
|
120
|
-
tickets.map(ticket => TicketOrder.create(ticket))
|
|
121
|
-
);
|
|
121
|
+
tickets.map(ticket => TicketOrder.create(ticket)),
|
|
122
|
+
);
|
|
122
123
|
}
|
|
123
124
|
}
|
|
124
125
|
}
|
|
@@ -1,130 +1,129 @@
|
|
|
1
|
-
import { Request } from
|
|
1
|
+
import { Request } from '@simonbackx/simple-endpoints';
|
|
2
2
|
import { OrganizationFactory, Token, UserFactory, WebshopFactory } from '@stamhoofd/models';
|
|
3
|
-
import { PermissionLevel, Permissions, PrivateWebshop, Webshop as WebshopStruct
|
|
3
|
+
import { PermissionLevel, Permissions, PrivateWebshop, Webshop as WebshopStruct } from '@stamhoofd/structures';
|
|
4
4
|
|
|
5
|
-
import { testServer } from
|
|
5
|
+
import { testServer } from '../../../../tests/helpers/TestServer';
|
|
6
6
|
import { GetWebshopEndpoint } from './GetWebshopEndpoint';
|
|
7
7
|
|
|
8
|
-
describe(
|
|
8
|
+
describe('Endpoint.GetWebshop', () => {
|
|
9
9
|
// Test endpoint
|
|
10
10
|
const endpoint = new GetWebshopEndpoint();
|
|
11
11
|
|
|
12
|
-
test(
|
|
13
|
-
const organization = await new OrganizationFactory({}).create()
|
|
14
|
-
const user = await new UserFactory({ organization }).create()
|
|
15
|
-
const token = await Token.createToken(user)
|
|
16
|
-
const webshop = await new WebshopFactory({ organizationId: organization.id }).create()
|
|
12
|
+
test('Get webshop as signed in user', async () => {
|
|
13
|
+
const organization = await new OrganizationFactory({}).create();
|
|
14
|
+
const user = await new UserFactory({ organization }).create();
|
|
15
|
+
const token = await Token.createToken(user);
|
|
16
|
+
const webshop = await new WebshopFactory({ organizationId: organization.id }).create();
|
|
17
17
|
|
|
18
|
-
const r = Request.buildJson(
|
|
19
|
-
r.headers.authorization =
|
|
18
|
+
const r = Request.buildJson('GET', '/v244/webshop/' + webshop.id, organization.getApiHost());
|
|
19
|
+
r.headers.authorization = 'Bearer ' + token.accessToken;
|
|
20
20
|
|
|
21
21
|
const response = await testServer.test(endpoint, r);
|
|
22
22
|
expect(response.body).toBeDefined();
|
|
23
23
|
|
|
24
|
-
expect(response.body.id).toEqual(webshop.id)
|
|
25
|
-
expect((response.body as any).privateMeta).toBeUndefined()
|
|
24
|
+
expect(response.body.id).toEqual(webshop.id);
|
|
25
|
+
expect((response.body as any).privateMeta).toBeUndefined();
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
test(
|
|
29
|
-
const organization = await new OrganizationFactory({}).create()
|
|
30
|
-
const webshop = await new WebshopFactory({ organizationId: organization.id }).create()
|
|
28
|
+
test('Allow access without organization scope in old v243', async () => {
|
|
29
|
+
const organization = await new OrganizationFactory({}).create();
|
|
30
|
+
const webshop = await new WebshopFactory({ organizationId: organization.id }).create();
|
|
31
31
|
|
|
32
|
-
const r = Request.buildJson(
|
|
32
|
+
const r = Request.buildJson('GET', '/v243/webshop/' + webshop.id);
|
|
33
33
|
|
|
34
34
|
const response = await testServer.test(endpoint, r);
|
|
35
35
|
expect(response.body).toBeDefined();
|
|
36
36
|
|
|
37
|
-
expect(response.body.id).toEqual(webshop.id)
|
|
38
|
-
expect((response.body as any).privateMeta).toBeUndefined()
|
|
37
|
+
expect(response.body.id).toEqual(webshop.id);
|
|
38
|
+
expect((response.body as any).privateMeta).toBeUndefined();
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
-
test(
|
|
42
|
-
const organization = await new OrganizationFactory({}).create()
|
|
43
|
-
const webshop = await new WebshopFactory({ organizationId: organization.id }).create()
|
|
44
|
-
const r = Request.buildJson(
|
|
41
|
+
test('Do not allow access without organization scope in v244', async () => {
|
|
42
|
+
const organization = await new OrganizationFactory({}).create();
|
|
43
|
+
const webshop = await new WebshopFactory({ organizationId: organization.id }).create();
|
|
44
|
+
const r = Request.buildJson('GET', '/v244/webshop/' + webshop.id);
|
|
45
45
|
await expect(testServer.test(endpoint, r)).rejects.toThrow('Please specify the organization in the hostname');
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
test(
|
|
49
|
-
const organization = await new OrganizationFactory({}).create()
|
|
48
|
+
test('Get webshop as admin', async () => {
|
|
49
|
+
const organization = await new OrganizationFactory({}).create();
|
|
50
50
|
const user = await new UserFactory({
|
|
51
51
|
organization,
|
|
52
52
|
permissions: Permissions.create({
|
|
53
|
-
level: PermissionLevel.Read
|
|
54
|
-
})
|
|
55
|
-
}).create()
|
|
56
|
-
const token = await Token.createToken(user)
|
|
53
|
+
level: PermissionLevel.Read,
|
|
54
|
+
}),
|
|
55
|
+
}).create();
|
|
56
|
+
const token = await Token.createToken(user);
|
|
57
57
|
|
|
58
|
-
const webshop = await new WebshopFactory({ organizationId: organization.id }).create()
|
|
58
|
+
const webshop = await new WebshopFactory({ organizationId: organization.id }).create();
|
|
59
59
|
|
|
60
|
-
const r = Request.buildJson(
|
|
61
|
-
r.headers.authorization =
|
|
60
|
+
const r = Request.buildJson('GET', '/v244/webshop/' + webshop.id, organization.getApiHost());
|
|
61
|
+
r.headers.authorization = 'Bearer ' + token.accessToken;
|
|
62
62
|
|
|
63
63
|
const response = await testServer.test(endpoint, r);
|
|
64
64
|
expect(response.body).toBeDefined();
|
|
65
65
|
|
|
66
|
-
expect(response.body.id).toEqual(webshop.id)
|
|
67
|
-
expect((response.body as any).privateMeta).toBeDefined()
|
|
66
|
+
expect(response.body.id).toEqual(webshop.id);
|
|
67
|
+
expect((response.body as any).privateMeta).toBeDefined();
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
-
test(
|
|
71
|
-
const organization = await new OrganizationFactory({}).create()
|
|
70
|
+
test('Get webshop as admin that does not have access to specific webshop', async () => {
|
|
71
|
+
const organization = await new OrganizationFactory({}).create();
|
|
72
72
|
const user = await new UserFactory({
|
|
73
73
|
organization,
|
|
74
74
|
permissions: Permissions.create({
|
|
75
|
-
level: PermissionLevel.None
|
|
76
|
-
})
|
|
77
|
-
}).create()
|
|
78
|
-
const token = await Token.createToken(user)
|
|
75
|
+
level: PermissionLevel.None,
|
|
76
|
+
}),
|
|
77
|
+
}).create();
|
|
78
|
+
const token = await Token.createToken(user);
|
|
79
79
|
|
|
80
|
-
const webshop = await new WebshopFactory({ organizationId: organization.id }).create()
|
|
80
|
+
const webshop = await new WebshopFactory({ organizationId: organization.id }).create();
|
|
81
81
|
|
|
82
|
-
const r = Request.buildJson(
|
|
83
|
-
r.headers.authorization =
|
|
82
|
+
const r = Request.buildJson('GET', '/v244/webshop/' + webshop.id, organization.getApiHost());
|
|
83
|
+
r.headers.authorization = 'Bearer ' + token.accessToken;
|
|
84
84
|
|
|
85
85
|
const response = await testServer.test(endpoint, r);
|
|
86
86
|
expect(response.body).toBeDefined();
|
|
87
87
|
|
|
88
|
-
expect(response.body.id).toEqual(webshop.id)
|
|
89
|
-
expect((response.body as any).privateMeta).toBeUndefined()
|
|
88
|
+
expect(response.body.id).toEqual(webshop.id);
|
|
89
|
+
expect((response.body as any).privateMeta).toBeUndefined();
|
|
90
90
|
});
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
const organization = await new OrganizationFactory({}).create()
|
|
94
|
-
const organization2 = await new OrganizationFactory({}).create()
|
|
92
|
+
test('Get webshop as admin of a different organization', async () => {
|
|
93
|
+
const organization = await new OrganizationFactory({}).create();
|
|
94
|
+
const organization2 = await new OrganizationFactory({}).create();
|
|
95
95
|
const user = await new UserFactory({
|
|
96
96
|
organization: organization2,
|
|
97
97
|
permissions: Permissions.create({
|
|
98
|
-
level: PermissionLevel.Read
|
|
99
|
-
})
|
|
100
|
-
}).create()
|
|
98
|
+
level: PermissionLevel.Read,
|
|
99
|
+
}),
|
|
100
|
+
}).create();
|
|
101
101
|
|
|
102
|
-
const token = await Token.createToken(user)
|
|
103
|
-
const webshop = await new WebshopFactory({ organizationId: organization.id }).create()
|
|
102
|
+
const token = await Token.createToken(user);
|
|
103
|
+
const webshop = await new WebshopFactory({ organizationId: organization.id }).create();
|
|
104
104
|
|
|
105
|
-
const r = Request.buildJson(
|
|
106
|
-
r.headers.authorization =
|
|
105
|
+
const r = Request.buildJson('GET', '/v244/webshop/' + webshop.id, organization.getApiHost());
|
|
106
|
+
r.headers.authorization = 'Bearer ' + token.accessToken;
|
|
107
107
|
|
|
108
108
|
await expect(testServer.test(endpoint, r)).rejects.toThrow('The access token is invalid');
|
|
109
109
|
});
|
|
110
110
|
|
|
111
|
-
test(
|
|
112
|
-
const organization = await new OrganizationFactory({}).create()
|
|
113
|
-
const organization2 = await new OrganizationFactory({}).create()
|
|
111
|
+
test('If organization scope is missing in v243, access is still checked correctly', async () => {
|
|
112
|
+
const organization = await new OrganizationFactory({}).create();
|
|
113
|
+
const organization2 = await new OrganizationFactory({}).create();
|
|
114
114
|
const user = await new UserFactory({
|
|
115
115
|
organization: organization2,
|
|
116
116
|
permissions: Permissions.create({
|
|
117
|
-
level: PermissionLevel.Full
|
|
118
|
-
})
|
|
119
|
-
}).create()
|
|
117
|
+
level: PermissionLevel.Full,
|
|
118
|
+
}),
|
|
119
|
+
}).create();
|
|
120
120
|
|
|
121
|
-
const token = await Token.createToken(user)
|
|
122
|
-
const webshop = await new WebshopFactory({ organizationId: organization.id }).create()
|
|
121
|
+
const token = await Token.createToken(user);
|
|
122
|
+
const webshop = await new WebshopFactory({ organizationId: organization.id }).create();
|
|
123
123
|
|
|
124
|
-
const r = Request.buildJson(
|
|
125
|
-
r.headers.authorization =
|
|
124
|
+
const r = Request.buildJson('GET', '/v243/webshop/' + webshop.id);
|
|
125
|
+
r.headers.authorization = 'Bearer ' + token.accessToken;
|
|
126
126
|
|
|
127
127
|
await expect(testServer.test(endpoint, r)).rejects.toThrow('The access token is invalid');
|
|
128
128
|
});
|
|
129
|
-
|
|
130
129
|
});
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { DecodedRequest, Endpoint, Request, Response } from
|
|
1
|
+
import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
|
|
2
2
|
import { SimpleError } from '@simonbackx/simple-errors';
|
|
3
3
|
import { Webshop } from '@stamhoofd/models';
|
|
4
|
-
import { PrivateWebshop, Webshop as WebshopStruct } from
|
|
4
|
+
import { PrivateWebshop, Webshop as WebshopStruct } from '@stamhoofd/structures';
|
|
5
5
|
|
|
6
|
-
import { AuthenticatedStructures } from
|
|
7
|
-
import { Context } from
|
|
6
|
+
import { AuthenticatedStructures } from '../../../helpers/AuthenticatedStructures';
|
|
7
|
+
import { Context } from '../../../helpers/Context';
|
|
8
8
|
|
|
9
9
|
type Params = { id: string };
|
|
10
10
|
type Query = undefined;
|
|
11
|
-
type Body = undefined
|
|
11
|
+
type Body = undefined;
|
|
12
12
|
type ResponseBody = PrivateWebshop | WebshopStruct;
|
|
13
13
|
|
|
14
14
|
export class GetWebshopEndpoint extends Endpoint<Params, Query, Body, ResponseBody> {
|
|
15
15
|
protected doesMatch(request: Request): [true, Params] | [false] {
|
|
16
|
-
if (request.method
|
|
16
|
+
if (request.method !== 'GET') {
|
|
17
17
|
return [false];
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
const params = Endpoint.parseParameters(request.url,
|
|
20
|
+
const params = Endpoint.parseParameters(request.url, '/webshop/@id', { id: String });
|
|
21
21
|
|
|
22
22
|
if (params) {
|
|
23
23
|
return [true, params as Params];
|
|
@@ -28,23 +28,24 @@ export class GetWebshopEndpoint extends Endpoint<Params, Query, Body, ResponseBo
|
|
|
28
28
|
async handle(request: DecodedRequest<Params, Query, Body>) {
|
|
29
29
|
if (Context.version < 244) {
|
|
30
30
|
await Context.setOptionalOrganizationScope();
|
|
31
|
-
}
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
32
33
|
await Context.setOrganizationScope();
|
|
33
34
|
}
|
|
34
|
-
|
|
35
|
-
await Context.optionalAuthenticate()
|
|
36
35
|
|
|
37
|
-
|
|
36
|
+
await Context.optionalAuthenticate();
|
|
37
|
+
|
|
38
|
+
const webshop = await Webshop.getByID(request.params.id);
|
|
38
39
|
if (!webshop) {
|
|
39
40
|
throw new SimpleError({
|
|
40
|
-
code:
|
|
41
|
-
message:
|
|
42
|
-
human:
|
|
43
|
-
})
|
|
41
|
+
code: 'not_found',
|
|
42
|
+
message: 'Webshop not found',
|
|
43
|
+
human: 'Deze webshop bestaat niet (meer)',
|
|
44
|
+
});
|
|
44
45
|
}
|
|
45
|
-
|
|
46
|
+
|
|
46
47
|
return new Response(
|
|
47
|
-
await AuthenticatedStructures.webshop(webshop)
|
|
48
|
+
await AuthenticatedStructures.webshop(webshop),
|
|
48
49
|
);
|
|
49
50
|
}
|
|
50
51
|
}
|