@adminforth/many2many 1.0.8 → 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/build.log CHANGED
@@ -8,5 +8,5 @@ custom/ManyToManyInput.vue
8
8
  custom/ManyToManyShow.vue
9
9
  custom/tsconfig.json
10
10
 
11
- sent 4,993 bytes received 77 bytes 10,140.00 bytes/sec
11
+ sent 4,989 bytes received 77 bytes 10,132.00 bytes/sec
12
12
  total size is 4,701 speedup is 0.93
package/dist/index.js CHANGED
@@ -80,7 +80,8 @@ export default class extends AdminForthPlugin {
80
80
  create: false,
81
81
  edit: false
82
82
  },
83
- label: this.options.labelForColumn || this.options.linkedResourceId
83
+ label: this.options.labelForColumn || this.options.linkedResourceId,
84
+ showIf: this.options.showIf || null,
84
85
  };
85
86
  resourceConfig.columns.push(virtualColumn);
86
87
  // ** HOOKS FOR CREATE **//
@@ -133,27 +134,27 @@ export default class extends AdminForthPlugin {
133
134
  }));
134
135
  // ** HOOKS FOR DELETE **//
135
136
  if (!this.options.dontDeleteJunctionRecords) {
136
- 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 }) {
137
138
  const existingJunctionRecords = yield this.adminforth.resource(junctionResource.resourceId).list([Filters.EQ(resourceColumnNameInJunctionResource, recordId)]);
138
139
  for (const jr of existingJunctionRecords) {
139
140
  yield this.adminforth.deleteResourceRecord({
140
141
  resource: junctionResource,
141
142
  recordId: jr[junctionResource.columns.find(c => c.primaryKey).name],
142
143
  record: jr,
143
- adminUser: null
144
+ adminUser
144
145
  });
145
146
  }
146
147
  return { ok: true };
147
148
  }));
148
149
  const linkedResource = this.adminforth.config.resources.find(r => r.resourceId === this.options.linkedResourceId);
149
- 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 }) {
150
151
  const existingJunctionRecords = yield this.adminforth.resource(junctionResource.resourceId).list([Filters.EQ(linkedColumnNameInJunctionResource, recordId)]);
151
152
  for (const jr of existingJunctionRecords) {
152
153
  yield this.adminforth.deleteResourceRecord({
153
154
  resource: junctionResource,
154
155
  recordId: jr[junctionResource.columns.find(c => c.primaryKey).name],
155
156
  record: jr,
156
- adminUser: null
157
+ adminUser
157
158
  });
158
159
  }
159
160
  return { ok: true };
@@ -175,6 +176,9 @@ export default class extends AdminForthPlugin {
175
176
  path: `/plugin/${this.pluginInstanceId}/get-junctionResource-records`,
176
177
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body }) {
177
178
  const { recordId, returnLabels } = body;
179
+ if (recordId === undefined || recordId === null || recordId === '') {
180
+ return { ok: true, data: [] };
181
+ }
178
182
  const junctionRecords = yield this.adminforth.resource(junctionResource.resourceId).list([Filters.EQ(resourceColumnNameInJunctionResource, recordId)]);
179
183
  let dataToReturn = [];
180
184
  const junctionResourcePkColumn = junctionResource.columns.find(c => c.primaryKey);
package/index.ts CHANGED
@@ -75,7 +75,8 @@ export default class extends AdminForthPlugin {
75
75
  create: false,
76
76
  edit: false
77
77
  },
78
- label: this.options.labelForColumn || this.options.linkedResourceId
78
+ label: this.options.labelForColumn || this.options.linkedResourceId,
79
+ showIf: this.options.showIf || null,
79
80
  };
80
81
  resourceConfig.columns.push(virtualColumn);
81
82
 
@@ -133,27 +134,27 @@ export default class extends AdminForthPlugin {
133
134
 
134
135
  // ** HOOKS FOR DELETE **//
135
136
  if (!this.options.dontDeleteJunctionRecords) {
136
- 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 }) => {
137
138
  const existingJunctionRecords = await this.adminforth.resource(junctionResource.resourceId).list([Filters.EQ(resourceColumnNameInJunctionResource, recordId)]);
138
139
  for(const jr of existingJunctionRecords) {
139
140
  await this.adminforth.deleteResourceRecord({
140
141
  resource: junctionResource,
141
142
  recordId: jr[junctionResource.columns.find(c => c.primaryKey).name],
142
143
  record: jr,
143
- adminUser: null
144
+ adminUser
144
145
  });
145
146
  }
146
147
  return { ok: true };
147
148
  });
148
149
  const linkedResource = this.adminforth.config.resources.find(r => r.resourceId === this.options.linkedResourceId);
149
- 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 }) => {
150
151
  const existingJunctionRecords = await this.adminforth.resource(junctionResource.resourceId).list([Filters.EQ(linkedColumnNameInJunctionResource, recordId)]);
151
152
  for(const jr of existingJunctionRecords) {
152
153
  await this.adminforth.deleteResourceRecord({
153
154
  resource: junctionResource,
154
155
  recordId: jr[junctionResource.columns.find(c => c.primaryKey).name],
155
156
  record: jr,
156
- adminUser: null
157
+ adminUser
157
158
  });
158
159
  }
159
160
  return { ok: true };
@@ -177,6 +178,9 @@ export default class extends AdminForthPlugin {
177
178
  path: `/plugin/${this.pluginInstanceId}/get-junctionResource-records`,
178
179
  handler: async ({ body }) => {
179
180
  const { recordId, returnLabels } = body;
181
+ if (recordId === undefined || recordId === null || recordId === '') {
182
+ return { ok: true, data: [] };
183
+ }
180
184
  const junctionRecords = await this.adminforth.resource(junctionResource.resourceId).list([Filters.EQ(resourceColumnNameInJunctionResource, recordId)]);
181
185
  let dataToReturn = [];
182
186
  const junctionResourcePkColumn = junctionResource.columns.find(c => c.primaryKey);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/many2many",
3
- "version": "1.0.8",
3
+ "version": "1.1.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/types.ts CHANGED
@@ -1,5 +1,7 @@
1
+ import { Predicate } from "adminforth"
1
2
  export interface PluginOptions {
2
3
  linkedResourceId: string
3
4
  dontDeleteJunctionRecords?: boolean
4
5
  labelForColumn?: string
6
+ showIf?: Predicate
5
7
  }