2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-24 02:47:48 +00:00

52 lines
950 B
JavaScript
Raw Permalink 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 = (query = {}) =>
Group.find(query);
2017-09-22 17:12:39 +02:00
const listVisibleGroups = () =>
Group.find({ $not: { link: '' } });
2017-09-22 17:12:39 +02:00
const managesGroup = group =>
Group.findOne(group);
2017-09-22 17:12:39 +02:00
2020-05-26 13:23:54 +02:00
const migrateGroup = (oldId, newId) =>
Group.update(
{ id: oldId, type: 'group' },
{ $set: { id: newId, type: 'supergroup' } },
);
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,
2020-05-26 13:23:54 +02:00
migrateGroup,
2017-09-28 22:59:35 +02:00
removeGroup,
updateGroup,
2017-09-22 17:12:39 +02:00
};