Last active
November 17, 2017 06:53
-
-
Save dclarke-modus/868fb14698ba3c625dd4721dc4cd53d8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
await connectionManager.connect(); | |
let client = await connectionManager.getClient().findOne({'client' : 'local'}); | |
let grant = await connectionManager.getGrant().findOne({'name' : 'Client_Credential'}); | |
let service = await connectionManager.getService().findOne({'description' : 'Service 1'}); | |
let ScopeModel = connectionManager.getScope(); | |
let scope = new ScopeModel({client_id : client._id, grant_id : grant._id, service_id : service._id}); | |
await scope.save(); | |
console.log(await connectionManager.getClient().findOne({'client' : 'local'}).populate('scopes')); | |
console.log(await connectionManager.getScope().findOne({})); | |
//The problem here..line #10 doen't show the `scopes` dependency inside `client` model. Below is the actual console log: | |
{ _id: 5a0706cc26b1572d945811b4, | |
name: 'TechStack Solutions Ltd', | |
address: '', | |
city: '', | |
country: 'Trinidad & Tobago', | |
telephone: '', | |
owner: true, | |
url: '', | |
client: 'local', | |
client_secret: 'sha1$4bd4acb6$1$0aba309a6194cd3bc33d83fad09b7dca1bfe464f', | |
email: 'email' } | |
{ _id: 5a0e870a2f013725402ea5dd, __v: 0 } | |
//My Client Schemaimport mongoose from 'mongoose'; | |
let Schema = mongoose.Schema; | |
var ScopeSchema = Schema({ | |
client_id: String, | |
service_id: String, | |
grant_id: String | |
}); | |
ScopeSchema.virtual("client", { | |
ref : 'Client', | |
localField : 'client_id', | |
foreignField : '_id', | |
justOne: true | |
}); | |
ScopeSchema.virtual("service", { | |
ref : 'Service', | |
localField : 'service_id', | |
foreignField : '_id', | |
justOne: true | |
}); | |
ScopeSchema.virtual("grant", { | |
ref : 'Grant', | |
localField : 'grant_id', | |
foreignField : '_id', | |
justOne: true | |
}); | |
export default ScopeSchema;: | |
import mongoose from 'mongoose'; | |
let Schema = mongoose.Schema; | |
let ClientSchema = Schema({ | |
name: String, | |
address: String, | |
city: String, | |
country: String, | |
telephone: String, | |
owner: Boolean, | |
url: String | |
}); | |
ClientSchema.virtual("scopes", { | |
ref : 'Scope', | |
localField : '_id', | |
foreignField : 'client_id', | |
justOne: false | |
}); | |
export default ClientSchema; | |
//My Scope Schema: | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment