Register mediators

Closes #147 

@rcrichton if you could please review?
I agree on the concept but if people skip versions of the mediator things
will get out of wack. Unless we version the updates, and include all
previous updates. That seems to be getting too complex though...

Sent from my Android phone.
On 25 Sep 2014 11:59, "Hannes Venter" <notifications@github.com> wrote:

> In src/api/mediators.coffee:
>
> > +				message: 'UUID is required'
> > +			}
> > +		}
> > +
> > +		if (!mediator.version || !semver.valid(mediator.version)) {
> > +			throw {
> > +				name: 'ValidationError',
> > +				message: 'Version is required. Must be in SemVer form x.y.z'
> > +			}
> > +		}
> > +
> > +		var existing = yield Mediator.findOne({uuid: mediator.uuid}).exec()
> > +		if (typeof existing !== "undefined" && existing !== null) {
> > +			if (semver.gt(mediator.version, existing.version)) {
> > +				yield Mediator.findByIdAndUpdate(existing._id, mediator).exec();
> > +			}
>
> Yeah, I was also worried about overriding any changes someone may have
> made to the existing channel. To me the 'running' channel trumps default
> config; but then again a newer version of a mediator may want changes to
> the channel config...
>
> Maybe we should treat updates with a different field in the registration
> message? e.g.
>
> {
>   defaultChannelConfig: [ ... ] //Only applied for new mediators. Must contain full channel info
>   channelConfigUpdate: [ ... ] //Applied if version incremented. May only contain subset of fields
> }
>
> So at the end of the day, defaultChannelConfig equates to a mongo insert
> while config updates equate to a mongo update?
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/jembi/openhim-core-js/pull/203/files#r18023639>.
>