From 9e705ae92efee1a5f21e43e14ca8d7a22ae3d95c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Thu, 29 May 2014 17:24:44 +0200 Subject: [PATCH] models: add default value for Todo.created Modify Todo definition and set `properties.created.default` to `Date.now`. This commit is a follow-up for #7, which moved Todo definition to models.json, but did not configured the default value for `created`. --- models.json | 3 +-- models/todo.js | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/models.json b/models.json index 0a6fd45..d1d94ec 100644 --- a/models.json +++ b/models.json @@ -15,8 +15,7 @@ "default": false }, "created": { - "type": "number", - "//default": "//TODO: Date.now" + "type": "number" } }, "dataSource": "db" diff --git a/models/todo.js b/models/todo.js index 298d181..583b27f 100644 --- a/models/todo.js +++ b/models/todo.js @@ -4,6 +4,8 @@ var async = require('async'); module.exports = function(app) { var Todo = app.models.Todo; + Todo.definition.properties.created.default = Date.now; + Todo.beforeSave = function(next, model) { if (!model.id) model.id = 't-' + Math.floor(Math.random() * 10000).toString(); next();