@nkhang1902/strapi-plugin-export-import-clsx 1.2.3 → 1.2.5

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.3",
3
+ "version": "1.2.5",
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,13 +147,13 @@ 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
155
  const existing = await strapi.documents(target).findFirst({
156
- filters: { [field]: { $eq: value } },
156
+ filters: { [field]: { $eq: value }, event: { documentId: { $eq: eventId } } },
157
157
  });
158
158
  if (existing) return { id: existing.id };
159
159
  // throw new Error(`Not found.`);
@@ -205,7 +205,7 @@ module.exports = ({ strapi }) => ({
205
205
 
206
206
  for (const v of values) {
207
207
  if (!v || v === "") continue;
208
- const resolved = await resolveRelationValue(field, v, target);
208
+ const resolved = await resolveRelationValue(field, v, target, eventId);
209
209
  if (resolved) processed.push(resolved);
210
210
  }
211
211
 
@@ -393,15 +393,6 @@ module.exports = ({ strapi }) => ({
393
393
  const results = { created: 0, updated: 0, errors: [] };
394
394
 
395
395
  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
396
  let shouldRollback = false;
406
397
 
407
398
  for (let i = 0; i < entries.length; i++) {
@@ -413,15 +404,13 @@ module.exports = ({ strapi }) => ({
413
404
 
414
405
  if (id) {
415
406
  existing = await strapi.documents(contentType).findFirst(
416
- { filters: { id }, populate: "*" },
407
+ { filters: { id, event: { documentId: eventId } }, populate: "*" },
417
408
  { transaction: trx }
418
409
  );
419
410
  // if (!existing) throw new Error(`Document with id ${id} not found`);
420
411
  }
421
412
 
422
- if (event && !data.event) data.event = event.name;
423
-
424
- data = await this.handleRelations(data, contentType);
413
+ data = await this.handleRelations(data, contentType, eventId);
425
414
  data = await this.handleComponents(data, existing, contentType);
426
415
 
427
416
  const sanitizeErrors = [];
@@ -438,7 +427,7 @@ module.exports = ({ strapi }) => ({
438
427
  results.updated++;
439
428
  } else {
440
429
  await strapi.documents(contentType).create(
441
- { data },
430
+ { ...data, event: { documentId: eventId } },
442
431
  { transaction: trx }
443
432
  );
444
433
  results.created++;