@adminforth/many2many 1.0.6 → 1.0.8
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/dist/index.js +34 -11
- package/index.ts +34 -11
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -84,34 +84,47 @@ export default class extends AdminForthPlugin {
|
|
|
84
84
|
};
|
|
85
85
|
resourceConfig.columns.push(virtualColumn);
|
|
86
86
|
// ** HOOKS FOR CREATE **//
|
|
87
|
-
resourceConfig.hooks.create.afterSave.push((_a) => __awaiter(this, [_a], void 0, function* ({ recordId, recordWithVirtualColumns }) {
|
|
87
|
+
resourceConfig.hooks.create.afterSave.push((_a) => __awaiter(this, [_a], void 0, function* ({ recordId, recordWithVirtualColumns, adminUser }) {
|
|
88
88
|
if (recordWithVirtualColumns[`many2many_${this.pluginInstanceId}`]) {
|
|
89
89
|
for (const linkedId of recordWithVirtualColumns[`many2many_${this.pluginInstanceId}`]) {
|
|
90
|
-
yield this.adminforth.
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
yield this.adminforth.createResourceRecord({
|
|
91
|
+
resource: junctionResource,
|
|
92
|
+
record: {
|
|
93
|
+
[resourceColumnNameInJunctionResource]: recordId,
|
|
94
|
+
[linkedColumnNameInJunctionResource]: linkedId,
|
|
95
|
+
},
|
|
96
|
+
adminUser
|
|
93
97
|
});
|
|
94
98
|
}
|
|
95
99
|
}
|
|
96
100
|
return { ok: true };
|
|
97
101
|
}));
|
|
98
102
|
// ** HOOKS FOR EDIT **//
|
|
99
|
-
resourceConfig.hooks.edit.beforeSave.push((_a) => __awaiter(this, [_a], void 0, function* ({ recordId, updates }) {
|
|
103
|
+
resourceConfig.hooks.edit.beforeSave.push((_a) => __awaiter(this, [_a], void 0, function* ({ recordId, updates, adminUser }) {
|
|
100
104
|
if (updates[`many2many_${this.pluginInstanceId}`]) {
|
|
101
105
|
const existingJunctionRecords = yield this.adminforth.resource(junctionResource.resourceId).list([Filters.EQ(resourceColumnNameInJunctionResource, recordId)]);
|
|
102
106
|
const updatedLinkedIds = updates[`many2many_${this.pluginInstanceId}`];
|
|
103
107
|
for (const jr of existingJunctionRecords) {
|
|
104
108
|
const linkedId = jr[linkedColumnNameInJunctionResource];
|
|
105
109
|
if (!updatedLinkedIds.includes(linkedId)) {
|
|
106
|
-
yield this.adminforth.
|
|
110
|
+
yield this.adminforth.deleteResourceRecord({
|
|
111
|
+
resource: junctionResource,
|
|
112
|
+
recordId: jr[junctionResource.columns.find(c => c.primaryKey).name],
|
|
113
|
+
record: jr,
|
|
114
|
+
adminUser
|
|
115
|
+
});
|
|
107
116
|
}
|
|
108
117
|
}
|
|
109
118
|
for (const linkedId of updatedLinkedIds) {
|
|
110
119
|
const alreadyExists = existingJunctionRecords.find(jr => jr[linkedColumnNameInJunctionResource] === linkedId);
|
|
111
120
|
if (!alreadyExists) {
|
|
112
|
-
yield this.adminforth.
|
|
113
|
-
|
|
114
|
-
|
|
121
|
+
yield this.adminforth.createResourceRecord({
|
|
122
|
+
resource: junctionResource,
|
|
123
|
+
record: {
|
|
124
|
+
[resourceColumnNameInJunctionResource]: recordId,
|
|
125
|
+
[linkedColumnNameInJunctionResource]: linkedId,
|
|
126
|
+
},
|
|
127
|
+
adminUser
|
|
115
128
|
});
|
|
116
129
|
}
|
|
117
130
|
}
|
|
@@ -123,7 +136,12 @@ export default class extends AdminForthPlugin {
|
|
|
123
136
|
resourceConfig.hooks.delete.beforeSave.push((_a) => __awaiter(this, [_a], void 0, function* ({ recordId, record }) {
|
|
124
137
|
const existingJunctionRecords = yield this.adminforth.resource(junctionResource.resourceId).list([Filters.EQ(resourceColumnNameInJunctionResource, recordId)]);
|
|
125
138
|
for (const jr of existingJunctionRecords) {
|
|
126
|
-
yield this.adminforth.
|
|
139
|
+
yield this.adminforth.deleteResourceRecord({
|
|
140
|
+
resource: junctionResource,
|
|
141
|
+
recordId: jr[junctionResource.columns.find(c => c.primaryKey).name],
|
|
142
|
+
record: jr,
|
|
143
|
+
adminUser: null
|
|
144
|
+
});
|
|
127
145
|
}
|
|
128
146
|
return { ok: true };
|
|
129
147
|
}));
|
|
@@ -131,7 +149,12 @@ export default class extends AdminForthPlugin {
|
|
|
131
149
|
linkedResource.hooks.delete.beforeSave.push((_a) => __awaiter(this, [_a], void 0, function* ({ recordId, record }) {
|
|
132
150
|
const existingJunctionRecords = yield this.adminforth.resource(junctionResource.resourceId).list([Filters.EQ(linkedColumnNameInJunctionResource, recordId)]);
|
|
133
151
|
for (const jr of existingJunctionRecords) {
|
|
134
|
-
yield this.adminforth.
|
|
152
|
+
yield this.adminforth.deleteResourceRecord({
|
|
153
|
+
resource: junctionResource,
|
|
154
|
+
recordId: jr[junctionResource.columns.find(c => c.primaryKey).name],
|
|
155
|
+
record: jr,
|
|
156
|
+
adminUser: null
|
|
157
|
+
});
|
|
135
158
|
}
|
|
136
159
|
return { ok: true };
|
|
137
160
|
}));
|
package/index.ts
CHANGED
|
@@ -81,12 +81,16 @@ export default class extends AdminForthPlugin {
|
|
|
81
81
|
|
|
82
82
|
// ** HOOKS FOR CREATE **//
|
|
83
83
|
|
|
84
|
-
resourceConfig.hooks.create.afterSave.push(async ({ recordId, recordWithVirtualColumns }) => {
|
|
84
|
+
resourceConfig.hooks.create.afterSave.push(async ({ recordId, recordWithVirtualColumns, adminUser }) => {
|
|
85
85
|
if ( recordWithVirtualColumns[`many2many_${this.pluginInstanceId}`] ) {
|
|
86
86
|
for(const linkedId of recordWithVirtualColumns[`many2many_${this.pluginInstanceId}`]) {
|
|
87
|
-
await this.adminforth.
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
await this.adminforth.createResourceRecord({
|
|
88
|
+
resource: junctionResource,
|
|
89
|
+
record: {
|
|
90
|
+
[resourceColumnNameInJunctionResource]: recordId,
|
|
91
|
+
[linkedColumnNameInJunctionResource]: linkedId,
|
|
92
|
+
},
|
|
93
|
+
adminUser
|
|
90
94
|
});
|
|
91
95
|
}
|
|
92
96
|
}
|
|
@@ -95,22 +99,31 @@ export default class extends AdminForthPlugin {
|
|
|
95
99
|
|
|
96
100
|
// ** HOOKS FOR EDIT **//
|
|
97
101
|
|
|
98
|
-
resourceConfig.hooks.edit.beforeSave.push(async ({recordId, updates }: { recordId: any, updates: any }) => {
|
|
102
|
+
resourceConfig.hooks.edit.beforeSave.push(async ({recordId, updates, adminUser }: { recordId: any, updates: any, adminUser: any }) => {
|
|
99
103
|
if ( updates[`many2many_${this.pluginInstanceId}`] ) {
|
|
100
104
|
const existingJunctionRecords = await this.adminforth.resource(junctionResource.resourceId).list([Filters.EQ(resourceColumnNameInJunctionResource, recordId)]);
|
|
101
105
|
const updatedLinkedIds = updates[`many2many_${this.pluginInstanceId}`];
|
|
102
106
|
for(const jr of existingJunctionRecords) {
|
|
103
107
|
const linkedId = jr[linkedColumnNameInJunctionResource];
|
|
104
108
|
if ( !updatedLinkedIds.includes(linkedId) ) {
|
|
105
|
-
await this.adminforth.
|
|
109
|
+
await this.adminforth.deleteResourceRecord({
|
|
110
|
+
resource: junctionResource,
|
|
111
|
+
recordId: jr[junctionResource.columns.find(c => c.primaryKey).name],
|
|
112
|
+
record: jr,
|
|
113
|
+
adminUser
|
|
114
|
+
});
|
|
106
115
|
}
|
|
107
116
|
}
|
|
108
117
|
for(const linkedId of updatedLinkedIds) {
|
|
109
118
|
const alreadyExists = existingJunctionRecords.find(jr => jr[linkedColumnNameInJunctionResource] === linkedId);
|
|
110
119
|
if ( !alreadyExists ) {
|
|
111
|
-
await this.adminforth.
|
|
112
|
-
|
|
113
|
-
|
|
120
|
+
await this.adminforth.createResourceRecord({
|
|
121
|
+
resource: junctionResource,
|
|
122
|
+
record: {
|
|
123
|
+
[resourceColumnNameInJunctionResource]: recordId,
|
|
124
|
+
[linkedColumnNameInJunctionResource]: linkedId,
|
|
125
|
+
},
|
|
126
|
+
adminUser
|
|
114
127
|
});
|
|
115
128
|
}
|
|
116
129
|
}
|
|
@@ -123,7 +136,12 @@ export default class extends AdminForthPlugin {
|
|
|
123
136
|
resourceConfig.hooks.delete.beforeSave.push(async ({ recordId, record }: { recordId: any, record: any }) => {
|
|
124
137
|
const existingJunctionRecords = await this.adminforth.resource(junctionResource.resourceId).list([Filters.EQ(resourceColumnNameInJunctionResource, recordId)]);
|
|
125
138
|
for(const jr of existingJunctionRecords) {
|
|
126
|
-
await this.adminforth.
|
|
139
|
+
await this.adminforth.deleteResourceRecord({
|
|
140
|
+
resource: junctionResource,
|
|
141
|
+
recordId: jr[junctionResource.columns.find(c => c.primaryKey).name],
|
|
142
|
+
record: jr,
|
|
143
|
+
adminUser: null
|
|
144
|
+
});
|
|
127
145
|
}
|
|
128
146
|
return { ok: true };
|
|
129
147
|
});
|
|
@@ -131,7 +149,12 @@ export default class extends AdminForthPlugin {
|
|
|
131
149
|
linkedResource.hooks.delete.beforeSave.push(async ({ recordId, record }: { recordId: any, record: any }) => {
|
|
132
150
|
const existingJunctionRecords = await this.adminforth.resource(junctionResource.resourceId).list([Filters.EQ(linkedColumnNameInJunctionResource, recordId)]);
|
|
133
151
|
for(const jr of existingJunctionRecords) {
|
|
134
|
-
await this.adminforth.
|
|
152
|
+
await this.adminforth.deleteResourceRecord({
|
|
153
|
+
resource: junctionResource,
|
|
154
|
+
recordId: jr[junctionResource.columns.find(c => c.primaryKey).name],
|
|
155
|
+
record: jr,
|
|
156
|
+
adminUser: null
|
|
157
|
+
});
|
|
135
158
|
}
|
|
136
159
|
return { ok: true };
|
|
137
160
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adminforth/many2many",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -44,6 +44,6 @@
|
|
|
44
44
|
"semantic-release-slack-bot": "^4.0.2"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"adminforth": "
|
|
47
|
+
"adminforth": "next"
|
|
48
48
|
}
|
|
49
49
|
}
|