@adminforth/many2many 1.1.0 → 1.1.1
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 +7 -4
- package/index.ts +7 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -134,27 +134,27 @@ export default class extends AdminForthPlugin {
|
|
|
134
134
|
}));
|
|
135
135
|
// ** HOOKS FOR DELETE **//
|
|
136
136
|
if (!this.options.dontDeleteJunctionRecords) {
|
|
137
|
-
resourceConfig.hooks.delete.beforeSave.push((_a) => __awaiter(this, [_a], void 0, function* ({ recordId, record }) {
|
|
137
|
+
resourceConfig.hooks.delete.beforeSave.push((_a) => __awaiter(this, [_a], void 0, function* ({ recordId, record, adminUser }) {
|
|
138
138
|
const existingJunctionRecords = yield this.adminforth.resource(junctionResource.resourceId).list([Filters.EQ(resourceColumnNameInJunctionResource, recordId)]);
|
|
139
139
|
for (const jr of existingJunctionRecords) {
|
|
140
140
|
yield this.adminforth.deleteResourceRecord({
|
|
141
141
|
resource: junctionResource,
|
|
142
142
|
recordId: jr[junctionResource.columns.find(c => c.primaryKey).name],
|
|
143
143
|
record: jr,
|
|
144
|
-
adminUser
|
|
144
|
+
adminUser
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
147
|
return { ok: true };
|
|
148
148
|
}));
|
|
149
149
|
const linkedResource = this.adminforth.config.resources.find(r => r.resourceId === this.options.linkedResourceId);
|
|
150
|
-
linkedResource.hooks.delete.beforeSave.push((_a) => __awaiter(this, [_a], void 0, function* ({ recordId, record }) {
|
|
150
|
+
linkedResource.hooks.delete.beforeSave.push((_a) => __awaiter(this, [_a], void 0, function* ({ recordId, record, adminUser }) {
|
|
151
151
|
const existingJunctionRecords = yield this.adminforth.resource(junctionResource.resourceId).list([Filters.EQ(linkedColumnNameInJunctionResource, recordId)]);
|
|
152
152
|
for (const jr of existingJunctionRecords) {
|
|
153
153
|
yield this.adminforth.deleteResourceRecord({
|
|
154
154
|
resource: junctionResource,
|
|
155
155
|
recordId: jr[junctionResource.columns.find(c => c.primaryKey).name],
|
|
156
156
|
record: jr,
|
|
157
|
-
adminUser
|
|
157
|
+
adminUser
|
|
158
158
|
});
|
|
159
159
|
}
|
|
160
160
|
return { ok: true };
|
|
@@ -176,6 +176,9 @@ export default class extends AdminForthPlugin {
|
|
|
176
176
|
path: `/plugin/${this.pluginInstanceId}/get-junctionResource-records`,
|
|
177
177
|
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body }) {
|
|
178
178
|
const { recordId, returnLabels } = body;
|
|
179
|
+
if (recordId === undefined || recordId === null || recordId === '') {
|
|
180
|
+
return { ok: true, data: [] };
|
|
181
|
+
}
|
|
179
182
|
const junctionRecords = yield this.adminforth.resource(junctionResource.resourceId).list([Filters.EQ(resourceColumnNameInJunctionResource, recordId)]);
|
|
180
183
|
let dataToReturn = [];
|
|
181
184
|
const junctionResourcePkColumn = junctionResource.columns.find(c => c.primaryKey);
|
package/index.ts
CHANGED
|
@@ -134,27 +134,27 @@ export default class extends AdminForthPlugin {
|
|
|
134
134
|
|
|
135
135
|
// ** HOOKS FOR DELETE **//
|
|
136
136
|
if (!this.options.dontDeleteJunctionRecords) {
|
|
137
|
-
resourceConfig.hooks.delete.beforeSave.push(async ({ recordId, record }: { recordId: any, record: any }) => {
|
|
137
|
+
resourceConfig.hooks.delete.beforeSave.push(async ({ recordId, record, adminUser }: { recordId: any, record: any, adminUser: any }) => {
|
|
138
138
|
const existingJunctionRecords = await this.adminforth.resource(junctionResource.resourceId).list([Filters.EQ(resourceColumnNameInJunctionResource, recordId)]);
|
|
139
139
|
for(const jr of existingJunctionRecords) {
|
|
140
140
|
await this.adminforth.deleteResourceRecord({
|
|
141
141
|
resource: junctionResource,
|
|
142
142
|
recordId: jr[junctionResource.columns.find(c => c.primaryKey).name],
|
|
143
143
|
record: jr,
|
|
144
|
-
adminUser
|
|
144
|
+
adminUser
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
147
|
return { ok: true };
|
|
148
148
|
});
|
|
149
149
|
const linkedResource = this.adminforth.config.resources.find(r => r.resourceId === this.options.linkedResourceId);
|
|
150
|
-
linkedResource.hooks.delete.beforeSave.push(async ({ recordId, record }: { recordId: any, record: any }) => {
|
|
150
|
+
linkedResource.hooks.delete.beforeSave.push(async ({ recordId, record, adminUser }: { recordId: any, record: any, adminUser: any }) => {
|
|
151
151
|
const existingJunctionRecords = await this.adminforth.resource(junctionResource.resourceId).list([Filters.EQ(linkedColumnNameInJunctionResource, recordId)]);
|
|
152
152
|
for(const jr of existingJunctionRecords) {
|
|
153
153
|
await this.adminforth.deleteResourceRecord({
|
|
154
154
|
resource: junctionResource,
|
|
155
155
|
recordId: jr[junctionResource.columns.find(c => c.primaryKey).name],
|
|
156
156
|
record: jr,
|
|
157
|
-
adminUser
|
|
157
|
+
adminUser
|
|
158
158
|
});
|
|
159
159
|
}
|
|
160
160
|
return { ok: true };
|
|
@@ -178,6 +178,9 @@ export default class extends AdminForthPlugin {
|
|
|
178
178
|
path: `/plugin/${this.pluginInstanceId}/get-junctionResource-records`,
|
|
179
179
|
handler: async ({ body }) => {
|
|
180
180
|
const { recordId, returnLabels } = body;
|
|
181
|
+
if (recordId === undefined || recordId === null || recordId === '') {
|
|
182
|
+
return { ok: true, data: [] };
|
|
183
|
+
}
|
|
181
184
|
const junctionRecords = await this.adminforth.resource(junctionResource.resourceId).list([Filters.EQ(resourceColumnNameInJunctionResource, recordId)]);
|
|
182
185
|
let dataToReturn = [];
|
|
183
186
|
const junctionResourcePkColumn = junctionResource.columns.find(c => c.primaryKey);
|