Skip to content

Instantly share code, notes, and snippets.

@ssebro
ssebro / generated-event-consumer.js
Last active November 10, 2015 15:57 — forked from kristofsajdak/complex1.js
Generic template for event consumer
//This is a representation of what would be generated by the generic-event-consumer
var rabbit = require('rabbitConnect');
//Data consumer can be anything that depends on a queue - it's just a placeholder.
var dataConsumer = require('dataConsumer');
//The dataConsumer will dispatch messages to the change handler functions appropriately.
var exchange = rabbit.topic('change.events');
exchange
@ssebro
ssebro / generic-event-consumer.js
Last active November 10, 2015 13:31
Generic template for event consumer
//Please ignore this for now; instead, look at the mixed event consumer. This will be updated to match that format later.
var onChange = require('onChange');
onChange(‘canAlarms’).add({
“insert”:function(data){
if(JSON.parse(data).canAlarms[0].archiveRequested){
return createAndSendCanAlarms(data).catch(function(err){
console.error(err);
throw err;
});
@ssebro
ssebro / a_simple.js
Last active August 29, 2015 14:17
Demo
'use strict';
var Joi = require('joi');
module.exports = function (harvester, swagger, mustbeConfig) {
var category = harvester
.resource('categories', {
name: Joi.string().required().description('a name'),
links: {
@ssebro
ssebro / extended_dsl+auth_as_default_middleware.js
Created March 26, 2015 17:40
extended_dsl+auth_as_default_middleware.js
'use strict';
var Joi = require('joi');
//##OPTION B: authorization as default middleware
module.exports = function (harvestApp, mustbeConfig) {
var customJoiValidationSchema = {query: {myAwesomeParam: Joi.string().required().description('My awesome parameter')}};
var harvestApp = harvestApp
@ssebro
ssebro / extended_dsl+auth_as_add-on_middleware.js
Created March 26, 2015 17:38
extended_dsl+auth_as_add-on_middleware.js
'use strict';
var Joi = require('joi');
//##OPTION A: authorization as add-on middleware
module.exports = function (harvestApp, mustbeConfig) {
var harvestApp = harvestApp
.resource('category', {
name: Joi.string().required().description('a name'),
adapter.update = function (model, id, update) {
return _update(model,id,update);
}
adapter.upsert = function (model, id, update) {
return adapter.update(model,id,update,{upsert:true});
}
adapter.update = function (model, id, update ,options) {
var _this = this;
model = typeof model == 'string' ? this.model(model) : model;
update = this._serialize(model, update);
return new Promise(function (resolve, reject) {
var cb = function (error, resource) {
if (error) {
return reject(error);
}
adapter.upsert = function (model, id, update) {
var _this = this;
model = typeof model == 'string' ? this.model(model) : model;
update = this._serialize(model, update);
return new Promise(function (resolve, reject) {
model.findByIdAndUpdate(id, update,{upsert:true}, function (error, resource) {
if (error) {
return reject(error);
}
_this._handleWrite(model, resource, error, resolve, reject);