ramirez/src/blocked.js

43 lines
833 B
JavaScript
Raw Normal View History

2017-02-09 21:56:36 -05:00
const jsonDb = require('./jsonDb');
2017-02-09 23:36:47 -05:00
/**
* Checks whether userId is blocked
* @param {String} userId
* @returns {Promise<Boolean>}
*/
2017-02-09 21:56:36 -05:00
function isBlocked(userId) {
2017-02-09 23:36:47 -05:00
return jsonDb.get('blocked', []).then(blocked => {
2017-02-09 21:56:36 -05:00
return blocked.indexOf(userId) !== -1;
});
}
2017-02-09 23:36:47 -05:00
/**
* Blocks the given userId
* @param {String} userId
* @returns {Promise}
*/
2017-02-09 21:56:36 -05:00
function block(userId) {
2017-02-09 23:36:47 -05:00
return jsonDb.get('blocked', []).then(blocked => {
2017-02-09 21:56:36 -05:00
blocked.push(userId);
return jsonDb.save('blocked', blocked);
});
}
2017-02-09 23:36:47 -05:00
/**
* Unblocks the given userId
* @param {String} userId
* @returns {Promise}
*/
2017-02-09 21:56:36 -05:00
function unblock(userId) {
2017-02-09 23:36:47 -05:00
return jsonDb.get('blocked', []).then(blocked => {
2017-02-09 21:56:36 -05:00
blocked.splice(blocked.indexOf(userId), 1);
return jsonDb.save('blocked', blocked);
});
}
module.exports = {
isBlocked,
block,
unblock,
};