2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-28 20:57:52 +00:00

45 lines
811 B
JavaScript
Raw Normal View History

2017-09-22 17:12:39 +02:00
'use strict';
const Datastore = require('nedb-promise');
2017-09-25 16:17:18 +03:30
const Group = new Datastore({
2017-09-22 17:12:39 +02:00
autoload: true,
filename: 'data/Group.db',
2017-09-22 17:12:39 +02:00
});
2017-09-25 16:17:18 +03:30
Group.ensureIndex({
2017-09-22 17:12:39 +02:00
fieldName: 'id',
unique: true,
});
const addGroup = group =>
Group.update({ id: group.id }, group, { upsert: true });
const hideGroup = ({ id }) =>
Group.update({ id }, { $set: { link: '' } });
const updateGroup = group =>
Group.update({ id: group.id }, { $set: group });
2017-09-22 17:12:39 +02:00
const listGroups = () =>
2017-09-25 16:17:18 +03:30
Group.find({});
2017-09-22 17:12:39 +02:00
const listVisibleGroups = () =>
Group.cfind({ $not: { link: '' } }).sort({ title: 1 }).exec();
2017-09-22 17:12:39 +02:00
const managesGroup = group =>
Group.findOne(group);
2017-09-22 17:12:39 +02:00
2017-09-28 22:59:35 +02:00
const removeGroup = ({ id }) =>
Group.remove({ id });
2017-09-22 17:12:39 +02:00
module.exports = {
addGroup,
hideGroup,
2017-09-22 17:12:39 +02:00
listGroups,
listVisibleGroups,
2017-09-22 17:12:39 +02:00
managesGroup,
2017-09-28 22:59:35 +02:00
removeGroup,
updateGroup,
2017-09-22 17:12:39 +02:00
};