@lucaapp/service-utils 1.61.1 → 1.61.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/dist/lib/api/endpoint.js +26 -19
- package/dist/lib/money/money.d.ts +2 -2
- package/dist/lib/money/money.js +12 -8
- package/package.json +1 -1
package/dist/lib/api/endpoint.js
CHANGED
|
@@ -167,7 +167,7 @@ async function stream2buffer(stream) {
|
|
|
167
167
|
stream.on('error', error => reject(error));
|
|
168
168
|
});
|
|
169
169
|
}
|
|
170
|
-
function handleMultipleFileUpload(request) {
|
|
170
|
+
async function handleMultipleFileUpload(request) {
|
|
171
171
|
return new Promise((resolve, reject) => {
|
|
172
172
|
const bb = (0, busboy_1.default)({
|
|
173
173
|
headers: request.headers,
|
|
@@ -178,26 +178,33 @@ function handleMultipleFileUpload(request) {
|
|
|
178
178
|
},
|
|
179
179
|
});
|
|
180
180
|
const files = [];
|
|
181
|
-
bb.once('error', error =>
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
const { encoding, mimeType: mimetype, filename: name } = filename;
|
|
181
|
+
bb.once('error', error => reject(error));
|
|
182
|
+
const filePromises = [];
|
|
183
|
+
bb.on('file', async (fieldname, fileStream, fileInfo) => {
|
|
184
|
+
const { encoding, mimeType: mimetype, filename: name } = fileInfo;
|
|
186
185
|
const originalName = Buffer.from(name, 'latin1').toString('utf8');
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
186
|
+
const filePromise = stream2buffer(fileStream).then(fileBuffer => {
|
|
187
|
+
const file = {
|
|
188
|
+
buffer: fileBuffer,
|
|
189
|
+
originalname: originalName,
|
|
190
|
+
encoding,
|
|
191
|
+
mimetype,
|
|
192
|
+
size: fileBuffer.length,
|
|
193
|
+
fieldname,
|
|
194
|
+
filename: name,
|
|
195
|
+
};
|
|
196
|
+
files.push(file);
|
|
197
|
+
});
|
|
198
|
+
filePromises.push(filePromise);
|
|
198
199
|
});
|
|
199
|
-
bb.once('finish', () => {
|
|
200
|
-
|
|
200
|
+
bb.once('finish', async () => {
|
|
201
|
+
try {
|
|
202
|
+
await Promise.all(filePromises);
|
|
203
|
+
resolve(files);
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
reject(error);
|
|
207
|
+
}
|
|
201
208
|
});
|
|
202
209
|
request.pipe(bb);
|
|
203
210
|
});
|
|
@@ -21,6 +21,8 @@ export declare class Money<T extends SupportedCurrencies = SupportedCurrencies>
|
|
|
21
21
|
static fromAmount<T extends SupportedCurrencies>(value: number, currency: T): Money<T>;
|
|
22
22
|
static fromFloat<T extends SupportedCurrencies>(value: number, currency: T): Money<T>;
|
|
23
23
|
static zero<T extends SupportedCurrencies>(currency: T): Money<T>;
|
|
24
|
+
static min<T extends SupportedCurrencies>(value1: Money<T>, value2: Money<T>): Money<T>;
|
|
25
|
+
static max<T extends SupportedCurrencies>(value1: Money<T>, value2: Money<T>): Money<T>;
|
|
24
26
|
private constructor();
|
|
25
27
|
clone(): Money<T>;
|
|
26
28
|
getAmount(): number;
|
|
@@ -40,8 +42,6 @@ export declare class Money<T extends SupportedCurrencies = SupportedCurrencies>
|
|
|
40
42
|
isZero(): boolean;
|
|
41
43
|
isPositive(): boolean;
|
|
42
44
|
isNegative(): boolean;
|
|
43
|
-
min(comparator: Money<T>): Money<T>;
|
|
44
|
-
max(comparator: Money<T>): Money<T>;
|
|
45
45
|
}
|
|
46
46
|
export declare const moneyfiedGet: <T extends SupportedCurrencies>(model: Model, key: string) => Money<T> | null;
|
|
47
47
|
export declare const moneyfiedSet: <T extends SupportedCurrencies>(model: Model, key: string, value: Money<T> | undefined) => void;
|
package/dist/lib/money/money.js
CHANGED
|
@@ -23,6 +23,18 @@ class Money {
|
|
|
23
23
|
static zero(currency) {
|
|
24
24
|
return Money.fromAmount(0, currency);
|
|
25
25
|
}
|
|
26
|
+
static min(value1, value2) {
|
|
27
|
+
if (value1.lessThan(value2)) {
|
|
28
|
+
return value1;
|
|
29
|
+
}
|
|
30
|
+
return value2;
|
|
31
|
+
}
|
|
32
|
+
static max(value1, value2) {
|
|
33
|
+
if (value1.greaterThan(value2)) {
|
|
34
|
+
return value1;
|
|
35
|
+
}
|
|
36
|
+
return value2;
|
|
37
|
+
}
|
|
26
38
|
constructor(amount, currency) {
|
|
27
39
|
if (!currency) {
|
|
28
40
|
throw new TypeError('currency required');
|
|
@@ -113,14 +125,6 @@ class Money {
|
|
|
113
125
|
isNegative() {
|
|
114
126
|
return this.value < 0;
|
|
115
127
|
}
|
|
116
|
-
min(comparator) {
|
|
117
|
-
this.assertSameCurrency(comparator);
|
|
118
|
-
return this.value < comparator.value ? this.clone() : comparator.clone();
|
|
119
|
-
}
|
|
120
|
-
max(comparator) {
|
|
121
|
-
this.assertSameCurrency(comparator);
|
|
122
|
-
return this.value > comparator.value ? this.clone() : comparator.clone();
|
|
123
|
-
}
|
|
124
128
|
}
|
|
125
129
|
exports.Money = Money;
|
|
126
130
|
const moneyfiedGet = (model, key) => {
|