Update Application model for the push notification
This commit is contained in:
parent
26d0f74d66
commit
bfffd839a7
|
@ -217,3 +217,4 @@ loopback.Model = require('./models/model');
|
|||
loopback.Email = require('./models/email');
|
||||
loopback.User = require('./models/user');
|
||||
loopback.Session = require('./models/session');
|
||||
loopback.Application = require('./models/application');
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
var loopback = require('../loopback');
|
||||
var assert = require('assert');
|
||||
|
||||
// Authentication schemes
|
||||
var AuthenticationSchemeSchema = {
|
||||
scheme: String, // local, facebook, google, twitter, linkedin, github
|
||||
credential: Object // Scheme-specific credentials
|
||||
}
|
||||
};
|
||||
|
||||
var APNSSettingSchema = {
|
||||
pushOptions: {type: {
|
||||
|
@ -27,13 +28,13 @@ var PushNotificationSettingSchema = {
|
|||
platform: {type: String, required: true}, // apns, gcm, mpns
|
||||
// configuration: {type: Object} // platform-specific configurations
|
||||
apns: APNSSettingSchema
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Data model for Application
|
||||
*/
|
||||
var ApplicationSchema = {
|
||||
|
||||
id: {type: String, id: true, generated: true},
|
||||
// Basic information
|
||||
name: {type: String, required: true}, // The name
|
||||
description: String, // The description
|
||||
|
@ -59,7 +60,7 @@ var ApplicationSchema = {
|
|||
masterKey: String,
|
||||
|
||||
// Push notification
|
||||
pushSettings: [PushNotificationSettingSchema],
|
||||
pushSettings: PushNotificationSettingSchema,
|
||||
|
||||
// User Authentication
|
||||
authenticationEnabled: {type: Boolean, default: true},
|
||||
|
@ -90,16 +91,13 @@ function generateKey(hmacKey, algorithm, encoding) {
|
|||
return hmac.digest('base64');
|
||||
}
|
||||
|
||||
module.exports = function (dataSource) {
|
||||
dataSource = dataSource || new require('loopback-datasource-juggler').ModelBuilder();
|
||||
|
||||
// var AuthenticationScheme = dataSource.define('AuthenticationScheme', AuthenticationSchemeSchema);
|
||||
// ApplicationSchema.authenticationSchemes = [AuthenticationScheme];
|
||||
|
||||
// var PushNotificationSetting = dataSource.define('PushNotificationSetting', PushNotificationSettingSchema);
|
||||
// ApplicationSchema.pushSettings = [PushNotificationSetting];
|
||||
|
||||
var Application = dataSource.define('Application', ApplicationSchema);
|
||||
var Application = loopback.createModel('Application', ApplicationSchema);
|
||||
|
||||
// Application.hasMany(AuthenticationScheme, {as: 'authenticationSchemes', foreignKey: 'appId'});
|
||||
// Application.hasMany(PushNotificationSetting, {as: 'pushNotificationSettings', foreignKey: 'appId'});
|
||||
|
@ -140,7 +138,7 @@ module.exports = function (dataSource) {
|
|||
}
|
||||
}
|
||||
Application.create(props, cb);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Reset keys for the application instance
|
||||
|
@ -154,7 +152,7 @@ module.exports = function (dataSource) {
|
|||
this.masterKey = generateKey('master');
|
||||
this.modified = new Date();
|
||||
this.save(cb);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Reset keys for a given application by the appId
|
||||
|
@ -169,7 +167,7 @@ module.exports = function (dataSource) {
|
|||
}
|
||||
app.resetKeys(cb);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -191,10 +189,10 @@ module.exports = function (dataSource) {
|
|||
});
|
||||
cb && cb(null, matched);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Application;
|
||||
|
||||
return Application;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
var models = require('../lib/models');
|
||||
var loopback = require(('../'));
|
||||
var assert = require('assert');
|
||||
|
||||
var dataSource = loopback.createDataSource('db', {connector: loopback.Memory});
|
||||
|
||||
var Application = models.Application(dataSource);
|
||||
var Application = loopback.Application;
|
||||
Application.attachTo(dataSource);
|
||||
|
||||
describe('Application', function () {
|
||||
var registeredApp = null;
|
||||
|
|
Loading…
Reference in New Issue