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