From 05d072a3657790847f6df6dae1cea0190ef1a077 Mon Sep 17 00:00:00 2001 From: Tom Kruijsen Date: Fri, 5 Apr 2013 16:12:40 +0200 Subject: [PATCH] Move dbToJson to Location --- cli.coffee | 2 +- lib/lib.coffee | 5 ----- lib/models.coffee | 7 +++++++ web.coffee | 3 +-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/cli.coffee b/cli.coffee index e9fa64e..d1c1385 100644 --- a/cli.coffee +++ b/cli.coffee @@ -15,7 +15,7 @@ app.config.defaults({ Location.connect(app.config.get('MONGOHQ_URL')) read = -> - Waterdata.dbToJson (error, res) -> + Location.toJson (error, res) -> console.log res Location.db.close() diff --git a/lib/lib.coffee b/lib/lib.coffee index ef4da11..b3b82ef 100644 --- a/lib/lib.coffee +++ b/lib/lib.coffee @@ -54,11 +54,6 @@ Waterdata = writeToDb: (object, callback) -> Location.update {lokatie:object.lokatie}, object, {upsert: true}, callback - # Turn the database into json. Dynamic for now. - dbToJson: (callback) -> - Location.find {}, '-_id', (error, res) -> - callback(error, res) - processWaterdata: (callback) -> # get the zipfile console.log 'Starting' diff --git a/lib/models.coffee b/lib/models.coffee index 310f02e..2505676 100644 --- a/lib/models.coffee +++ b/lib/models.coffee @@ -11,8 +11,15 @@ schema = mongoose.Schema { }, laatstBijgewerkt: String } + Location = mongoose.model 'Location', schema + Location.connect = (url) -> mongoose.connect(url) +# Turn the database into json. Dynamic for now. +Location.toJson = (callback) -> + Location.find {}, '-_id', (error, res) -> + callback(error, res) + exports.Location = Location diff --git a/web.coffee b/web.coffee index e158754..95dc6a4 100644 --- a/web.coffee +++ b/web.coffee @@ -1,5 +1,4 @@ flatiron = require 'flatiron' -Waterdata = require('./lib/lib').Waterdata Location = require('./lib/models').Location app = flatiron.app @@ -14,7 +13,7 @@ app.config.defaults({ Location.connect(app.config.get('MONGOHQ_URL')) read = -> - Waterdata.dbToJson (error, json) => + Location.toJson (error, json) => @res.writeHead(200, {'Content-Type': 'application/json'}) @res.write JSON.stringify(json) @res.end()