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(
|
2018-02-02 15:47:09 +01:00
|
|
|
{ name: command.name },
|
2020-02-19 08:11:32 +01:00
|
|
|
{ $set: { isActive: false, ...command } },
|
2017-10-31 23:08:22 +01:00
|
|
|
{ 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);
|
|
|
|
|
2018-08-15 12:44:06 +02:00
|
|
|
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,
|
|
|
|
};
|