aboutsummaryrefslogtreecommitdiff
path: root/web/models/points.js
blob: d506900634134e7bd60bf269435d14596746f0be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var mongoose = require('mongoose');

// Mongoose Schema definition
var Schema = mongoose.Schema;
var JsonSchema = new Schema({
  type: String,
  coordinates: Array,
  gender: String,
  age: String,
  race: String,
  longhair: Boolean,
  longbeard: Boolean,
  extra: String,
  status: String
});

// Mongoose Model definition
var Json = mongoose.model('Jstring', JsonSchema, 'pointscollection');

// this function gets ALL the points from the db
// returns the entire document without modifications
exports.get_points = function(callback) {
  Json.find({}).exec(function(err, docs) {
    if (err) callback(err, null);
    callback(null, docs);
  });
}

exports.get_all_active_points = function(callback) {
  var activeStatusTypes = ["new", "pending"];
  Json.find({ status: { $in: activeStatusTypes } }).exec(function(err, docs) {
    if (err) callback(err, null);
    callback(null, docs);
  });
}

// this function stores A user report into the db
exports.save_request = function(data, callback) {
  Json.create(data, function(err, result) {
    if (err) callback(err, null);
    callback(null, result);
  });
}

exports.update_point_status = function(id, newStatus, callback) {
  Json.findByIdAndUpdate(id, {status: newStatus}, {new: true},
    function(err, result) {
      if (err) callback(err, null);
      // result contains the updated point document
      callback(null, result);
    }
  );
}