-
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
Felipe Klerk Signorini
committed
Aug 24, 2017
1 parent
d78d7ad
commit dfb1406
Showing
12 changed files
with
105 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
const _ = require('lodash'); | ||
|
||
const DRelationsSyncerService = require('core/services/RelationsSyncerService'); | ||
|
||
|
||
const RelationsApp = (Entity, REntity, RelationsSyncerService = DRelationsSyncerService) => { | ||
|
||
return { | ||
syncer: (req, res, next) => { | ||
const source = 'params.id'; | ||
|
||
RelationsSyncerService(Entity)(REntity) | ||
.syncer(req, source) | ||
.then(e => res.json(e)) | ||
.catch(next); | ||
} | ||
|
||
}; | ||
}; | ||
|
||
module.exports = _.curry(RelationsApp); |
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
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,35 @@ | ||
'use strict'; | ||
|
||
const _ = require('lodash'); | ||
const DBRepository = require('core/repositories/DBRepository'); | ||
const {transfID} = require('core/applications/transforms/strIDtoObjectID'); | ||
|
||
|
||
const RelationsSyncerService = (Entity) => (REntity) => { | ||
|
||
return { | ||
syncer: (data, source = '_id') => { | ||
|
||
return new Promise((resolve, reject) => { | ||
|
||
const _id = _.get(transfID(data, source), source); | ||
const path = `${Entity.name}._id`; | ||
|
||
const fielder = `${REntity.name}_count`; | ||
|
||
DBRepository(REntity) | ||
.count({[path]:_id}, [path]) | ||
.then(total => { | ||
return DBRepository(Entity) | ||
.update({_id}, {[fielder]: total}) | ||
.catch(console.log); | ||
}) | ||
.then(resolve) | ||
.catch(reject); | ||
}); | ||
} | ||
|
||
}; | ||
}; | ||
|
||
module.exports = RelationsSyncerService; |
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
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