-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopyEntityPath.js
35 lines (27 loc) · 1.02 KB
/
copyEntityPath.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var getCompiler = require('cerebral-url-scheme-compiler/get')
var setCompiler = require('cerebral-url-scheme-compiler/set')
function copyEntityPath (entityType, uuidPath, copyPath) {
var getUuid = getCompiler(uuidPath)
var setValue = setCompiler(copyPath)
function action (args) {
var module = args.modules['cerebral-module-entities']
var uuid = getUuid(args)
var entityPath = null
if (!uuid) {
throw Error('cerebral-module-entities: The UUID can not be found at path ' + uuidPath)
}
if (module.state.get([entityType, uuid])) {
entityPath = [entityType, uuid]
} else if (module.state.get(['ids', entityType, uuid])) {
uuid = module.state.get(['ids', entityType, uuid])
if (!uuid) {
throw Error('cerebral-module-entities: The UUID can not be found ' + uuidPath)
}
entityPath = [entityType, uuid]
}
setValue(args, entityPath)
}
action.displayName = 'entities.copyEntityPath (' + entityType + ')'
return action
}
module.exports = copyEntityPath