2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-23 10:28:09 +00:00
the-guard-bot/stores/command.js

38 lines
735 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(
{ id: command.id, isActive: false },
Object.assign({}, command, { isActive: false }),
{ 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.find({ isActive: true });
module.exports = {
addCommand,
getCommand,
listCommands,
removeCommand,
updateCommand,
};