Skip to content

Commit

Permalink
Revises Client Model
Browse files Browse the repository at this point in the history
This commit revises the client model to logout all sessions when resetting.

Signed-off-by: Lui de la Parra <Lui@mutesymphony.com>
  • Loading branch information
Luidog committed Sep 15, 2019
1 parent b63b7d7 commit 40f4263
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
34 changes: 19 additions & 15 deletions src/models/client.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,22 +203,26 @@ class Client extends Document {
* @return {Promise} returns a promise that will either with a message object.
*/
reset() {
const logouts = [];
this.agent.pending = [];
this.agent.queue = [];

this.agent.connection.sessions.forEach(({ id }) =>
logouts.push(this.logout(id))
);
return new Promise((resolve, reject) => {
const logouts = [];
this.agent.queue = [];
this.agent.pending = [];
this.agent.connection.sessions.forEach(({ id }) =>
logouts.push(this.logout(id))
);

return Promise.all(logouts)
.then(results => {
this.agent.connection.sessions = [];
this.save();
})
.then(client => ({
message: 'Client Reset'
}));
Promise.all(logouts)
.then(results => {
this.agent.connection.sessions = [];
return this.save();
})
.then(client =>
resolve({
message: 'Client Reset'
})
)
.catch(error => reject({ message: 'Client Reset Failed' }));
});
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/models/connection.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ class Connection extends EmbeddedDocument {
},
/**
* Open Data API sessions.
* @member Connection#sessions
* @member Connection#starting
* @see {@link Session}
* @type Array
* @type Boolean
*/
starting: {
type: Boolean,
Expand Down

0 comments on commit 40f4263

Please sign in to comment.