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(
|
2017-11-25 14:10:18 +05:00
|
|
|
{ id: command.id, isActive: false },
|
2017-11-20 14:32:34 +03:30
|
|
|
Object.assign({}, command, { isActive: false }),
|
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);
|
|
|
|
|
|
|
|
const listCommands = () => Command.find({ isActive: true });
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
addCommand,
|
|
|
|
getCommand,
|
|
|
|
listCommands,
|
|
|
|
removeCommand,
|
|
|
|
updateCommand,
|
|
|
|
};
|