Skip to content

Commit

Permalink
Some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
niekcandaele committed Jul 4, 2020
1 parent ec70189 commit 7fc2f05
Showing 1 changed file with 3 additions and 19 deletions.
22 changes: 3 additions & 19 deletions api/helpers/sdtd/validate-item-name.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
var sevenDays = require('machinepack-7daystodiewebapi');

const SdtdApi = require('7daystodie-api-wrapper')

module.exports = {


friendlyName: 'Validate item name',


description: 'checks if a given item name is valid for a server',


inputs: {

serverId: {
Expand All @@ -27,18 +18,13 @@ module.exports = {

},


exits: {
success: {
outputFriendlyName: 'Success',
outputType: 'boolean'
},


},



fn: async function (inputs, exits) {

let server = await SdtdServer.findOne(inputs.serverId);
Expand All @@ -51,13 +37,11 @@ module.exports = {
const itemsFound = (await sails.helpers.sdtdApi.executeConsoleCommand(server, `listitems ${inputs.itemName}`))
.result
.split('\n')
.map(itemName => itemName.trim());


const itemFound = !!itemsFound.filter(_ => _ === inputs.itemName).length;
.map(itemName => itemName.trim());

const isItemValid = !!itemsFound.filter(foundItem => foundItem === inputs.itemName).length;

return exits.success(itemFound);
return exits.success(isItemValid);
} catch (e) {
exits.error(e);
}
Expand Down

0 comments on commit 7fc2f05

Please sign in to comment.