Created
January 12, 2015 05:55
-
-
Save ciscoheat/2ea2034a239024c89547 to your computer and use it in GitHub Desktop.
Problem with creating a Mongoose model
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
package; | |
import js.npm.mongoose.macro.Manager; | |
import js.npm.mongoose.macro.Model; | |
typedef AttractionSchema = { | |
name: String, | |
description: String, | |
location: { lat: Float, lng: Float }, | |
history: { | |
event: String, | |
?notes: String, | |
email: String, | |
date: Date, | |
}, | |
?updateId: String, | |
approved: Bool | |
} | |
class AttractionManager extends Manager<AttractionSchema, Attraction> {} | |
class Attraction extends Model<AttractionSchema> | |
{ | |
public static function build(db) { | |
return AttractionManager.build(db, "Attraction"); | |
} | |
} |
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
package; | |
public class Main | |
{ | |
static function main() { | |
var db = null; // Get the mongoose db from somewhere | |
var attractions = Attraction.build(db); | |
var body = { | |
lat: 45.516011, | |
lng: -122.682062, | |
name: 'Portland Art Museum', | |
description: 'Founded in 1892, the Portland Art Museum\'s colleciton ' + | |
'of native art is not to be missed. If modern art is more to your ' + | |
'liking, there are six stories of modern art for your enjoyment.', | |
email: '[email protected]', | |
}; | |
// This doesn't compile to "new attractions({...})" | |
// because of the call to Date | |
attractions.construct({ | |
name: name, | |
description: body.description, | |
location: { lat: body.lat, lng: body.lng }, | |
history: { | |
event: 'created', | |
email: body.email, | |
date: Date.now() // Problem! | |
}, | |
approved: false | |
}).save(); | |
// This works: | |
var d = Date.now(); | |
attractions.construct({ | |
name: body.name, | |
description: body.description, | |
location: { lat: body.lat, lng: body.lng }, | |
history: { | |
event: 'created', | |
email: body.email, | |
date: d // Working when using a variable | |
}, | |
approved: false | |
}).save(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment