changepin.js 814 Bytes
"use strict";

const commandError = require('./error');
const coreapi = require('../coreapi');

const coreEndpoint = '/terminals/change-password';

function help(keyword) {
    return `Untuk mengganti pin, ketik perintah dengan format: ${ keyword.toUpperCase() }.<PINBARU>.<PINLAMA>`;
}

function execute(tokens, params, cb) {
    
    if (!tokens || tokens.length < 3) {
        const responseParams = {
            body: `${ commandError.ERR_INVALID_FORMAT }. ${ help(tokens[0]) }`
        }

        cb(null, null, responseParams);
        return;
    }

    const coreParams = {
        origin: params.origin,
        asker_terminal_name: params.from,
        asker_terminal_password: tokens[2],
        password: tokens[1]
    };

    coreapi(coreEndpoint, coreParams, 'GET', cb);
}

module.exports = execute;