-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement a way for consumers to add model hooks #228
Comments
Copy&paste of an IRC conversation with my proposal for this:
I'd like to dedicate this issue to implement the mechanism to allow consumers to add model hooks. In the end, the consumer should be able to do something like: const bodyParser = require('body-parser');
const express = require('express');
const SensorThings = require('../dist/sensorthings');
const Clients = require('myclientsmodel');
var app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
const config = {
db: {
host: 'localhost',
port: 5432,
name: 'sensorthingsexample',
user: 'postgres',
password: '12345678'
}
};
const dbHooks = {
beforeCreate: (instance, options, fn) => { ... },
beforeDestroy: (instance, options, fn) => { ... },
beforeUpdate: null,
beforeSave: (instance, options, fn) => {
//XXX Mostly pseudocode!
if (instance.$modelOptions.name.plural !== 'Things' || !instance.clientId) {
return;
}
return Clients.getById(instance.clientId).then(client => {
instance.properties = Object.assign({}, instance.properties, {
MozillaSensorWebOwner: client.name
});
});
},
beforeUpsert: (values, options, fn) => { ... }
};
app.use('/', SensorThings(config, dbHooks));
app.listen(8080, () => console.log('Running on localhost:8080')); |
Fixed by #235 |
The user story SSB-7 says "As a user I would like to be able to understand the source of data that I am viewing. (LASS, other source, Sensorweb device) so that I can judge the credibility and see the source of the information."
The text was updated successfully, but these errors were encountered: