remult 0.18.1-exp.8 → 0.18.1-exp.9
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.
|
@@ -125,13 +125,37 @@ testAll("put with validations on entity fails", async ({ remult, createEntity })
|
|
|
125
125
|
x = await s.find({ where: { myId: 1 } });
|
|
126
126
|
expect(x[0].name).toBe('noam');
|
|
127
127
|
});
|
|
128
|
-
testAll("test date with null works", async ({ createEntity }) => {
|
|
128
|
+
testAll("test date only with null works", async ({ createEntity }) => {
|
|
129
129
|
let repo = await createEntity(testDateWithNull);
|
|
130
130
|
let r = repo.create({ id: 0 });
|
|
131
131
|
await r.save();
|
|
132
132
|
r = await repo.findFirst();
|
|
133
133
|
expect(r.d).toBeNull();
|
|
134
134
|
expect(await repo.count({ d: null })).toBe(1);
|
|
135
|
+
r.d = new Date(1976, 5, 16);
|
|
136
|
+
await r.save();
|
|
137
|
+
expect(r.d.getFullYear()).toBe(1976);
|
|
138
|
+
r = await repo.findFirst();
|
|
139
|
+
expect(r.d.getFullYear()).toBe(1976);
|
|
140
|
+
r.d = null;
|
|
141
|
+
await r.save();
|
|
142
|
+
expect(r.d).toBeNull();
|
|
143
|
+
}, false);
|
|
144
|
+
testAll("test date with null works", async ({ createEntity }) => {
|
|
145
|
+
let repo = await createEntity(testDateWithNull);
|
|
146
|
+
let r = repo.create({ id: 0 });
|
|
147
|
+
await r.save();
|
|
148
|
+
r = await repo.findFirst();
|
|
149
|
+
expect(r.fullDate).toBeNull("expected null after");
|
|
150
|
+
expect(await repo.count({ fullDate: null })).toBe(1);
|
|
151
|
+
r.fullDate = new Date(1976, 5, 16);
|
|
152
|
+
await r.save();
|
|
153
|
+
expect(r.fullDate.getFullYear()).toBe(1976);
|
|
154
|
+
r = await repo.findFirst();
|
|
155
|
+
expect(r.fullDate.getFullYear()).toBe(1976);
|
|
156
|
+
r.fullDate = null;
|
|
157
|
+
await r.save();
|
|
158
|
+
expect(r.fullDate).toBeNull();
|
|
135
159
|
}, false);
|
|
136
160
|
testAll("test original value of date", async ({ createEntity }) => {
|
|
137
161
|
let r = await (await createEntity(testDateWithNull)).create({ id: 1, d: new Date(1976, 6, 16) }).save();
|
|
@@ -141,6 +165,7 @@ let testDateWithNull = class testDateWithNull extends EntityBase {
|
|
|
141
165
|
constructor() {
|
|
142
166
|
super(...arguments);
|
|
143
167
|
this.id = 0;
|
|
168
|
+
this.fullDate = null;
|
|
144
169
|
}
|
|
145
170
|
};
|
|
146
171
|
__decorate([
|
|
@@ -151,6 +176,10 @@ __decorate([
|
|
|
151
176
|
Fields.dateOnly({ allowNull: true }),
|
|
152
177
|
__metadata("design:type", Date)
|
|
153
178
|
], testDateWithNull.prototype, "d", void 0);
|
|
179
|
+
__decorate([
|
|
180
|
+
Fields.date({ allowNull: true }),
|
|
181
|
+
__metadata("design:type", Date)
|
|
182
|
+
], testDateWithNull.prototype, "fullDate", void 0);
|
|
154
183
|
testDateWithNull = __decorate([
|
|
155
184
|
Entity('testDateWithNull', { allowApiCrud: true })
|
|
156
185
|
], testDateWithNull);
|
|
@@ -3,6 +3,8 @@ export class ValueConverters {
|
|
|
3
3
|
}
|
|
4
4
|
ValueConverters.Date = {
|
|
5
5
|
toJson: (val) => {
|
|
6
|
+
if (val === null)
|
|
7
|
+
return null;
|
|
6
8
|
if (!val)
|
|
7
9
|
return '';
|
|
8
10
|
if (typeof (val) === "string")
|
|
@@ -15,6 +17,8 @@ ValueConverters.Date = {
|
|
|
15
17
|
}
|
|
16
18
|
},
|
|
17
19
|
fromJson: (val) => {
|
|
20
|
+
if (val === null)
|
|
21
|
+
return null;
|
|
18
22
|
if (val == undefined)
|
|
19
23
|
return undefined;
|
|
20
24
|
if (val == '')
|
|
@@ -70,10 +74,7 @@ ValueConverters.DateOnly = {
|
|
|
70
74
|
} //when using date storage, the database expects and returns a date local and every where else we reflect on date iso
|
|
71
75
|
,
|
|
72
76
|
fromDb: (val) => {
|
|
73
|
-
|
|
74
|
-
if (!d)
|
|
75
|
-
return null;
|
|
76
|
-
return val;
|
|
77
|
+
return ValueConverters.Date.fromDb(val);
|
|
77
78
|
},
|
|
78
79
|
fieldTypeInDb: 'date',
|
|
79
80
|
displayValue: (value) => {
|
package/package.json
CHANGED
|
@@ -347,7 +347,7 @@ db_tests_setup_1.testAll("put with validations on entity fails", function (_a) {
|
|
|
347
347
|
});
|
|
348
348
|
});
|
|
349
349
|
});
|
|
350
|
-
db_tests_setup_1.testAll("test date with null works", function (_a) {
|
|
350
|
+
db_tests_setup_1.testAll("test date only with null works", function (_a) {
|
|
351
351
|
var createEntity = _a.createEntity;
|
|
352
352
|
return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
353
353
|
var repo, r, _b;
|
|
@@ -368,6 +368,60 @@ db_tests_setup_1.testAll("test date with null works", function (_a) {
|
|
|
368
368
|
return [4 /*yield*/, repo.count({ d: null })];
|
|
369
369
|
case 4:
|
|
370
370
|
_b.apply(void 0, [_c.sent()]).toBe(1);
|
|
371
|
+
r.d = new Date(1976, 5, 16);
|
|
372
|
+
return [4 /*yield*/, r.save()];
|
|
373
|
+
case 5:
|
|
374
|
+
_c.sent();
|
|
375
|
+
expect(r.d.getFullYear()).toBe(1976);
|
|
376
|
+
return [4 /*yield*/, repo.findFirst()];
|
|
377
|
+
case 6:
|
|
378
|
+
r = _c.sent();
|
|
379
|
+
expect(r.d.getFullYear()).toBe(1976);
|
|
380
|
+
r.d = null;
|
|
381
|
+
return [4 /*yield*/, r.save()];
|
|
382
|
+
case 7:
|
|
383
|
+
_c.sent();
|
|
384
|
+
expect(r.d).toBeNull();
|
|
385
|
+
return [2 /*return*/];
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
|
+
}, false);
|
|
390
|
+
db_tests_setup_1.testAll("test date with null works", function (_a) {
|
|
391
|
+
var createEntity = _a.createEntity;
|
|
392
|
+
return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
393
|
+
var repo, r, _b;
|
|
394
|
+
return tslib_1.__generator(this, function (_c) {
|
|
395
|
+
switch (_c.label) {
|
|
396
|
+
case 0: return [4 /*yield*/, createEntity(testDateWithNull)];
|
|
397
|
+
case 1:
|
|
398
|
+
repo = _c.sent();
|
|
399
|
+
r = repo.create({ id: 0 });
|
|
400
|
+
return [4 /*yield*/, r.save()];
|
|
401
|
+
case 2:
|
|
402
|
+
_c.sent();
|
|
403
|
+
return [4 /*yield*/, repo.findFirst()];
|
|
404
|
+
case 3:
|
|
405
|
+
r = _c.sent();
|
|
406
|
+
expect(r.fullDate).toBeNull("expected null after");
|
|
407
|
+
_b = expect;
|
|
408
|
+
return [4 /*yield*/, repo.count({ fullDate: null })];
|
|
409
|
+
case 4:
|
|
410
|
+
_b.apply(void 0, [_c.sent()]).toBe(1);
|
|
411
|
+
r.fullDate = new Date(1976, 5, 16);
|
|
412
|
+
return [4 /*yield*/, r.save()];
|
|
413
|
+
case 5:
|
|
414
|
+
_c.sent();
|
|
415
|
+
expect(r.fullDate.getFullYear()).toBe(1976);
|
|
416
|
+
return [4 /*yield*/, repo.findFirst()];
|
|
417
|
+
case 6:
|
|
418
|
+
r = _c.sent();
|
|
419
|
+
expect(r.fullDate.getFullYear()).toBe(1976);
|
|
420
|
+
r.fullDate = null;
|
|
421
|
+
return [4 /*yield*/, r.save()];
|
|
422
|
+
case 7:
|
|
423
|
+
_c.sent();
|
|
424
|
+
expect(r.fullDate).toBeNull();
|
|
371
425
|
return [2 /*return*/];
|
|
372
426
|
}
|
|
373
427
|
});
|
|
@@ -394,6 +448,7 @@ var testDateWithNull = /** @class */ (function (_super) {
|
|
|
394
448
|
function testDateWithNull() {
|
|
395
449
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
396
450
|
_this.id = 0;
|
|
451
|
+
_this.fullDate = null;
|
|
397
452
|
return _this;
|
|
398
453
|
}
|
|
399
454
|
tslib_1.__decorate([
|
|
@@ -404,6 +459,10 @@ var testDateWithNull = /** @class */ (function (_super) {
|
|
|
404
459
|
remult3_1.Fields.dateOnly({ allowNull: true }),
|
|
405
460
|
tslib_1.__metadata("design:type", Date)
|
|
406
461
|
], testDateWithNull.prototype, "d", void 0);
|
|
462
|
+
tslib_1.__decorate([
|
|
463
|
+
remult3_1.Fields.date({ allowNull: true }),
|
|
464
|
+
tslib_1.__metadata("design:type", Date)
|
|
465
|
+
], testDateWithNull.prototype, "fullDate", void 0);
|
|
407
466
|
testDateWithNull = tslib_1.__decorate([
|
|
408
467
|
remult3_1.Entity('testDateWithNull', { allowApiCrud: true })
|
|
409
468
|
], testDateWithNull);
|
package/src/valueConverters.js
CHANGED
|
@@ -8,6 +8,8 @@ var ValueConverters = /** @class */ (function () {
|
|
|
8
8
|
}
|
|
9
9
|
ValueConverters.Date = {
|
|
10
10
|
toJson: function (val) {
|
|
11
|
+
if (val === null)
|
|
12
|
+
return null;
|
|
11
13
|
if (!val)
|
|
12
14
|
return '';
|
|
13
15
|
if (typeof (val) === "string")
|
|
@@ -20,6 +22,8 @@ var ValueConverters = /** @class */ (function () {
|
|
|
20
22
|
}
|
|
21
23
|
},
|
|
22
24
|
fromJson: function (val) {
|
|
25
|
+
if (val === null)
|
|
26
|
+
return null;
|
|
23
27
|
if (val == undefined)
|
|
24
28
|
return undefined;
|
|
25
29
|
if (val == '')
|
|
@@ -75,10 +79,7 @@ var ValueConverters = /** @class */ (function () {
|
|
|
75
79
|
} //when using date storage, the database expects and returns a date local and every where else we reflect on date iso
|
|
76
80
|
,
|
|
77
81
|
fromDb: function (val) {
|
|
78
|
-
|
|
79
|
-
if (!d)
|
|
80
|
-
return null;
|
|
81
|
-
return val;
|
|
82
|
+
return ValueConverters.Date.fromDb(val);
|
|
82
83
|
},
|
|
83
84
|
fieldTypeInDb: 'date',
|
|
84
85
|
displayValue: function (value) {
|