Created
April 25, 2018 09:59
-
-
Save mayfer/d30adaaf5b64df79199e86915ba2d5fd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CashorbitEvent { | |
constructor() { | |
this.version = 0; | |
} | |
validate(payload) { | |
if (!event_hub || (!this.version && this.version !== 0) || !this.vote_schema) { | |
throw new Error('Spiel_feedback requires event_hub, vote_type, version.'); | |
} | |
let {error} = Joi.validate(payload, this.vote_schema); | |
if (error) { | |
console.error('Spiel_feedback validation error: ', error); | |
throw error; | |
} | |
} | |
async emit({payload, responders}) { | |
this.validate(payload) | |
return await event_hub.add_event({type: this.event_name, version: this.version, payload, responders}); | |
} | |
// only use this if you need a response/confirmation back | |
async emit_and_respond({payload, responders}) { | |
if(!responders || responders.length == 0) { | |
responders = this.default_responders; | |
} | |
return await this.emit({payload, responders}) | |
} | |
} | |
class SpielFeedbackReason extends CashorbitEvent { | |
constructor() { | |
super() | |
this.event_name = event_registry.spiel_feedback.reason; | |
this.default_responders = ['spiel_feedback_reason']; | |
this.vote_schema = Joi.object().keys({ | |
user_id: Joi.number().required(), | |
spiel_id: Joi.string().required(), | |
reason_id: Joi.number().required(), | |
type: Joi.string().required(), | |
from_channel: Joi.string().optional(), | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment