@lenne.tech/nest-server 9.2.8 → 9.3.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": "@lenne.tech/nest-server",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.3.0",
|
|
4
4
|
"description": "Modern, fast, powerful Node.js web framework in TypeScript based on Nest with a GraphQL API and a connection to MongoDB (or other databases).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node",
|
|
@@ -5,7 +5,7 @@ import { Kind } from 'graphql';
|
|
|
5
5
|
* Date scalar to convert string into date
|
|
6
6
|
*/
|
|
7
7
|
@Scalar('Date', (type) => Date)
|
|
8
|
-
export class DateScalar implements CustomScalar<
|
|
8
|
+
export class DateScalar implements CustomScalar<string, Date> {
|
|
9
9
|
description = 'Date custom scalar type';
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -18,17 +18,46 @@ export class DateScalar implements CustomScalar<number, Date> {
|
|
|
18
18
|
/**
|
|
19
19
|
* Serialize value to send to the client
|
|
20
20
|
*/
|
|
21
|
-
serialize(value: Date):
|
|
22
|
-
return value.
|
|
21
|
+
serialize(value: Date): string {
|
|
22
|
+
return value.toISOString(); // value sent to the client
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Parse value from the client query
|
|
27
27
|
*/
|
|
28
28
|
parseLiteral(ast: any): Date {
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
// Check value
|
|
30
|
+
if (ast.value === undefined || ast.value === null) {
|
|
31
|
+
return ast.value;
|
|
31
32
|
}
|
|
32
|
-
|
|
33
|
+
|
|
34
|
+
// Check nullable
|
|
35
|
+
if (!ast.value) {
|
|
36
|
+
throw new Error('Invalid value for date');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Check value type
|
|
40
|
+
if (ast.kind !== Kind.INT && ast.kind !== Kind.STRING) {
|
|
41
|
+
throw new Error('Invalid value type for date');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Check format if value is a string
|
|
45
|
+
if (ast.kind === Kind.STRING && isNaN(Date.parse(ast.value))) {
|
|
46
|
+
throw new Error('Invalid ISO 8601 format for date');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Create date from value
|
|
50
|
+
const date = new Date(ast.value);
|
|
51
|
+
|
|
52
|
+
// Check value
|
|
53
|
+
if (date.toString() === 'Invalid Date') {
|
|
54
|
+
throw new Error('Invalid value for date');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Check if range is valid
|
|
58
|
+
date.toISOString();
|
|
59
|
+
|
|
60
|
+
// Return date if everything is fine
|
|
61
|
+
return date;
|
|
33
62
|
}
|
|
34
63
|
}
|