Git Product home page Git Product logo

Comments (3)

tavsec avatar tavsec commented on June 2, 2024 1

Hey @omikulcik , thanks for the answer. Yes, the issues are almost identical. I "borrowed" some of the functionalities from the plugin's Admin controllers and duplicated them into API controllers, while I wait for the official support for that.

If anyone is interested, I created the new-event-version controller with the following contents:

src/api/new-event-version/controllers/new-event-version.js

'use strict';

const { v4: uuid } = require("uuid");
const { getService } = require("../utils");
const { pick } = require("lodash");

/**
 * A set of functions called "actions" for `new-event-version`
 */

module.exports = {
  createNewVersion: async (ctx, next) => {
    try {
      const { slug } = ctx.request.params;
      const { data } = ctx.request.body;
      const { user } = ctx.state;

      const { createVersion } = getService("core-api");

      if (data.isDuplicatingEntry) {
        const allVersions = await strapi.db.query(slug).findMany({
          where: {
            vuid: data.vuid,
            //locale: data.locale // Clone all or only this locale ?
          },
          sort: [{ versionNumber: "asc" }], // Incrementaly create versions
        });


        let initialCloneVersion = null;
        const newVuid = uuid();

        for (const versionData of allVersions) {
          versionData.vuid = newVuid;
          const created = await createVersion(slug, versionData, user, {});

          // identify first clone version to be returned
          if (
            created.locale == data.locale &&
            created.versionNumber == data.versionNumber
          ) {
            initialCloneVersion = created;
          }
        }
        return initialCloneVersion;
      }

      return await createVersion(slug, data, user, ctx.request.query);
    } catch (err) {
      // console.log("error", err)
      ctx.body = err;
    }
  }
};

src/api/new-event-version/routes/new-event-version.js

module.exports = {
  routes: [
    {
     method: 'POST',
     path: '/new-event-version/:slug',
     handler: 'new-event-version.createNewVersion',
     config: {
       policies: [],
       middlewares: [],
     },
    },
  ],
};

API is available on POST /api/new-event-version/<slug> and the request body:

{
    "data": {
        "vuid": "58396b8f-6baa-4b2f-bacb-9bb24ba0dd40",
        "title": "testing creation of new version with the same vuid"
    }
}

If anyone will be using this code, please adjust it to your needs (and permissions). This was just my workaround, and was not throughly tested, so be mindful of that :)

Thanks again @omikulcik !

from strapi-plugin-content-versioning.

omikulcik avatar omikulcik commented on June 2, 2024

Hi @tavsec If I understand correctly, your question is almost the same as #49. I am sorry to say that this is not yet supported.

from strapi-plugin-content-versioning.

omikulcik avatar omikulcik commented on June 2, 2024

Thank you for sharing your code. I think this might be helpful for others so I will leave this open since it is a discussion issue.

from strapi-plugin-content-versioning.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.