Skip to content

Commit 9dbd353

Browse files
devdev
authored andcommitted
relationship recorded gets created after group and supplier agents have been created during order hook
1 parent 432a405 commit 9dbd353

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

ordering/services/orders.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const feathersKnex = require('feathers-knex')
22
const { iff } = require('feathers-hooks-common')
3-
import { pipe, equals, length, isNil } from 'ramda'
3+
import { pipe, equals, length, isNil, isEmpty } from 'ramda'
44
import * as taskRecipes from '../../tasks/data/recipes'
55

66
module.exports = function () {
@@ -18,7 +18,8 @@ const hooks = {
1818
before: {
1919
create: [
2020
iff(hasNoGroupAgent, createGroupAgent),
21-
iff(hasNoSupplierAgent, createSupplierAgent)
21+
iff(hasNoSupplierAgent, createSupplierAgent),
22+
iff(hasNoRelation, createRelation)
2223
]
2324
},
2425
after: {
@@ -42,6 +43,27 @@ function hasNoGroupAgent (hook) {
4243
return isNil(hook.data.consumerAgentId)
4344
}
4445

46+
function hasNoRelation (hook) {
47+
const relationships = hook.app.service('relationships')
48+
const supplierAgentId = hook.data.supplierAgentId
49+
return relationships.find({ query: { sourceId: supplierAgentId } }).then((relationship)=>{
50+
return isEmpty(relationship)
51+
})
52+
}
53+
54+
function createRelation (hook){
55+
const relationships = hook.app.service('relationships')
56+
const consumerAgentId = hook.data.consumerAgentId
57+
const supplierAgentId = hook.data.supplierAgentId
58+
return relationships.create({
59+
relationshipType: 'supplier',
60+
sourceId: consumerAgentId,
61+
targetId: supplierAgentId
62+
}).then(() => {
63+
return hook
64+
})
65+
}
66+
4567
const hasLengthOne = pipe(length, equals(1))
4668

4769
function hasOneOrder (hook) {

tasks/services/plans.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ function createChildTaskPlans (hook) {
4343
return Promise.all(
4444
childTaskRecipes.map((childTaskRecipe) => {
4545
var params = hook.params[childTaskRecipe.id]
46-
console.log(params, 'the params')
4746
return taskPlans.create({
4847
parentTaskPlanId: hook.result.id,
4948
assigneeId: hook.data.assigneeId,

0 commit comments

Comments
 (0)