@stamhoofd/backend 2.39.0 → 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,9 +1,9 @@
|
|
|
1
1
|
import { AutoEncoderPatchType, Decoder } from '@simonbackx/simple-encoding';
|
|
2
|
-
import { DecodedRequest, Endpoint, Request, Response } from
|
|
2
|
+
import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
|
|
3
3
|
import { SimpleError } from '@simonbackx/simple-errors';
|
|
4
4
|
import { Token, Webshop } from '@stamhoofd/models';
|
|
5
5
|
import { QueueHandler } from '@stamhoofd/queues';
|
|
6
|
-
import { PermissionLevel, PrivateWebshop, WebshopPrivateMetaData } from
|
|
6
|
+
import { PermissionLevel, PrivateWebshop, WebshopPrivateMetaData } from '@stamhoofd/structures';
|
|
7
7
|
import { Formatter } from '@stamhoofd/utility';
|
|
8
8
|
|
|
9
9
|
import { Context } from '../../../../helpers/Context';
|
|
@@ -18,14 +18,14 @@ type ResponseBody = PrivateWebshop;
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
export class PatchWebshopEndpoint extends Endpoint<Params, Query, Body, ResponseBody> {
|
|
21
|
-
bodyDecoder = PrivateWebshop.patchType() as Decoder<AutoEncoderPatchType<PrivateWebshop
|
|
21
|
+
bodyDecoder = PrivateWebshop.patchType() as Decoder<AutoEncoderPatchType<PrivateWebshop>>;
|
|
22
22
|
|
|
23
23
|
protected doesMatch(request: Request): [true, Params] | [false] {
|
|
24
|
-
if (request.method
|
|
24
|
+
if (request.method !== 'PATCH') {
|
|
25
25
|
return [false];
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
const params = Endpoint.parseParameters(request.url,
|
|
28
|
+
const params = Endpoint.parseParameters(request.url, '/webshop/@id', { id: String });
|
|
29
29
|
|
|
30
30
|
if (params) {
|
|
31
31
|
return [true, params as Params];
|
|
@@ -35,170 +35,173 @@ export class PatchWebshopEndpoint extends Endpoint<Params, Query, Body, Response
|
|
|
35
35
|
|
|
36
36
|
async handle(request: DecodedRequest<Params, Query, Body>) {
|
|
37
37
|
const organization = await Context.setOrganizationScope();
|
|
38
|
-
await Context.authenticate()
|
|
38
|
+
await Context.authenticate();
|
|
39
39
|
|
|
40
40
|
// Fast throw first (more in depth checking for patches later)
|
|
41
41
|
if (!await Context.auth.hasSomeAccess(organization.id)) {
|
|
42
|
-
throw Context.auth.error()
|
|
42
|
+
throw Context.auth.error();
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
// Halt all order placement and validation + pause stock updates
|
|
46
|
-
return await QueueHandler.schedule(
|
|
47
|
-
const webshop = await Webshop.getByID(request.params.id)
|
|
46
|
+
return await QueueHandler.schedule('webshop-stock/' + request.params.id, async () => {
|
|
47
|
+
const webshop = await Webshop.getByID(request.params.id);
|
|
48
48
|
if (!webshop || !await Context.auth.canAccessWebshop(webshop, PermissionLevel.Full)) {
|
|
49
|
-
throw Context.auth.notFoundOrNoAccess()
|
|
49
|
+
throw Context.auth.notFoundOrNoAccess();
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
// Do all updates
|
|
53
53
|
if (request.body.meta) {
|
|
54
|
-
request.body.meta.domainActive = undefined
|
|
55
|
-
webshop.meta.patchOrPut(request.body.meta)
|
|
54
|
+
request.body.meta.domainActive = undefined;
|
|
55
|
+
webshop.meta.patchOrPut(request.body.meta);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
if (request.body.privateMeta) {
|
|
59
59
|
// Prevent editing internal fields
|
|
60
|
-
(request.body.privateMeta as any).dnsRecords = undefined
|
|
61
|
-
webshop.privateMeta.patchOrPut(request.body.privateMeta)
|
|
60
|
+
(request.body.privateMeta as any).dnsRecords = undefined;
|
|
61
|
+
webshop.privateMeta.patchOrPut(request.body.privateMeta);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
if (request.body.products) {
|
|
65
|
-
webshop.products = request.body.products.applyTo(webshop.products)
|
|
65
|
+
webshop.products = request.body.products.applyTo(webshop.products);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
if (request.body.categories) {
|
|
69
|
-
webshop.categories = request.body.categories.applyTo(webshop.categories)
|
|
69
|
+
webshop.categories = request.body.categories.applyTo(webshop.categories);
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
if (request.body.domain !== undefined) {
|
|
73
73
|
if (request.body.domain !== null) {
|
|
74
74
|
const cleaned = request.body.domain.toLowerCase().replace(/[^a-zA-Z0-9-.]/g, '');
|
|
75
75
|
|
|
76
|
-
if (cleaned
|
|
77
|
-
webshop.domain = cleaned
|
|
78
|
-
webshop.meta.domainActive = false
|
|
79
|
-
webshop.privateMeta.dnsRecords = WebshopPrivateMetaData.buildDNSRecords(cleaned)
|
|
76
|
+
if (cleaned !== webshop.domain) {
|
|
77
|
+
webshop.domain = cleaned;
|
|
78
|
+
webshop.meta.domainActive = false;
|
|
79
|
+
webshop.privateMeta.dnsRecords = WebshopPrivateMetaData.buildDNSRecords(cleaned);
|
|
80
80
|
|
|
81
81
|
// Check if this is a known domain
|
|
82
|
-
const knownWebshops = await Webshop.getByDomainOnly(cleaned)
|
|
82
|
+
const knownWebshops = await Webshop.getByDomainOnly(cleaned);
|
|
83
83
|
|
|
84
84
|
if (knownWebshops.length > 0) {
|
|
85
|
-
const active = !!knownWebshops.find(k => k.meta.domainActive)
|
|
85
|
+
const active = !!knownWebshops.find(k => k.meta.domainActive);
|
|
86
86
|
|
|
87
87
|
if (active) {
|
|
88
|
-
const sameOrg = knownWebshops.find(w => w.organizationId === organization.id)
|
|
89
|
-
const otherOrg = knownWebshops.find(w => w.organizationId !== organization.id)
|
|
88
|
+
const sameOrg = knownWebshops.find(w => w.organizationId === organization.id);
|
|
89
|
+
const otherOrg = knownWebshops.find(w => w.organizationId !== organization.id);
|
|
90
90
|
if (otherOrg && !sameOrg) {
|
|
91
91
|
throw new SimpleError({
|
|
92
|
-
code:
|
|
93
|
-
message:
|
|
94
|
-
human:
|
|
95
|
-
statusCode: 400
|
|
96
|
-
})
|
|
92
|
+
code: 'domain_already_used',
|
|
93
|
+
message: 'This domain is already used by another organization',
|
|
94
|
+
human: 'Deze domeinnaam is al in gebruik door een andere vereniging. Neem contact op met Stamhoofd als je denkt dat je toch toegang zou moeten krijgen.',
|
|
95
|
+
statusCode: 400,
|
|
96
|
+
});
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
// Automatically update the dns records already.
|
|
100
100
|
// This domain was already used, so no risk of making DNS-caches dirty
|
|
101
|
-
console.log(
|
|
102
|
-
await webshop.updateDNSRecords()
|
|
101
|
+
console.log('Automatically updating dns records for', cleaned, 'during patch');
|
|
102
|
+
await webshop.updateDNSRecords();
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
if (cleaned.length < 4 || !cleaned.includes(
|
|
106
|
+
if (cleaned.length < 4 || !cleaned.includes('.')) {
|
|
107
107
|
throw new SimpleError({
|
|
108
|
-
code:
|
|
109
|
-
message:
|
|
110
|
-
human:
|
|
111
|
-
field:
|
|
112
|
-
})
|
|
108
|
+
code: 'invalid_field',
|
|
109
|
+
message: 'Invalid domain',
|
|
110
|
+
human: 'Ongeldige domeinnaam',
|
|
111
|
+
field: 'customUrl',
|
|
112
|
+
});
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
webshop.
|
|
118
|
-
webshop.
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
webshop.domain = null;
|
|
118
|
+
webshop.privateMeta.dnsRecords = [];
|
|
119
|
+
webshop.meta.domainActive = false;
|
|
119
120
|
}
|
|
120
121
|
}
|
|
121
122
|
|
|
122
123
|
if (request.body.domainUri !== undefined) {
|
|
123
124
|
if (webshop.domain !== null) {
|
|
124
|
-
webshop.domainUri = request.body.domainUri ??
|
|
125
|
+
webshop.domainUri = request.body.domainUri ?? '';
|
|
125
126
|
|
|
126
|
-
if (webshop.domainUri
|
|
127
|
+
if (webshop.domainUri !== Formatter.slug(webshop.domainUri)) {
|
|
127
128
|
throw new SimpleError({
|
|
128
|
-
code:
|
|
129
|
-
message:
|
|
130
|
-
human:
|
|
131
|
-
field:
|
|
132
|
-
})
|
|
129
|
+
code: 'invalid_field',
|
|
130
|
+
message: 'domainUri contains invalid characters',
|
|
131
|
+
human: 'Een link mag geen spaties, hoofdletters of speciale tekens bevatten',
|
|
132
|
+
field: 'customUrl',
|
|
133
|
+
});
|
|
133
134
|
}
|
|
134
135
|
|
|
135
136
|
// Check exists
|
|
136
137
|
const existing = await Webshop.getByDomain(webshop.domain, webshop.domainUri);
|
|
137
138
|
if (existing !== undefined) {
|
|
138
139
|
throw new SimpleError({
|
|
139
|
-
code:
|
|
140
|
-
message:
|
|
141
|
-
human:
|
|
142
|
-
})
|
|
140
|
+
code: 'invalid_domain',
|
|
141
|
+
message: 'This domain is already in use',
|
|
142
|
+
human: 'Deze link is al in gebruik door een andere webshop: ' + existing.meta.name + '. Verwijder of pas daar de link eerst aan als je die wilt hergebruiken.',
|
|
143
|
+
});
|
|
143
144
|
}
|
|
144
|
-
}
|
|
145
|
-
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
webshop.domainUri = null;
|
|
146
148
|
}
|
|
147
149
|
}
|
|
148
150
|
|
|
149
151
|
if (request.body.legacyUri !== undefined) {
|
|
150
152
|
// Support editing the legacy uri (e.g. delete it, or for older clients)
|
|
151
|
-
webshop.legacyUri = request.body.legacyUri
|
|
153
|
+
webshop.legacyUri = request.body.legacyUri;
|
|
152
154
|
}
|
|
153
155
|
|
|
154
156
|
if (request.body.uri !== undefined) {
|
|
155
157
|
// Validate
|
|
156
158
|
if (request.body.uri.length == 0) {
|
|
157
159
|
throw new SimpleError({
|
|
158
|
-
code:
|
|
159
|
-
message:
|
|
160
|
-
human:
|
|
161
|
-
field:
|
|
162
|
-
})
|
|
160
|
+
code: 'invalid_field',
|
|
161
|
+
message: 'Uri cannot be empty',
|
|
162
|
+
human: 'De link mag niet leeg zijn',
|
|
163
|
+
field: 'uri',
|
|
164
|
+
});
|
|
163
165
|
}
|
|
164
166
|
|
|
165
|
-
if (request.body.uri
|
|
167
|
+
if (request.body.uri !== Formatter.slug(request.body.uri)) {
|
|
166
168
|
throw new SimpleError({
|
|
167
|
-
code:
|
|
168
|
-
message:
|
|
169
|
-
human:
|
|
170
|
-
field:
|
|
171
|
-
})
|
|
169
|
+
code: 'invalid_field',
|
|
170
|
+
message: 'Uri contains invalid characters',
|
|
171
|
+
human: 'Een link mag geen spaties, hoofdletters of speciale tekens bevatten',
|
|
172
|
+
field: 'uri',
|
|
173
|
+
});
|
|
172
174
|
}
|
|
173
175
|
|
|
174
|
-
webshop.uri = request.body.uri
|
|
176
|
+
webshop.uri = request.body.uri;
|
|
175
177
|
}
|
|
176
178
|
|
|
177
179
|
// Verify if we still have full access
|
|
178
180
|
if (!await Context.auth.canAccessWebshop(webshop, PermissionLevel.Full)) {
|
|
179
181
|
throw new SimpleError({
|
|
180
|
-
code:
|
|
181
|
-
message:
|
|
182
|
-
human:
|
|
183
|
-
})
|
|
182
|
+
code: 'missing_permissions',
|
|
183
|
+
message: 'You cannot restrict your own permissions',
|
|
184
|
+
human: 'Je kan je eigen volledige toegang tot deze webshop niet verwijderen (algemeen > toegangsbeheer). Vraag aan een hoofdbeheerder om jouw toegang te verwijderen.',
|
|
185
|
+
});
|
|
184
186
|
}
|
|
185
187
|
|
|
186
188
|
try {
|
|
187
|
-
await webshop.save()
|
|
188
|
-
}
|
|
189
|
+
await webshop.save();
|
|
190
|
+
}
|
|
191
|
+
catch (e) {
|
|
189
192
|
// Duplicate key probably
|
|
190
|
-
if (e.code && e.code ==
|
|
193
|
+
if (e.code && e.code == 'ER_DUP_ENTRY') {
|
|
191
194
|
throw new SimpleError({
|
|
192
|
-
code:
|
|
193
|
-
message:
|
|
194
|
-
human:
|
|
195
|
-
field:
|
|
196
|
-
})
|
|
195
|
+
code: 'invalid_field',
|
|
196
|
+
message: 'Uri already in use',
|
|
197
|
+
human: 'De link die je hebt gekozen is al in gebruik. Kies een andere.',
|
|
198
|
+
field: 'uri',
|
|
199
|
+
});
|
|
197
200
|
}
|
|
198
201
|
throw e;
|
|
199
202
|
}
|
|
200
|
-
|
|
203
|
+
|
|
201
204
|
return new Response(PrivateWebshop.create(webshop));
|
|
202
|
-
})
|
|
205
|
+
});
|
|
203
206
|
}
|
|
204
207
|
}
|