@izara_project/izara-core-library-service-schemas 1.0.60 → 1.0.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -24,6 +24,7 @@ module.exports = {
24
24
  uploadUseCase: require('./src/libs/UploadUseCase'),
25
25
  relSchemaLib: require('./src/libs/RelSchemaLib'),
26
26
  s3Utils: require('./src/libs/s3Utils'),
27
+ createNodeLib: require('./src/libs/CreateNodeLib'),
27
28
 
28
29
  // .src
29
30
  consts: require('./src/Consts'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@izara_project/izara-core-library-service-schemas",
3
- "version": "1.0.60",
3
+ "version": "1.0.61",
4
4
  "description": "Schemas for the service and objects it controls",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,131 @@
1
+ /*
2
+ Copyright(C) 2021 Sven Mason < http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and / or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or(at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program.If not, see < http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+ const { createRelTypeConcat, createLinkTypeId } = require('../Utils')
20
+ const { findLinksByObjTypes } = require('./RelSchemaLib')
21
+ const getObjectSchema = require('../GetObjectSchema');
22
+
23
+ async function validateRelationshipDirection(_izContext, objType, relationshipProperties) {
24
+ _izContext.logger.debug("function validateRelationshipDirection::", { objType, relationshipProperties });
25
+
26
+ let getObjectRelationship = await getObjectSchema.getRelationshipSchemaWithCache(
27
+ _izContext,
28
+ relationshipProperties.relType
29
+ )
30
+ _izContext.logger.debug("getObjectRelationship", getObjectRelationship);
31
+
32
+ let errorsFound = [];
33
+ let checkCorrectLinks = [];
34
+
35
+ for (const relationshipLink of Object.values(getObjectRelationship.links)) {
36
+ if (relationshipLink.from.linkType === "many" && relationshipLink.to.linkType === "many") {
37
+ if (relationshipLink.from.requiredOnCreate === true || relationshipLink.to.requiredOnCreate === true) {
38
+ errorsFound.push("error many to many linkType can't have requireOnCreate === true")
39
+ }
40
+ }
41
+ }
42
+ const links = await findLinksByObjTypes(_izContext, [objType, relationshipProperties.targetObjType], getObjectRelationship.links);
43
+ _izContext.logger.debug("links", links)
44
+
45
+ if (!links.length) {
46
+ errorsFound.push(`not found link between ${JSON.stringify({ mainObjType: objType })} and ${JSON.stringify({ toObjType: relationshipProperties.targetObjType })} `)
47
+ }
48
+
49
+ for (let link of links) {
50
+ const { serviceTag: fromServiceTag, objectType: fromObjectType } = objType;
51
+ const { serviceTag: toServiceTag, objectType: toObjectType } = relationshipProperties.targetObjType
52
+
53
+ const { serviceTag: firstServiceTag, objectType: firstObjectType } = link.from.objType;
54
+ const { serviceTag: secondServiceTag, objectType: secondObjectType } = link.to.objType
55
+
56
+ const matchesFromTo =
57
+ fromServiceTag === firstServiceTag && fromObjectType === firstObjectType &&
58
+ toServiceTag === secondServiceTag && toObjectType === secondObjectType;
59
+
60
+ const matchesToFrom =
61
+ fromServiceTag === secondServiceTag && fromObjectType === secondObjectType &&
62
+ toServiceTag === firstServiceTag && toObjectType === firstObjectType
63
+
64
+ if ((relationshipProperties.relationshipDirection === "from" && matchesFromTo) ||
65
+ (relationshipProperties.relationshipDirection === "to" && matchesToFrom)) {
66
+ checkCorrectLinks.push(true)
67
+ } else {
68
+ checkCorrectLinks.push(false)
69
+ }
70
+ }
71
+
72
+ for (const [index, checkCorrectLink] of checkCorrectLinks.entries()) {
73
+ if (checkCorrectLink === false) {
74
+ errorsFound.push(`relationship direction ${JSON.stringify(requestParams.relationships[index])} is invalid`)
75
+ }
76
+ }
77
+ return errorsFound;
78
+ }
79
+
80
+ function grouplinkRequireOnCreateByRelType(_izContext, links) {
81
+ let groupLink = {};
82
+ for (let link of links) {
83
+ let relTypeConcat = createRelTypeConcat(_izContext, link.relType);
84
+ if (!groupLink.hasOwnProperty(relTypeConcat)) {
85
+ Object.assign(groupLink, {
86
+ [relTypeConcat]: {
87
+ from: [],
88
+ to: []
89
+ }
90
+ }
91
+ )
92
+ }
93
+
94
+ if (link.base.direction === "from") {
95
+ groupLink[relTypeConcat].from.push(link)
96
+ } else {
97
+ groupLink[relTypeConcat].to.push(link)
98
+ }
99
+ }
100
+ return groupLink
101
+ }
102
+
103
+ function createLinkTypeIdFromLinkGroup(_izContext, linkGroup) {
104
+ let linkTypeIds = new Set();
105
+ for (const objectRelationshipGroup of Object.values(linkGroup)) {
106
+ for (const direction of Object.keys(objectRelationshipGroup)) {
107
+ let objectRelationshipByDirection = objectRelationshipGroup[direction]
108
+ if (objectRelationshipGroup[direction].length) {
109
+ for (const objectRelLink of objectRelationshipGroup[direction]) {
110
+ linkTypeIds.add(createLinkTypeId(
111
+ _izContext,
112
+ objectRelLink?.base?.objType,
113
+ objectRelLink?.other?.objType,
114
+ objectRelLink?.relType,
115
+ objectRelLink?.base?.direction
116
+ ))
117
+ }
118
+ }
119
+ }
120
+ }
121
+ return [...linkTypeIds]
122
+ }
123
+
124
+ function validateLinkTypeFromObjectRelLink(_izContext, links) {
125
+
126
+ }
127
+ module.exports = {
128
+ validateRelationshipDirection,
129
+ grouplinkRequireOnCreateByRelType,
130
+ createLinkTypeIdFromLinkGroup
131
+ }
@@ -433,44 +433,48 @@ async function refRelationshipPerObjectSchema(_izContext, objSchema) {
433
433
  let refObjectRel = {};
434
434
 
435
435
 
436
- if (objSchema.hasOwnProperty("belongTo")) {
437
- Object.assign(
438
- refObjectRel,
439
- {
440
- "createdBy": {
441
- relationshipServiceTag: "UserAccount"
442
- },
443
- "belongTo": {
444
- relationshipServiceTag: "UserAccount"
436
+ if (process.env.iz_serviceTag !== "UserAccount") {
437
+ if (objSchema.hasOwnProperty("belongTo")) {
438
+ Object.assign(
439
+ refObjectRel,
440
+ {
441
+ "createdBy": {
442
+ relationshipServiceTag: "UserAccount"
443
+ },
444
+ "belongTo": {
445
+ relationshipServiceTag: "UserAccount"
446
+ }
445
447
  }
446
- }
447
- )
448
- } else {
449
- Object.assign(
450
- refObjectRel,
451
- {
452
- "createdBy": {
453
- relationshipServiceTag: "UserAccount"
448
+ )
449
+ } else {
450
+ Object.assign(
451
+ refObjectRel,
452
+ {
453
+ "createdBy": {
454
+ relationshipServiceTag: "UserAccount"
455
+ }
454
456
  }
455
- }
456
- )
457
+ )
458
+ }
457
459
  }
458
460
 
459
- if (objSchema?.addOnDataStructure?.length && objSchema.addOnDataStructure.some(addOn => addOn.type === "translation")) {
460
- Object.assign(
461
- refObjectRel,
462
- {
463
- hasTranslationLink: {
464
- relationshipServiceTag: "Translations",
465
- },
466
- currentTranslationLink: {
467
- relationshipServiceTag: "Translations",
468
- },
469
- defaultTranslationLink: {
470
- relationshipServiceTag: "Translations",
471
- },
472
- }
473
- )
461
+ if (process.env.iz_serviceTag !== "Translations") {
462
+ if (objSchema?.addOnDataStructure?.length && objSchema.addOnDataStructure.some(addOn => addOn.type === "translation")) {
463
+ Object.assign(
464
+ refObjectRel,
465
+ {
466
+ hasTranslationLink: {
467
+ relationshipServiceTag: "Translations",
468
+ },
469
+ currentTranslationLink: {
470
+ relationshipServiceTag: "Translations",
471
+ },
472
+ defaultTranslationLink: {
473
+ relationshipServiceTag: "Translations",
474
+ },
475
+ }
476
+ )
477
+ }
474
478
  }
475
479
 
476
480