2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-22 18:08:51 +00:00
the-guard-bot/stores/command.js

39 lines
743 B
JavaScript
Raw Normal View History

2017-10-04 20:55:50 +03:30
'use strict';
const Datastore = require('nedb-promise');
const Command = new Datastore({
autoload: true,
filename: 'data/Command.db',
});
Command.ensureIndex({
fieldName: 'name',
unique: true,
});
const addCommand = command =>
Command.update(
{ name: command.name },
{ $set: { isActive: false, ...command } },
{ upsert: true }
);
2017-10-04 20:55:50 +03:30
const updateCommand = (data) =>
Command.update({ id: data.id, isActive: false }, { $set: data });
const removeCommand = command => Command.remove(command);
const getCommand = (data) => Command.findOne(data);
const listCommands = () =>
Command.cfind({ isActive: true }).sort({ name: 1 }).exec();
2017-10-04 20:55:50 +03:30
module.exports = {
addCommand,
getCommand,
listCommands,
removeCommand,
updateCommand,
};