2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-22 09:57:50 +00:00
the-guard-bot/stores/command.js
2020-02-19 08:11:32 +01:00

39 lines
743 B
JavaScript

'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 }
);
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();
module.exports = {
addCommand,
getCommand,
listCommands,
removeCommand,
updateCommand,
};