0.11.10 : add link post

This commit is contained in:
2025-10-29 22:53:35 +01:00
parent 337293182b
commit 39c3a516cd
8 changed files with 211 additions and 61 deletions
+27 -1
View File
@@ -207,7 +207,26 @@ export default ({ strapi }: { strapi: Core.Strapi }) =>
}
});
// 7️⃣ Enrichir le feed avec les propriétés friend, member, contactFollow, group et registered participants
// 7️⃣ Récupérer les PostOwnership pour vérifier si les events sont déjà partagés
const eventPostOwnerships = await strapi.db
.query("api::post-ownership.post-ownership")
.findMany({
where: {
contextId: eventIds,
contextType: "event",
relation: "link",
},
populate: ["author"],
});
// Créer une map des events partagés par userId et eventId
const sharedEventsByUserAndEvent = new Map<string, boolean>();
eventPostOwnerships.forEach((po) => {
const key = `${po.author?.id}-${po.contextId}`;
sharedEventsByUserAndEvent.set(key, true);
});
// 8️⃣ Enrichir le feed avec les propriétés friend, member, contactFollow, group, registered participants et isShared
const enrichedFeed = feed.map((eventRelationship) => {
const authorId = eventRelationship.author?.id;
const contextType = eventRelationship.contextType;
@@ -235,6 +254,12 @@ export default ({ strapi }: { strapi: Core.Strapi }) =>
? participantsByEventId.get(eventId) || []
: [];
// Vérifier si l'event est déjà partagé par l'auteur
const isShared =
authorId && eventId
? sharedEventsByUserAndEvent.has(`${authorId}-${eventId}`)
: false;
return {
...eventRelationship,
friend: isFriend,
@@ -242,6 +267,7 @@ export default ({ strapi }: { strapi: Core.Strapi }) =>
member: isMember,
...(group && { group }), // Ajouter group seulement s'il existe
registered, // Ajouter les participants enregistrés
isShared, // Indiquer si l'event est partagé par l'auteur
};
});
@@ -23,7 +23,8 @@
"enum": [
"user",
"group",
"system"
"system",
"event"
]
},
"contextId": {
@@ -34,7 +35,8 @@
"enum": [
"owner",
"saved",
"hidden"
"hidden",
"link"
]
},
"metas": {
+11 -2
View File
@@ -19,7 +19,12 @@
"type": "media",
"multiple": true,
"required": false,
"allowedTypes": ["images", "files", "videos", "audios"]
"allowedTypes": [
"images",
"files",
"videos",
"audios"
]
},
"likes": {
"type": "relation",
@@ -28,7 +33,11 @@
},
"category": {
"type": "enumeration",
"enum": ["photo", "video", "event"]
"enum": [
"photo",
"video",
"event"
]
},
"comments": {
"type": "relation",
+52
View File
@@ -720,5 +720,57 @@ export default factories.createCoreController(
return ctx.internalServerError("Failed to add comment");
}
},
async link(ctx) {
const user = ctx.state.user;
if (!user) {
return ctx.unauthorized("You must be logged in to link events");
}
const { contextType, contextId, relation } = ctx.request.body;
if (!contextType || contextId === undefined || !relation) {
return ctx.badRequest(
"contextType, contextId, and relation are required"
);
}
try {
// Check if link already exists
const existingLink = await strapi.db
.query("api::post-ownership.post-ownership")
.findOne({
where: {
author: user.id,
contextType,
contextId,
relation,
},
});
if (existingLink) {
return ctx.badRequest("This event is already linked");
}
const postOwnership = await strapi.db
.query("api::post-ownership.post-ownership")
.create({
data: {
author: user.id,
contextType,
contextId,
relation,
},
});
return ctx.send({
message: "Event linked successfully",
postOwnership,
});
} catch (error: any) {
console.error("Error linking event:", error);
return ctx.internalServerError("Failed to link event");
}
},
})
);
+5
View File
@@ -39,5 +39,10 @@ export default {
path: "/posts/:id/comment",
handler: "post.addComment",
},
{
method: "POST",
path: "/posts/link",
handler: "post.link",
},
],
};