-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
45 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {Type} from "./Type"; | ||
|
||
/** | ||
* Type of dates. | ||
*/ | ||
export class DateType extends Type<string, Date> | ||
{ | ||
deserialize(value: string): Date | ||
{ | ||
return new Date(value); | ||
} | ||
|
||
serialize(value: Date): string | ||
{ | ||
return value.toISOString(); | ||
} | ||
} | ||
|
||
/** | ||
* Type of dates. | ||
*/ | ||
export const SDate = new DateType(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import {SArray, SDecimal, SModel, SNumeric, SString, Identifier, Model, Property} from "../src"; | ||
import {SArray, SDecimal, SModel, SNumeric, SString, SDate, Identifier, Model, Property} from "../src"; | ||
|
||
/** | ||
* Another test model. | ||
|
@@ -14,13 +14,17 @@ class Author extends Model | |
@Property(SString) | ||
email: string = undefined; | ||
|
||
constructor(name: string = undefined, firstName: string = undefined, email: string = undefined) | ||
@Property(SDate) | ||
createdAt: Date = undefined; | ||
|
||
constructor(name: string = undefined, firstName: string = undefined, email: string = undefined, createdAt: Date = undefined) | ||
{ | ||
super(); | ||
|
||
this.name = name; | ||
this.firstName = firstName; | ||
this.email = email; | ||
this.createdAt = createdAt; | ||
} | ||
} | ||
|
||
|
@@ -51,29 +55,30 @@ it("deserialize", () => { | |
id: 1, | ||
title: "this is a test", | ||
authors: [ | ||
{ name: "DOE", firstName: "John", email: "[email protected]" }, | ||
{ name: "TEST", firstName: "Another", email: "[email protected]" }, | ||
{ name: "DOE", firstName: "John", email: "[email protected]", createdAt: "2022-08-07T08:47:01.000Z", }, | ||
{ name: "TEST", firstName: "Another", email: "[email protected]", createdAt: "2022-09-07T18:32:55.000Z", }, | ||
], | ||
text: "this is a long test.", | ||
evaluation: "25.23", | ||
}).serialize()).toStrictEqual({ | ||
id: 1, | ||
title: "this is a test", | ||
authors: [ | ||
{ name: "DOE", firstName: "John", email: "[email protected]" }, | ||
{ name: "TEST", firstName: "Another", email: "[email protected]" }, | ||
{ name: "DOE", firstName: "John", email: "[email protected]", createdAt: "2022-08-07T08:47:01.000Z", }, | ||
{ name: "TEST", firstName: "Another", email: "[email protected]", createdAt: "2022-09-07T18:32:55.000Z", }, | ||
], | ||
text: "this is a long test.", | ||
evaluation: "25.23", | ||
}); | ||
}); | ||
|
||
it("create and check state then serialize", () => { | ||
const now = new Date(); | ||
const article = new Article(); | ||
article.id = 1; | ||
article.title = "this is a test"; | ||
article.authors = [ | ||
new Author("DOE", "John", "[email protected]"), | ||
new Author("DOE", "John", "[email protected]", now), | ||
]; | ||
article.text = "this is a long test."; | ||
article.evaluation = 25.23; | ||
|
@@ -85,7 +90,7 @@ it("create and check state then serialize", () => { | |
id: 1, | ||
title: "this is a test", | ||
authors: [ | ||
{ name: "DOE", firstName: "John", email: "[email protected]" }, | ||
{ name: "DOE", firstName: "John", email: "[email protected]", createdAt: now.toISOString() }, | ||
], | ||
text: "this is a long test.", | ||
evaluation: "25.23", | ||
|
@@ -98,8 +103,8 @@ it("deserialize then save", () => { | |
id: 1, | ||
title: "this is a test", | ||
authors: [ | ||
{ name: "DOE", firstName: "John", email: "[email protected]" }, | ||
{ name: "TEST", firstName: "Another", email: "[email protected]" }, | ||
{ name: "DOE", firstName: "John", email: "[email protected]", createdAt: new Date(), }, | ||
{ name: "TEST", firstName: "Another", email: "[email protected]", createdAt: new Date(), }, | ||
], | ||
text: "this is a long test.", | ||
evaluation: "25.23", | ||
|
@@ -124,8 +129,8 @@ it("save with modified submodels", () => { | |
id: 1, | ||
title: "this is a test", | ||
authors: [ | ||
{ name: "DOE", firstName: "John", email: "[email protected]" }, | ||
{ name: "TEST", firstName: "Another", email: "[email protected]" }, | ||
{ name: "DOE", firstName: "John", email: "[email protected]", createdAt: new Date(), }, | ||
{ name: "TEST", firstName: "Another", email: "[email protected]", createdAt: new Date(), }, | ||
], | ||
text: "this is a long test.", | ||
evaluation: "25.23", | ||
|