Commit acc486decb77b68b460b3435610795c917368a96
1 parent
e63322c4
Exists in
master
and in
1 other branch
Adicionado a primeira parte do banco de dados, configuracoes do mongo
Showing
3 changed files
with
63 additions
and
0 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,36 @@ |
| 1 | +function read_all(Request, callback) { | |
| 2 | + Request.find(function(err, requests) { | |
| 3 | + if (err) callback(null); | |
| 4 | + | |
| 5 | + callback(requests); | |
| 6 | + }); | |
| 7 | +}; | |
| 8 | + | |
| 9 | +function create(object, callback) { | |
| 10 | + object.save(function(err, request) { | |
| 11 | + if (err) callback(null); | |
| 12 | + | |
| 13 | + callback(request); | |
| 14 | + }); | |
| 15 | +}; | |
| 16 | + | |
| 17 | +function update(object, status, callback) { | |
| 18 | + object.update({}, { $set : { 'type' : status }}, function (err, request) { | |
| 19 | + if (err) callback(null); | |
| 20 | + callback(request); | |
| 21 | + }); | |
| 22 | +} | |
| 23 | + | |
| 24 | +function remove(Request, hash, callback) { | |
| 25 | + Request.remove({ id: hash }, function(err, request) { | |
| 26 | + if (err) callback(null); | |
| 27 | + | |
| 28 | + callback(request); | |
| 29 | + }); | |
| 30 | +}; | |
| 31 | + | |
| 32 | +module.exports.read_all = read_all; | |
| 33 | +module.exports.create = create; | |
| 34 | +module.exports.remove = remove; | |
| 35 | +module.exports.update = update; | |
| 36 | + | ... | ... |
| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | +function connectMongo(mongoose) { | |
| 2 | + var db = mongoose.connection; | |
| 3 | + | |
| 4 | + db.on('error', console.error); | |
| 5 | + db.once('open', function() { | |
| 6 | + console.log('Conectado ao MongoDB.') | |
| 7 | + }); | |
| 8 | + | |
| 9 | + mongoose.connect('mongodb://localhost/vlibras-api'); | |
| 10 | +}; | |
| 11 | + | |
| 12 | +module.exports.connect = connectMongo; | |
| 0 | 13 | \ No newline at end of file | ... | ... |
| ... | ... | @@ -0,0 +1,15 @@ |
| 1 | +function init_schema(mongoose) { | |
| 2 | + var requestSchema = new mongoose.Schema({ | |
| 3 | + id: String, | |
| 4 | + status: String, | |
| 5 | + type: String, | |
| 6 | + created_at: { type: Date }, | |
| 7 | + updated_at: { type: Date } | |
| 8 | + }); | |
| 9 | + | |
| 10 | + var Request = mongoose.model('Request', requestSchema); | |
| 11 | + | |
| 12 | + return Request; | |
| 13 | +}; | |
| 14 | + | |
| 15 | +module.exports.init = init_schema; | |
| 0 | 16 | \ No newline at end of file | ... | ... |