@strapi/content-releases 0.0.0-next.cb00a1799402728de4ecec6d52a815e33fcedaf3 → 0.0.0-next.cfecf3ad808761571ce11e528113e5c1ea5f87fd

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.
@@ -235,13 +235,16 @@ async function disableContentTypeLocalized({ oldContentTypes, contentTypes: cont
235
235
  if (!oldContentTypes) {
236
236
  return;
237
237
  }
238
+ const i18nPlugin = strapi.plugin("i18n");
239
+ if (!i18nPlugin) {
240
+ return;
241
+ }
238
242
  for (const uid in contentTypes2) {
239
243
  if (!oldContentTypes[uid]) {
240
244
  continue;
241
245
  }
242
246
  const oldContentType = oldContentTypes[uid];
243
247
  const contentType = contentTypes2[uid];
244
- const i18nPlugin = strapi.plugin("i18n");
245
248
  const { isLocalizedContentType } = i18nPlugin.service("content-types");
246
249
  if (isLocalizedContentType(oldContentType) && !isLocalizedContentType(contentType)) {
247
250
  await strapi.db.queryBuilder(RELEASE_ACTION_MODEL_UID).update({
@@ -254,13 +257,16 @@ async function enableContentTypeLocalized({ oldContentTypes, contentTypes: conte
254
257
  if (!oldContentTypes) {
255
258
  return;
256
259
  }
260
+ const i18nPlugin = strapi.plugin("i18n");
261
+ if (!i18nPlugin) {
262
+ return;
263
+ }
257
264
  for (const uid in contentTypes2) {
258
265
  if (!oldContentTypes[uid]) {
259
266
  continue;
260
267
  }
261
268
  const oldContentType = oldContentTypes[uid];
262
269
  const contentType = contentTypes2[uid];
263
- const i18nPlugin = strapi.plugin("i18n");
264
270
  const { isLocalizedContentType } = i18nPlugin.service("content-types");
265
271
  const { getDefaultLocale } = i18nPlugin.service("locales");
266
272
  if (!isLocalizedContentType(oldContentType) && isLocalizedContentType(contentType)) {
@@ -679,12 +685,18 @@ const createReleaseService = ({ strapi: strapi2 }) => {
679
685
  }
680
686
  });
681
687
  },
682
- async findManyWithContentTypeEntryAttached(contentTypeUid, entryId) {
688
+ async findManyWithContentTypeEntryAttached(contentTypeUid, entriesIds) {
689
+ let entries = entriesIds;
690
+ if (!Array.isArray(entriesIds)) {
691
+ entries = [entriesIds];
692
+ }
683
693
  const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
684
694
  where: {
685
695
  actions: {
686
696
  target_type: contentTypeUid,
687
- target_id: entryId
697
+ target_id: {
698
+ $in: entries
699
+ }
688
700
  },
689
701
  releasedAt: {
690
702
  $null: true
@@ -695,18 +707,25 @@ const createReleaseService = ({ strapi: strapi2 }) => {
695
707
  actions: {
696
708
  where: {
697
709
  target_type: contentTypeUid,
698
- target_id: entryId
710
+ target_id: {
711
+ $in: entries
712
+ }
713
+ },
714
+ populate: {
715
+ entry: {
716
+ select: ["id"]
717
+ }
699
718
  }
700
719
  }
701
720
  }
702
721
  });
703
722
  return releases.map((release2) => {
704
723
  if (release2.actions?.length) {
705
- const [actionForEntry] = release2.actions;
724
+ const actionsForEntry = release2.actions;
706
725
  delete release2.actions;
707
726
  return {
708
727
  ...release2,
709
- action: actionForEntry
728
+ actions: actionsForEntry
710
729
  };
711
730
  }
712
731
  return release2;
@@ -1322,6 +1341,33 @@ const releaseController = {
1322
1341
  };
1323
1342
  ctx.body = { data };
1324
1343
  },
1344
+ async mapEntriesToReleases(ctx) {
1345
+ const { contentTypeUid, entriesIds } = ctx.query;
1346
+ if (!contentTypeUid || !entriesIds) {
1347
+ throw new utils.errors.ValidationError("Missing required query parameters");
1348
+ }
1349
+ const releaseService = getService("release", { strapi });
1350
+ const releasesWithActions = await releaseService.findManyWithContentTypeEntryAttached(
1351
+ contentTypeUid,
1352
+ entriesIds
1353
+ );
1354
+ const mappedEntriesInReleases = releasesWithActions.reduce(
1355
+ (acc, release2) => {
1356
+ release2.actions.forEach((action) => {
1357
+ if (!acc[action.entry.id]) {
1358
+ acc[action.entry.id] = [{ id: release2.id, name: release2.name }];
1359
+ } else {
1360
+ acc[action.entry.id].push({ id: release2.id, name: release2.name });
1361
+ }
1362
+ });
1363
+ return acc;
1364
+ },
1365
+ {}
1366
+ );
1367
+ ctx.body = {
1368
+ data: mappedEntriesInReleases
1369
+ };
1370
+ },
1325
1371
  async create(ctx) {
1326
1372
  const user = ctx.state.user;
1327
1373
  const releaseArgs = ctx.request.body;
@@ -1511,6 +1557,22 @@ const controllers = { release: releaseController, "release-action": releaseActio
1511
1557
  const release = {
1512
1558
  type: "admin",
1513
1559
  routes: [
1560
+ {
1561
+ method: "GET",
1562
+ path: "/mapEntriesToReleases",
1563
+ handler: "release.mapEntriesToReleases",
1564
+ config: {
1565
+ policies: [
1566
+ "admin::isAuthenticatedAdmin",
1567
+ {
1568
+ name: "admin::hasPermissions",
1569
+ config: {
1570
+ actions: ["plugin::content-releases.read"]
1571
+ }
1572
+ }
1573
+ ]
1574
+ }
1575
+ },
1514
1576
  {
1515
1577
  method: "POST",
1516
1578
  path: "/",