@stamhoofd/backend 2.22.0 → 2.23.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stamhoofd/backend",
3
- "version": "2.22.0",
3
+ "version": "2.23.0",
4
4
  "main": "./dist/index.js",
5
5
  "exports": {
6
6
  ".": {
@@ -36,14 +36,14 @@
36
36
  "@simonbackx/simple-encoding": "2.15.0",
37
37
  "@simonbackx/simple-endpoints": "1.14.0",
38
38
  "@simonbackx/simple-logging": "^1.0.1",
39
- "@stamhoofd/backend-i18n": "2.22.0",
40
- "@stamhoofd/backend-middleware": "2.22.0",
41
- "@stamhoofd/email": "2.22.0",
42
- "@stamhoofd/models": "2.22.0",
43
- "@stamhoofd/queues": "2.22.0",
44
- "@stamhoofd/sql": "2.22.0",
45
- "@stamhoofd/structures": "2.22.0",
46
- "@stamhoofd/utility": "2.22.0",
39
+ "@stamhoofd/backend-i18n": "2.23.0",
40
+ "@stamhoofd/backend-middleware": "2.23.0",
41
+ "@stamhoofd/email": "2.23.0",
42
+ "@stamhoofd/models": "2.23.0",
43
+ "@stamhoofd/queues": "2.23.0",
44
+ "@stamhoofd/sql": "2.23.0",
45
+ "@stamhoofd/structures": "2.23.0",
46
+ "@stamhoofd/utility": "2.23.0",
47
47
  "archiver": "^7.0.1",
48
48
  "aws-sdk": "^2.885.0",
49
49
  "axios": "1.6.8",
@@ -60,5 +60,5 @@
60
60
  "postmark": "4.0.2",
61
61
  "stripe": "^16.6.0"
62
62
  },
63
- "gitHead": "b3590dcb37d7f65be2663b11a6f025cf5f36a278"
63
+ "gitHead": "efcdf16aa2160bcb1fd295d0e5c72751caa3356b"
64
64
  }
@@ -7,7 +7,7 @@ type Query = undefined;
7
7
  type Body = undefined;
8
8
  type ResponseBody = undefined;
9
9
 
10
- export class CreateTokenEndpoint extends Endpoint<Params, Query, Body, ResponseBody> {
10
+ export class DeleteTokenEndpoint extends Endpoint<Params, Query, Body, ResponseBody> {
11
11
  protected doesMatch(request: Request): [true, Params] | [false] {
12
12
  if (request.method != "DELETE") {
13
13
  return [false];
@@ -0,0 +1,58 @@
1
+ import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
2
+
3
+ import { getDefaultEmailFrom, sendEmailTemplate } from '@stamhoofd/models';
4
+ import { EmailTemplateType, Recipient } from '@stamhoofd/structures';
5
+ import { Context } from '../../helpers/Context';
6
+
7
+ type Params = Record<string, never>;
8
+ type Query = undefined;
9
+ type Body = undefined;
10
+ type ResponseBody = undefined;
11
+
12
+ export class DeleteUserEndpoint extends Endpoint<Params, Query, Body, ResponseBody> {
13
+ protected doesMatch(request: Request): [true, Params] | [false] {
14
+ if (request.method != "DELETE") {
15
+ return [false];
16
+ }
17
+
18
+ const params = Endpoint.parseParameters(request.url, "/user", {});
19
+
20
+ if (params) {
21
+ return [true, params as Params];
22
+ }
23
+ return [false];
24
+ }
25
+
26
+ async handle(_: DecodedRequest<Params, Query, Body>) {
27
+ const organization = await Context.setOptionalOrganizationScope()
28
+ const {user, token} = await Context.authenticate({allowWithoutAccount: true})
29
+
30
+ // Send an e-mail to inform everyone about this action
31
+
32
+ // Delete the account
33
+
34
+ const bcc = (await getDefaultEmailFrom(null, {
35
+ template: {}
36
+ }))
37
+ await sendEmailTemplate(organization, {
38
+ recipients: [
39
+ Recipient.create({
40
+ email: user.email
41
+ })
42
+ ],
43
+ singleBcc: bcc.replyTo || bcc.from,
44
+ template: {
45
+ type: EmailTemplateType.DeleteAccountConfirmation,
46
+ },
47
+ type: 'transactional'
48
+ })
49
+
50
+ // Soft delete until processed manually
51
+ user.verified = false;
52
+ user.password = null;
53
+ await user.save()
54
+ await token.delete()
55
+
56
+ return new Response(undefined)
57
+ }
58
+ }
@@ -101,6 +101,10 @@ export class PatchOrganizationEndpoint extends Endpoint<Params, Query, Body, Res
101
101
 
102
102
  if (request.body.privateMeta && request.body.privateMeta.isPatch()) {
103
103
  organization.privateMeta.emails = request.body.privateMeta.emails.applyTo(organization.privateMeta.emails)
104
+ if(request.body.privateMeta.emails) {
105
+ shouldUpdateSetupSteps = true;
106
+ }
107
+
104
108
  organization.privateMeta.premises = patchObject(organization.privateMeta.premises, request.body.privateMeta.premises);
105
109
  if(request.body.privateMeta.premises) {
106
110
  shouldUpdateSetupSteps = true;
@@ -25,6 +25,8 @@ export class SetupStepUpdater {
25
25
  [SetupStepType.Companies]: this.updateStepCompanies,
26
26
  [SetupStepType.Groups]: this.updateStepGroups,
27
27
  [SetupStepType.Premises]: this.updateStepPremises,
28
+ [SetupStepType.Emails]: this.updateStepEmails,
29
+ [SetupStepType.Payment]: this.updateStepPayment
28
30
  };
29
31
 
30
32
  static async updateSetupStepsForAllOrganizationsInCurrentPeriod({
@@ -316,4 +318,35 @@ export class SetupStepUpdater {
316
318
  finishedSteps,
317
319
  });
318
320
  }
321
+
322
+ private static updateStepEmails(setupSteps: SetupSteps,
323
+ organization: Organization,
324
+ _platform: PlatformStruct) {
325
+
326
+ const totalSteps = 1;
327
+ let finishedSteps = 0;
328
+
329
+ const emails = organization.privateMeta.emails;
330
+
331
+ // organization should have 1 default email
332
+ if(emails.some(e => e.default)) {
333
+ finishedSteps = 1;
334
+ }
335
+
336
+ setupSteps.update(SetupStepType.Emails, {
337
+ totalSteps,
338
+ finishedSteps,
339
+ });
340
+
341
+ setupSteps.markReviewed(SetupStepType.Emails, {userId: 'backend', userName: 'backend'});
342
+ }
343
+
344
+ private static updateStepPayment(setupSteps: SetupSteps,
345
+ _organization: Organization,
346
+ _platform: PlatformStruct) {
347
+ setupSteps.update(SetupStepType.Payment, {
348
+ totalSteps: 0,
349
+ finishedSteps: 0,
350
+ });
351
+ }
319
352
  }