Comments (3)
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.
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.
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)
- Invalid validation errors on save and publish HOT 1
- Validation running on draft entries HOT 3
- Deadlock crash when updating an entity with many to many relationship HOT 7
- TypeError: Cannot read properties of undefined (reading 'length') HOT 4
- ManyToMany Relation dropped for all versions when we mark publish any version HOT 2
- Can't get to work HOT 3
- Unpublish when create new version
- Version comment cannot be updated
- is there any way to use this query in graphql ?populate=versions&publicationState=preview
- Single Type White Page HOT 6
- Error updating Content Manager Collection Types with Postgresql Connection HOT 1
- Update showed version button breaks JSON fields
- Add option to limit number of versions
- Cannot save any existing entity after update from 0.4.7 to 1.2.9
- `createdAt` field gets overwritten when creating new version
- Records in other `i18n` locales get hidden while creating new version
- Success Message to Appear on Updating showed Version
- Need a Patch file for v4.15.4
- Unable to duplicate/clone a new post from existing post in Strapi while using content versioning. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from strapi-plugin-content-versioning.