0.11.15 : add notification and private field on PostRelationship

This commit is contained in:
2025-11-07 14:40:48 +01:00
parent c5e63ab92a
commit 4071000895
8 changed files with 4657 additions and 2 deletions

View File

@@ -0,0 +1,45 @@
{
"kind": "collectionType",
"collectionName": "notifications",
"info": {
"singularName": "notification",
"pluralName": "notifications",
"displayName": "Notification"
},
"options": {
"draftAndPublish": false
},
"pluginOptions": {},
"attributes": {
"title": {
"type": "string"
},
"message": {
"type": "string"
},
"type": {
"type": "enumeration",
"enum": [
"info",
"success",
"warning",
"error"
]
},
"target_user": {
"type": "relation",
"relation": "oneToOne",
"target": "plugin::users-permissions.user"
},
"read": {
"type": "boolean",
"default": false
},
"source": {
"type": "string"
},
"payload": {
"type": "json"
}
}
}

View File

@@ -0,0 +1,7 @@
/**
* notification controller
*/
import { factories } from '@strapi/strapi'
export default factories.createCoreController('api::notification.notification');

View File

@@ -0,0 +1,7 @@
/**
* notification router
*/
import { factories } from '@strapi/strapi';
export default factories.createCoreRouter('api::notification.notification');

View File

@@ -0,0 +1,51 @@
interface NotificationPayload {
title: string;
message: string;
type?: "info" | "success" | "warning" | "error";
target_user?: number;
source?: string;
payload?: Record<string, any>;
}
interface NotificationEntity {
id: number;
title: string;
message: string;
type: string;
target_user?: number;
source?: string;
payload?: Record<string, any>;
read: boolean;
createdAt: string;
updatedAt: string;
}
/**
* notification service
*/
import { factories } from "@strapi/strapi";
export default factories.createCoreService(
"api::notification.notification",
({ strapi }: { strapi }) => ({
//Custom service for add notification.
async createNotification({
title,
message,
type = "info",
target_user,
source,
payload,
}: NotificationPayload): Promise<NotificationEntity> {
const data = { title, message, type, target_user, source, payload };
const notification = await strapi.entityService.create(
"api::notification.notification",
{ data }
);
strapi.log.info(`🔔 Notification créée: ${title}`);
return notification;
},
})
);

View File

@@ -47,6 +47,10 @@
"relation": "manyToOne",
"target": "api::post.post",
"inversedBy": "post_ownerships"
},
"public": {
"type": "boolean",
"default": false
}
}
}