@nkhang1902/strapi-plugin-export-import-clsx 1.2.4 → 1.2.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nkhang1902/strapi-plugin-export-import-clsx",
3
- "version": "1.2.4",
3
+ "version": "1.2.6",
4
4
  "description": "A powerful Strapi plugin for exporting and importing data with Excel support and advanced filtering",
5
5
  "main": "./strapi-server.js",
6
6
  "scripts": {
@@ -147,16 +147,23 @@ module.exports = ({ strapi }) => ({
147
147
  .map(([fieldName, attr]) => toCamel(fieldName));
148
148
  },
149
149
 
150
- async handleRelations(entry, contentType) {
151
- const resolveRelationValue = async (field, value, target) => {
150
+ async handleRelations(entry, contentType, eventId) {
151
+ const resolveRelationValue = async (field, value, target, eventId) => {
152
152
  const targetAttr = strapi.contentTypes[target].attributes;
153
153
  for (const field of SHORTCUT_FIELDS) {
154
154
  if (!targetAttr[field]) continue;
155
+ const filters = {
156
+ [field]: { $eq: value },
157
+ };
158
+ if (targetAttr.event && eventId) {
159
+ filters.event = {
160
+ documentId: { $eq: eventId },
161
+ };
162
+ }
155
163
  const existing = await strapi.documents(target).findFirst({
156
- filters: { [field]: { $eq: value } },
164
+ filters,
157
165
  });
158
166
  if (existing) return { id: existing.id };
159
- // throw new Error(`Not found.`);
160
167
  return null;
161
168
  }
162
169
  return null;
@@ -205,7 +212,7 @@ module.exports = ({ strapi }) => ({
205
212
 
206
213
  for (const v of values) {
207
214
  if (!v || v === "") continue;
208
- const resolved = await resolveRelationValue(field, v, target);
215
+ const resolved = await resolveRelationValue(field, v, target, eventId);
209
216
  if (resolved) processed.push(resolved);
210
217
  }
211
218
 
@@ -393,15 +400,6 @@ module.exports = ({ strapi }) => ({
393
400
  const results = { created: 0, updated: 0, errors: [] };
394
401
 
395
402
  await strapi.db.transaction(async ({ trx }) => {
396
- let event = null;
397
-
398
- if (eventId) {
399
- event = await strapi.documents("api::event.event").findFirst(
400
- { filters: { documentId: eventId } },
401
- { transaction: trx }
402
- );
403
- }
404
-
405
403
  let shouldRollback = false;
406
404
 
407
405
  for (let i = 0; i < entries.length; i++) {
@@ -419,9 +417,7 @@ module.exports = ({ strapi }) => ({
419
417
  // if (!existing) throw new Error(`Document with id ${id} not found`);
420
418
  }
421
419
 
422
- if (event && !data.event) data.event = event.name;
423
-
424
- data = await this.handleRelations(data, contentType);
420
+ data = await this.handleRelations(data, contentType, eventId);
425
421
  data = await this.handleComponents(data, existing, contentType);
426
422
 
427
423
  const sanitizeErrors = [];
@@ -438,7 +434,7 @@ module.exports = ({ strapi }) => ({
438
434
  results.updated++;
439
435
  } else {
440
436
  await strapi.documents(contentType).create(
441
- { data },
437
+ { ...data, event: { documentId: eventId } },
442
438
  { transaction: trx }
443
439
  );
444
440
  results.created++;