Last change
on this file since 416 was
415,
checked in by hendrikvanantwerpen, 12 years ago
|
Support data validation and increase dendency separation.
Added json-schema validation before documents are saved. Acts both as
a safe-guard and as a reference of the data model.
Added directory for server related material. For now it contains scripts
to configure CouchDB and check validity of documents against the schema.
Started separating out parts that depend on the data model from parts
that do not.
|
File size:
847 bytes
|
Line | |
---|
1 | define([ |
---|
2 | 'dojo/date/stamp', |
---|
3 | 'dojox/json/schema', |
---|
4 | './schema', |
---|
5 | './store/CouchStore' |
---|
6 | ],function(stamp,jsonSchema,schema,CouchStore){ |
---|
7 | |
---|
8 | var store = new CouchStore({ |
---|
9 | target: 'data/couch/', |
---|
10 | validate: function(object) { |
---|
11 | var result = jsonSchema.validate(object,schema); |
---|
12 | if ( result.valid ) { |
---|
13 | return true; |
---|
14 | } else { |
---|
15 | console.log("Found error ",result," for invalid object ",object); |
---|
16 | return false; |
---|
17 | } |
---|
18 | } |
---|
19 | }); |
---|
20 | store.formatDate = function(date){ |
---|
21 | return stamp.toISOString(date,{zulu:true}); |
---|
22 | }; |
---|
23 | store.parseDate = function(dateString){ |
---|
24 | return stamp.fromISOString(dateString); |
---|
25 | }; |
---|
26 | store.timestamp = function() { |
---|
27 | return this.formatDate(new Date()); |
---|
28 | }; |
---|
29 | return store; |
---|
30 | |
---|
31 | }); |
---|
Note: See
TracBrowser
for help on using the repository browser.