From 8c9457cd8c8d04eeb5853fbe60b5501e29eab7d6 Mon Sep 17 00:00:00 2001 From: GingerPlusPlus Date: Fri, 22 Sep 2017 17:12:39 +0200 Subject: [PATCH] Added groups store --- stores/groups.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 stores/groups.js diff --git a/stores/groups.js b/stores/groups.js new file mode 100644 index 0000000..9fcc476 --- /dev/null +++ b/stores/groups.js @@ -0,0 +1,28 @@ +'use strict'; + +const Datastore = require('nedb-promise'); + +const groups = new Datastore({ + autoload: true, + filename: 'data/groups.db', +}); + +groups.ensureIndex({ + fieldName: 'id', + unique: true, +}); + +const addGroup = group => + groups.insert(group); + +const listGroups = () => + groups.find({}); + +const managesGroup = group => + groups.findOne({ id: group.id }); + +module.exports = { + addGroup, + listGroups, + managesGroup, +};