mirror of
https://github.com/thedevs-network/the-guard-bot
synced 2025-08-23 10:28:09 +00:00
37 lines
736 B
JavaScript
37 lines
736 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(
|
||
|
{ id: command.id, isActive: false },
|
||
|
{ id: command.id, isActive: false, state: 'add', },
|
||
|
{ 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.find({ isActive: true });
|
||
|
|
||
|
module.exports = {
|
||
|
addCommand,
|
||
|
getCommand,
|
||
|
listCommands,
|
||
|
removeCommand,
|
||
|
updateCommand,
|
||
|
};
|