UNPKG

timers3000

Version:

Provides a graphical interface in your browser to create and manage incremental timers for your daily tasks.

86 lines (74 loc) 2.17 kB
var pantexdb = require('pantexdb'); var db = new pantexdb(process.env.TIMERDB, 'timers3000db', ["groups"], false).open(); /** * Create a new group * @param {String} name The groups name * @param {Function} done Function to call when the group was created */ exports.create = function(name, done){ var group = { "name" : name, "color": "#87BB68" }; db.groups.save(group, function(err, obj){ if(err) console.warn(err); return done(group._id); }); } /** * Delete a group * @param {String} id The group's id * @param {Function} done Function to call when the group was deleted */ exports.delete = function(id, done){ db.groups.delete({_id: id}, function(err){ if(err) console.warn(err); return done(); }); } /** * Finds the group to the specified id * @param {String} id The group id * @param {Function} done the callback function */ exports.getGroup = function(id, done){ db.groups.findOne({"_id":id},function(err, group){ if(err || !group){ return done(err,null); }else{ return done(null,group); } }); } /** * Get all groups * @param {Function} done Function to call when all groups are grabbed */ exports.getGroups = function(done){ db.groups.find({}, function(err, groups){ if(err) console.warn(err); done(groups); }); } /** * Change the color of a group * @param {String} id The group's id * @param {String} color The new color in hex-format * @param {Function} done Function to call when the color was changed */ exports.changeColor = function(id,color,done){ db.groups.update(id,{"color" : color},function(err,group){ if(err) console.log(err); return done(color); }); } /** * Change the name of a group * @param {String} id the group's id * @param {String} name the new name * @param {Function} done Function to call when the group was renamed */ exports.renameGroup = function(id,name,done){ db.groups.update(id,{"name" : name},function(err,group){ if(err) console.log(err); return done(); }); }