From d4bef1ab07ba781f855907dc50dfebe6ec91feac Mon Sep 17 00:00:00 2001 From: julien vdb Date: Fri, 31 Oct 2025 18:03:35 +0100 Subject: [PATCH] 0.11.13 : add post link --- package.json | 2 +- src/api/post/controllers/post.ts | 21 ++++++++++++++++++- .../1.0.0/full_documentation.json | 2 +- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 318e88f..0ee19d7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "harmony-back", - "version": "0.11.12", + "version": "0.11.13", "private": true, "description": "A Strapi application", "scripts": { diff --git a/src/api/post/controllers/post.ts b/src/api/post/controllers/post.ts index 9be929a..8a932be 100644 --- a/src/api/post/controllers/post.ts +++ b/src/api/post/controllers/post.ts @@ -183,6 +183,7 @@ export default factories.createCoreController( { author: { id: friendIds } }, // Posts de mes amis { author: { id: followIds } }, // Posts des contacts que je suis { author: { id: parseInt(userId) }, relation: "owner" }, // Mes propres posts + { author: { id: parseInt(userId) }, relation: "link" }, // Posts linkés (events partagés) { contextType: "group", contextId: groupIds }, // Posts de mes groupes { contextType: "group", contextId: friendsGroupIds }, // Posts des groupes de mes amis { contextType: "system" }, // Posts système @@ -273,6 +274,8 @@ export default factories.createCoreController( contactFollow: isContactFollow, member: isMember, blocked: isBlocked, + contextType, + contextId, ...(group && { group }), // Ajouter group seulement s'il existe }; }); @@ -727,7 +730,8 @@ export default factories.createCoreController( return ctx.unauthorized("You must be logged in to link events"); } - const { contextType, contextId, relation } = ctx.request.body; + const { contextType, contextId, relation, content, title } = + ctx.request.body; if (!contextType || contextId === undefined || !relation) { return ctx.badRequest( @@ -735,6 +739,10 @@ export default factories.createCoreController( ); } + if (!content || !title) { + return ctx.badRequest("content and title are required"); + } + try { // Check if link already exists const existingLink = await strapi.db @@ -752,10 +760,21 @@ export default factories.createCoreController( return ctx.badRequest("This event is already linked"); } + // Create the post + const post = await strapi.db.query("api::post.post").create({ + data: { + content, + title, + category: "event", + }, + }); + + // Create the postOwnership linked to the post const postOwnership = await strapi.db .query("api::post-ownership.post-ownership") .create({ data: { + post: post.id, author: user.id, contextType, contextId, diff --git a/src/extensions/documentation/documentation/1.0.0/full_documentation.json b/src/extensions/documentation/documentation/1.0.0/full_documentation.json index e8d3bf8..c959767 100644 --- a/src/extensions/documentation/documentation/1.0.0/full_documentation.json +++ b/src/extensions/documentation/documentation/1.0.0/full_documentation.json @@ -14,7 +14,7 @@ "name": "Apache 2.0", "url": "https://www.apache.org/licenses/LICENSE-2.0.html" }, - "x-generation-date": "2025-10-29T23:50:11.045Z" + "x-generation-date": "2025-10-31T17:03:14.573Z" }, "x-strapi-config": { "plugins": [