@stamhoofd/backend 2.17.2 → 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.
|
|
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.
|
|
43
|
-
"@stamhoofd/queues": "^2.17.
|
|
44
|
-
"@stamhoofd/sql": "^2.17.
|
|
45
|
-
"@stamhoofd/structures": "^2.17.
|
|
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": "
|
|
63
|
+
"gitHead": "9aa2fbb9c268c4c5c45efd68a9dc55f5d48eb621"
|
|
64
64
|
}
|
|
@@ -10,6 +10,7 @@ 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
|
-
//
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
-
|
|
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([
|