Skip to content

Commit

Permalink
Dates default to use current time
Browse files Browse the repository at this point in the history
* Fixes previous regression where 'created' models were not working
  • Loading branch information
MKHenson committed Nov 28, 2016
1 parent bbc881f commit 806df30
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
20 changes: 10 additions & 10 deletions src/models/schema-items/schema-date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
export class SchemaDate extends SchemaItem<number> {
public useNow: boolean;

/**
* Creates a new schema item
* @param name The name of this item
* @param val The date of this item. If none is specified the Date.now() number is used.
/**
* Creates a new schema item
* @param name The name of this item
* @param val The date of this item. If none is specified the Date.now() number is used.
* @param useNow [Optional] If true, the date will always be updated to use the current date
*/
constructor( name: string, val: number = 0, useNow: boolean = false ) {
*/
constructor( name: string, val: number = 0, useNow: boolean = true ) {
super( name, val );
this.useNow = useNow;
}
Expand All @@ -23,15 +23,15 @@ export class SchemaDate extends SchemaItem<number> {
* @returns
*/
public clone( copy?: SchemaDate ): SchemaDate {
copy = copy === undefined ? new SchemaDate( this.name, <number>this.value ) : copy;
copy = !copy ? new SchemaDate( this.name, <number>this.value ) : copy;
copy.useNow = this.useNow;
super.clone( copy );
return copy;
}

/**
* Checks the value stored to see if its correct in its current form
*/
/**
* Checks the value stored to see if its correct in its current form
*/
public validate(): Promise<boolean | Error> {
if ( this.useNow )
this.value = Date.now();
Expand Down
3 changes: 2 additions & 1 deletion test/tests/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ describe( 'Testing all post related endpoints', function() {
.string( res.body.data.tags[ 0 ] ).is( "super-tags-1234" )
.string( res.body.data.tags[ 1 ] ).is( "supert-tags-4321" )
.string( res.body.data._id )

.number( res.body.data.createdOn ).isGreaterThan( 0 )
.number( res.body.data.lastUpdated ).isGreaterThan( 0 )

done();
});
Expand Down

0 comments on commit 806df30

Please sign in to comment.