@warp-works/core
Advanced tools
Comparing version 1.0.0-rc1 to 1.0.0-rc2
const _ = require('lodash'); | ||
// const debug = require('debug')('W2:models:domain'); | ||
const fs = require('fs'); | ||
const Promise = require('bluebird'); | ||
@@ -13,2 +14,7 @@ const Base = require('./base'); | ||
// TODO: Fix this hard-coded value. | ||
function isRolesRelationship(relationship) { | ||
return relationship.name === 'Roles'; | ||
} | ||
class Domain extends Base { | ||
@@ -212,16 +218,32 @@ constructor(warpworks, name, desc, recreate) { | ||
authenticateUser(persistence, UserName, Password) { | ||
// TODO: Not hard-code entity names. | ||
return persistence.aggregate('Account', 'parentID', 'User', '_id', 'userInfo', { UserName, Password }) | ||
.then((users) => { | ||
if (users && users.length === 1) { | ||
const data = _.extend({}, users[0].userInfo[0], { | ||
UserName | ||
}); | ||
// TODO: What else to remove? | ||
delete data.ReadAccess; | ||
delete data.WriteAccess; | ||
return data; | ||
return users[0].userInfo[0]; | ||
} | ||
throw new DomainError("Authentication failed."); | ||
}) | ||
.then((user) => { | ||
const userEntity = this.getEntityByName('User'); | ||
const relationships = userEntity.getRelationships().filter(isRolesRelationship); | ||
return Promise.reduce( | ||
relationships, | ||
(memo, relationship) => relationship.getDocuments(persistence, user) | ||
.then((roles) => memo.concat(roles)), | ||
[] | ||
) | ||
.then((roles) => { | ||
return _.extend({}, _.pick(user, ['_id', 'type', 'Name']), { | ||
UserName, | ||
Roles: roles.map((role) => ({ | ||
type: role.type, | ||
Name: role.Name, | ||
Description: role.Description, | ||
id: role.id, | ||
label: role.Name | ||
})) | ||
}); | ||
}); | ||
}); | ||
@@ -228,0 +250,0 @@ } |
@@ -105,4 +105,8 @@ const Promise = require('bluebird'); | ||
return Promise.map(references, | ||
(reference) => targetEntity.getInstance(persistence, reference.id)); | ||
return Promise.reduce( | ||
this.getTargetReferences(instance), | ||
(memo, reference) => targetEntity.getInstance(persistence, reference._id) | ||
.then((targetInstance) => memo.concat(targetInstance)), | ||
[] | ||
); | ||
} | ||
@@ -109,0 +113,0 @@ |
{ | ||
"name": "@warp-works/core", | ||
"version": "1.0.0-rc1", | ||
"version": "1.0.0-rc2", | ||
"description": "Core library for WarpWorks", | ||
@@ -42,7 +42,7 @@ "main": "lib/index.js", | ||
"eslint-plugin-import": "2.3.0", | ||
"eslint-plugin-node": "4.2.2", | ||
"eslint-plugin-node": "5.0.0", | ||
"eslint-plugin-promise": "3.5.0", | ||
"eslint-plugin-standard": "3.0.1", | ||
"mocha": "3.4.2", | ||
"nyc": "10.3.2" | ||
"nyc": "11.0.2" | ||
}, | ||
@@ -54,4 +54,4 @@ "dependencies": { | ||
"lodash": "4.17.4", | ||
"mongodb": "2.2.27" | ||
"mongodb": "2.2.28" | ||
} | ||
} |
# Releases | ||
## 1.0.0-rc2 - 2017-06-04 | ||
- Fixed `domain.authenticateUser()` with new document structure. | ||
## 1.0.0-rc1 - 2017-05-31 | ||
@@ -4,0 +8,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
123470
35
3036
+ Addedmongodb@2.2.28(transitive)
+ Addedmongodb-core@2.1.12(transitive)
- Removedmongodb@2.2.27(transitive)
- Removedmongodb-core@2.1.11(transitive)
Updatedmongodb@2.2.28