This file contains 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
//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 |
This file contains 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
//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; | |
}); |
This file contains 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
'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: { |
This file contains 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
'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 |
This file contains 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
'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'), |
This file contains 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
adapter.update = function (model, id, update) { | |
return _update(model,id,update); | |
} |
This file contains 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
adapter.upsert = function (model, id, update) { | |
return adapter.update(model,id,update,{upsert:true}); | |
} |
This file contains 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
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); | |
} |
This file contains 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
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); |