@stamhoofd/backend 2.17.0 → 2.17.3

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.17.0",
3
+ "version": "2.17.3",
4
4
  "main": "./dist/index.js",
5
5
  "exports": {
6
6
  ".": {
@@ -39,10 +39,10 @@
39
39
  "@stamhoofd/backend-i18n": "^2.17.0",
40
40
  "@stamhoofd/backend-middleware": "^2.17.0",
41
41
  "@stamhoofd/email": "^2.17.0",
42
- "@stamhoofd/models": "^2.17.0",
43
- "@stamhoofd/queues": "^2.17.0",
44
- "@stamhoofd/sql": "^2.17.0",
45
- "@stamhoofd/structures": "^2.17.0",
42
+ "@stamhoofd/models": "^2.17.3",
43
+ "@stamhoofd/queues": "^2.17.3",
44
+ "@stamhoofd/sql": "^2.17.3",
45
+ "@stamhoofd/structures": "^2.17.3",
46
46
  "@stamhoofd/utility": "^2.17.0",
47
47
  "archiver": "^7.0.1",
48
48
  "aws-sdk": "^2.885.0",
@@ -60,5 +60,5 @@
60
60
  "postmark": "4.0.2",
61
61
  "stripe": "^16.6.0"
62
62
  },
63
- "gitHead": "5f940486646acd12e23e96a750bc12ca2be4df44"
63
+ "gitHead": "9aa2fbb9c268c4c5c45efd68a9dc55f5d48eb621"
64
64
  }
@@ -5,11 +5,12 @@ import { SimpleError } from '@simonbackx/simple-errors';
5
5
  import { Email } from '@stamhoofd/email';
6
6
  import { ArchiverWriterAdapter, exportToExcel, XlsxTransformerSheet, XlsxWriter } from '@stamhoofd/excel-writer';
7
7
  import { getEmailBuilderForTemplate, Platform, RateLimiter } from '@stamhoofd/models';
8
- import { EmailTemplateType, ExcelExportRequest, ExcelExportResponse, ExcelExportType, LimitedFilteredRequest, PaginatedResponse, Recipient, Replacement } from '@stamhoofd/structures';
8
+ import { EmailTemplateType, ExcelExportRequest, ExcelExportResponse, ExcelExportType, LimitedFilteredRequest, PaginatedResponse, Recipient, Replacement, Version } from '@stamhoofd/structures';
9
9
  import { sleep } from "@stamhoofd/utility";
10
10
  import { Context } from '../../../helpers/Context';
11
11
  import { fetchToAsyncIterator } from '../../../helpers/fetchToAsyncIterator';
12
12
  import { FileCache } from '../../../helpers/FileCache';
13
+ import { QueueHandler } from '@stamhoofd/queues';
13
14
 
14
15
  type Params = { type: string };
15
16
  type Query = undefined;
@@ -62,6 +63,15 @@ export class ExportToExcelEndpoint extends Endpoint<Params, Query, Body, Respons
62
63
  })
63
64
  }
64
65
 
66
+ if (QueueHandler.isRunning('user-export-to-excel-' + user.id)) {
67
+ throw new SimpleError({
68
+ code: "not_allowed",
69
+ message: "Export is pending",
70
+ human: 'Je hebt momenteel al een Excel export lopen. Wacht tot die klaar is voor je een nieuwe export start.',
71
+ statusCode: 403
72
+ })
73
+ }
74
+
65
75
  const loader = ExportToExcelEndpoint.loaders.get(request.params.type as ExcelExportType);
66
76
 
67
77
  if (!loader) {
@@ -137,27 +147,33 @@ export class ExportToExcelEndpoint extends Endpoint<Params, Query, Body, Respons
137
147
  }
138
148
 
139
149
  async job(loader: ExcelExporter<EncodableObject>, request: ExcelExportRequest, type: string): Promise<string> {
140
- // Estimate how long it will take.
141
- // If too long, we'll schedule it and write it to Digitalocean Spaces
142
- // Otherwise we'll just return the file directly
143
- const {file, stream} = await FileCache.getWriteStream('.xlsx');
144
-
145
- const zipWriterAdapter = new ArchiverWriterAdapter(stream);
146
- const writer = new XlsxWriter(zipWriterAdapter);
147
-
148
- // Limit to pages of 100
149
- request.filter.limit = 100;
150
-
151
- await exportToExcel({
152
- definitions: loader.sheets,
153
- writer,
154
- dataGenerator: fetchToAsyncIterator(request.filter, loader),
155
- filter: request.workbookFilter
156
- })
157
-
158
- console.log('Done writing excel file')
159
-
160
- const url = 'https://'+ STAMHOOFD.domains.api + '/file-cache?file=' + encodeURIComponent(file) + '&name=' + encodeURIComponent(type)
161
- return url;
150
+ // Only run 1 export per user at the same time
151
+ return await QueueHandler.schedule('user-export-to-excel-' + Context.user!.id, async () => {
152
+ // Allow maximum 2 running Excel jobs at the same time for all users
153
+ return await QueueHandler.schedule('export-to-excel', async () => {
154
+ // Estimate how long it will take.
155
+ // If too long, we'll schedule it and write it to Digitalocean Spaces
156
+ // Otherwise we'll just return the file directly
157
+ const {file, stream} = await FileCache.getWriteStream('.xlsx');
158
+
159
+ const zipWriterAdapter = new ArchiverWriterAdapter(stream);
160
+ const writer = new XlsxWriter(zipWriterAdapter);
161
+
162
+ // Limit to pages of 100
163
+ request.filter.limit = 100;
164
+
165
+ await exportToExcel({
166
+ definitions: loader.sheets,
167
+ writer,
168
+ dataGenerator: fetchToAsyncIterator(request.filter, loader),
169
+ filter: request.workbookFilter
170
+ })
171
+
172
+ console.log('Done writing excel file')
173
+
174
+ const url = 'https://'+ STAMHOOFD.domains.api + '/v'+ Version +'/file-cache?file=' + encodeURIComponent(file) + '&name=' + encodeURIComponent(type)
175
+ return url;
176
+ }, 2)
177
+ });
162
178
  }
163
179
  }
@@ -16,7 +16,8 @@ export const memberSorters: SQLSortDefinitions<MemberWithRegistrations> = {
16
16
  },
17
17
  'name': {
18
18
  getValue(a) {
19
- return a.details.name
19
+ // Note: we should not use 'name' here (that will remove the in between space if one is missing), because we need to use Exactly the same value as the filter will use
20
+ return a.firstName + ' ' + a.lastName
20
21
  },
21
22
  toSQL: (direction: SQLOrderByDirection): SQLOrderBy => {
22
23
  return SQLOrderBy.combine([