-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ddb8f3
commit 2074ad0
Showing
18 changed files
with
279 additions
and
144 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
'use strict' | ||
|
||
const Client = function (service) { | ||
return {} | ||
} | ||
const Client = service => ({ | ||
}) | ||
|
||
module.exports = Client |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
'use strict' | ||
|
||
const user = require('./commands/user') | ||
const refreshToken = require('./commands/refreshToken') | ||
|
||
const Commands = function (service, models, client) { | ||
return { | ||
user: user.Commands(service, models, client) | ||
} | ||
} | ||
const Commands = (service, models, client) => ({ | ||
user: user.Commands(service, models, client), | ||
refreshToken: refreshToken.Commands(service, models, client) | ||
}) | ||
|
||
module.exports = Commands |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
'use strict' | ||
|
||
const user = require('./models/user') | ||
const refreshToken = require('./models/refreshToken') | ||
|
||
const Models = function (service) { | ||
return { | ||
User: user.Model(service) | ||
} | ||
} | ||
const Models = service => ({ | ||
User: user.Model(service), | ||
RefreshToken: refreshToken.Model(service) | ||
}) | ||
|
||
module.exports = Models |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict' | ||
|
||
const randToken = require('rand-token') | ||
|
||
const templates = require('../templates') | ||
const utils = require('../utils') | ||
|
||
const Commands = (service, models, client) => { | ||
const add = userData => { | ||
const token = new models.RefreshToken({ | ||
token: randToken.generate(32), | ||
_user: userData._id | ||
}) | ||
return token.save() | ||
.catch(error => utils.transformValidationErrors(error, service)) | ||
.then(() => service.tracer.debug(templates.refreshTokenAdded(userData))) | ||
.then(() => Promise.resolve(token)) | ||
} | ||
|
||
const remove = token => models.RefreshToken.deleteOne({token}) | ||
|
||
const getUser = token => models.RefreshToken.find({token}) | ||
.then(tokenData => { | ||
if (tokenData) { | ||
return models.User.findById(tokenData._user) | ||
} | ||
return Promise.reject(new service.errors.NotFound(templates.refreshTokenNotFound())) | ||
}) | ||
|
||
return { | ||
add, | ||
remove, | ||
getUser | ||
} | ||
} | ||
|
||
module.exports = { | ||
Commands | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.