Skip to content

Instantly share code, notes, and snippets.

@nazt
Forked from anonymous/gist:3447056
Created August 24, 2012 07:21
Show Gist options
  • Save nazt/3447057 to your computer and use it in GitHub Desktop.
Save nazt/3447057 to your computer and use it in GitHub Desktop.
function cashcardController(fire, options, message, exchange, queue) {
this.startState = 'idle';
this.states = {
'idle': {
entry: function () {
console.log("===> IDLE --");
this.url = "http://localhost:8080/cashcard/state/getUserInfo/5";
return 'request01';
},
},
'request01': {
timeout: 5 * 1000,
entry: function () {
console.log("===> ENTRY REQUEST01 --");
fire.request({url: this.url});
},
actions: {
timeout: function() {
return ['timeoutState', false];
},
'.done': 'setTx',
'.err': function (err) {
console.log("!!! request ERROR !!!")
return 'errorState'
}
}
},
'setTx': {
timeout: 5 * 1000,
entry: function (response, body) {
console.log("===> SET TX")
fire.txService.setPropertyMap({pass: true});
},
actions: {
timeout: 'timeoutState',
'.done': 'insertTx',
'.err': function (err) {
console.log("setTx ERROR")
return ['errorState', false]
}
}
},
'insertTx': {
timeout: 5 * 1000,
entry: function () {
console.log("===> INSERT TX STATE")
var taxId = "taxIdSUCCESS"
, status = "STATUS"
, detail = "DETAIL"
, SUCC_STATUS = "FAILED";
this.txObj = {
taxId: taxId,
details:detail,
resultDisplayCode: '1',
resultDisplay: SUCC_STATUS,
resultStatusDetails: detail,
simNumber: options.mobileNo,
simBalance: -1,
sequence: message.sequence
}
fire.dbService.insertTx({pass: false});
},
actions: {
timeout: 'timeoutState',
'.done': 'finishState',
'.err': function (err) {
console.log("insertTx ERROR")
return 'errorState'
}
}
},
'finishState': {
entry: function () {
console.log("--- FINISHED ---")
}
},
'timeoutState': {
entry: function () {
console.log(" ___ IN TIMEOUT STATE ___ ");;
}
},
'errorState': {
entry: function (err) {
console.log(" !!!! ___ IN ERROR STATE ___ !!!! ")
console.log(err);
/*
CREATE TABLE transaction_exception_db (
machine_id character varying(6) NOT NULL,
phone_number character varying(15) NOT NULL,
type_menu character varying(2) NOT NULL,
provider character varying(2) NOT NULL,
result_code character varying(100) DEFAULT NULL::character varying,
result_status_details text,
req_date_time timestamp with time zone NOT NULL,
sequence character varying(20) NOT NULL,
menu integer,
money integer,
user_balance integer DEFAULT 0
);
*/
/*
var FAIL_STATUS = config.status.fail;
status: "SERVER ?"
detail: "SERVER ?"
simNumber: options.mobileNo -- ตู้
resultDisplayCode: '0' -- Hard Code?
resultDisPlay: CONSTANT
sequence: message.sequence -- ตู้
*/
var status = "STATUS"
, detail = "DETAIL"
, FAIL_STATUS = "FAILED";
this.txObj = {
resultStatus: status,
resultStatusDetails:detail,
simNumber: options.mobileNo,
resultDisplayCode: '0',
resultDisplay: FAIL_STATUS,
sequence: message.sequence
}
}
}
}
}
module.exports = cashcardController;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment