diff --git a/src/api/notification-template/content-types/notification-template/schema.json b/src/api/notification-template/content-types/notification-template/schema.json index 30a77cc..84f9c49 100644 --- a/src/api/notification-template/content-types/notification-template/schema.json +++ b/src/api/notification-template/content-types/notification-template/schema.json @@ -8,31 +8,36 @@ "description": "" }, "options": { - "draftAndPublish": true + "draftAndPublish": false }, "pluginOptions": {}, "attributes": { "title": { - "type": "string" + "type": "string", + "required": true }, "description": { - "type": "richtext" + "type": "richtext", + "required": true }, "url": { "type": "string" }, "push": { - "type": "boolean" + "type": "boolean", + "default": false, + "required": true }, "dueDate": { "type": "datetime" }, "thumbnail": { + "type": "media", + "multiple": false, + "required": false, "allowedTypes": [ "images" - ], - "type": "media", - "multiple": false + ] } } } diff --git a/src/api/notification/documentation/1.0.0/notification.json b/src/api/notification/documentation/1.0.0/notification.json index 8e5bbb0..08854a6 100644 --- a/src/api/notification/documentation/1.0.0/notification.json +++ b/src/api/notification/documentation/1.0.0/notification.json @@ -586,6 +586,88 @@ "operationId": "get/notification-list/{account}" } }, + "/accounts/{account}/notifications": { + "get": { + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/NotificationResponse" + } + } + } + }, + "400": { + "description": "Bad Request", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + }, + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + }, + "403": { + "description": "Forbidden", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + }, + "404": { + "description": "Not Found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + }, + "500": { + "description": "Internal Server Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + } + }, + "tags": [ + "Notification" + ], + "parameters": [ + { + "name": "account", + "in": "path", + "description": "", + "deprecated": false, + "required": true, + "schema": { + "type": "number" + } + } + ], + "operationId": "get/accounts/{account}/notifications" + } + }, "/push-notifications": { "get": { "responses": { diff --git a/src/api/notification/routes/notification.ts b/src/api/notification/routes/notification.ts index 0df6a20..b7801c1 100644 --- a/src/api/notification/routes/notification.ts +++ b/src/api/notification/routes/notification.ts @@ -21,6 +21,7 @@ const customRouter = (innerRouter, extraRoutes = []) => { }; const myExtraRoutes = [ + // TODO: For backward-compatibility, remove after August 2024 { method: 'GET', path: '/notification-list/:account', @@ -30,6 +31,15 @@ const myExtraRoutes = [ middlewares: [], }, }, + { + method: 'GET', + path: '/accounts/:account/notifications', + handler: 'notification.getNotificationList', + config: { + policies: [], + middlewares: [], + }, + }, { method: 'GET', path: '/push-notifications', diff --git a/src/api/notification/services/notification.ts b/src/api/notification/services/notification.ts index c9d949e..004bba3 100644 --- a/src/api/notification/services/notification.ts +++ b/src/api/notification/services/notification.ts @@ -5,8 +5,9 @@ import { factories } from '@strapi/strapi'; const MODULE_ID = 'api::notification.notification' -const GLOBAL_MODULE_ID = 'api::notifications-consumer.notifications-consumer' +const NOTIFICATIONS_CONSUMER_MODULE_ID = 'api::notifications-consumer.notifications-consumer' const SINGLETON_ID = 1 +const NOTIFICATIONS_LIMIT = 50 const NOTIFICATIONS_POPULATE = { notification_template: { @@ -39,7 +40,7 @@ export default factories.createCoreService(MODULE_ID, ({ strapi }) => { MODULE_ID, { start: 0, - limit: 50, + limit: NOTIFICATIONS_LIMIT, filters: { account: { $null: true }, notification_template: notificationsTemplateFilter(push) @@ -55,7 +56,7 @@ export default factories.createCoreService(MODULE_ID, ({ strapi }) => { MODULE_ID, { start: 0, - limit: 50, + limit: NOTIFICATIONS_LIMIT, filters: { $or: [ { account, notification_template: templateFilter }, @@ -80,11 +81,11 @@ export default factories.createCoreService(MODULE_ID, ({ strapi }) => { }, async getPushNotifications() { const push = true - const global = await strapi.entityService.findOne(GLOBAL_MODULE_ID, SINGLETON_ID, { + const notificationsConsumer = await strapi.entityService.findOne(NOTIFICATIONS_CONSUMER_MODULE_ID, SINGLETON_ID, { populate: ['id', 'lastConsumedNotificationDate'] }) - const lastConsumedNotificationDate = global?.lastConsumedNotificationDate + const lastConsumedNotificationDate = notificationsConsumer?.lastConsumedNotificationDate return strapi.entityService.findMany( MODULE_ID, @@ -102,7 +103,7 @@ export default factories.createCoreService(MODULE_ID, ({ strapi }) => { }, updateLastConsumedNotificationDate() { return strapi.entityService.update( - GLOBAL_MODULE_ID, + NOTIFICATIONS_CONSUMER_MODULE_ID, SINGLETON_ID, { data: { lastConsumedNotificationDate: new Date() } diff --git a/src/api/telegram-subscription/content-types/telegram-subscription/schema.json b/src/api/telegram-subscription/content-types/telegram-subscription/schema.json index a970dbb..aca2d7f 100644 --- a/src/api/telegram-subscription/content-types/telegram-subscription/schema.json +++ b/src/api/telegram-subscription/content-types/telegram-subscription/schema.json @@ -8,7 +8,7 @@ "description": "" }, "options": { - "draftAndPublish": true + "draftAndPublish": false }, "pluginOptions": {}, "attributes": { @@ -17,19 +17,19 @@ "required": true, "unique": false }, - "auth_date": { + "authDate": { "type": "biginteger" }, - "first_name": { + "firstName": { "type": "string" }, "hash": { "type": "string" }, - "chat_id": { + "chatId": { "type": "biginteger" }, - "photo_url": { + "photoUrl": { "type": "string" }, "username": { diff --git a/src/api/telegram-subscription/controllers/telegram-subscription.ts b/src/api/telegram-subscription/controllers/telegram-subscription.ts index fa787be..45cfa34 100644 --- a/src/api/telegram-subscription/controllers/telegram-subscription.ts +++ b/src/api/telegram-subscription/controllers/telegram-subscription.ts @@ -15,7 +15,7 @@ export default factories.createCoreController(MODULE_ID, ({strapi}) => { const service = strapi.service(MODULE_ID) - const existing = await strapi.entityService.findMany(MODULE_ID, { filters: { account, chat_id: data.id } }) + const existing = await strapi.entityService.findMany(MODULE_ID, { filters: { account, chatId: data.id } }) if (existing.length > 0) return true diff --git a/src/api/telegram-subscription/routes/telegram-subscription.ts b/src/api/telegram-subscription/routes/telegram-subscription.ts index 1e13bcb..f214d87 100644 --- a/src/api/telegram-subscription/routes/telegram-subscription.ts +++ b/src/api/telegram-subscription/routes/telegram-subscription.ts @@ -22,7 +22,7 @@ const customRouter = (innerRouter, extraRoutes = []) => { const myExtraRoutes = [ { method: 'GET', - path: '/tg-subscriptions', + path: '/subscriptions/telegram', handler: 'telegram-subscription.getSubscriptions', config: { policies: [], @@ -31,7 +31,7 @@ const myExtraRoutes = [ }, { method: 'GET', - path: '/tg-subscriptions/:account', + path: '/accounts/:account/subscriptions/telegram', handler: 'telegram-subscription.getAccountSubscriptions', config: { policies: [], diff --git a/src/api/telegram-subscription/services/telegram-subscription.ts b/src/api/telegram-subscription/services/telegram-subscription.ts index ca8bb13..306b01a 100644 --- a/src/api/telegram-subscription/services/telegram-subscription.ts +++ b/src/api/telegram-subscription/services/telegram-subscription.ts @@ -34,11 +34,11 @@ export default factories.createCoreService(MODULE_ID, ({strapi}) => { { data: { account, - auth_date: data.auth_date, - first_name: data.first_name, + authDate: data.auth_date, + firstName: data.first_name, hash: data.hash, - chat_id: data.id, - photo_url: data.photo_url, + chatId: data.id, + photoUrl: data.photo_url, username: data.username, } }) @@ -52,7 +52,7 @@ export default factories.createCoreService(MODULE_ID, ({strapi}) => { $in: accounts } }, - fields: ['id', 'account', 'chat_id'] + fields: ['id', 'account', 'chatId'] } ) }, @@ -63,7 +63,7 @@ export default factories.createCoreService(MODULE_ID, ({strapi}) => { filters: { account }, - fields: ['id', 'account', 'chat_id'] + fields: ['id', 'account', 'chatId'] } ) }, @@ -83,7 +83,7 @@ export default factories.createCoreService(MODULE_ID, ({strapi}) => { 'Content-Type': 'application/json' }, body: JSON.stringify({ - chat_id: subscription.chat_id, + chat_id: subscription.chatId, text: templateNotification(notification.notification_template.description, notification.data) }) }) 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 6ed8926..d4d9f87 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": "2024-06-07T17:23:18.291Z" + "x-generation-date": "2024-06-20T08:45:59.032Z" }, "x-strapi-config": { "path": "/documentation", @@ -12434,10 +12434,6 @@ "type": "string", "format": "date-time" }, - "publishedAt": { - "type": "string", - "format": "date-time" - }, "createdBy": { "type": "object", "properties": { @@ -12551,6 +12547,11 @@ ], "properties": { "data": { + "required": [ + "title", + "description", + "push" + ], "type": "object", "properties": { "title": { @@ -12632,6 +12633,11 @@ }, "NotificationTemplate": { "type": "object", + "required": [ + "title", + "description", + "push" + ], "properties": { "title": { "type": "string" @@ -13278,10 +13284,6 @@ "type": "string", "format": "date-time" }, - "publishedAt": { - "type": "string", - "format": "date-time" - }, "createdBy": { "type": "object", "properties": { @@ -18353,23 +18355,23 @@ "account": { "type": "string" }, - "auth_date": { + "authDate": { "type": "string", "pattern": "^\\d*$", "example": "123456789" }, - "first_name": { + "firstName": { "type": "string" }, "hash": { "type": "string" }, - "chat_id": { + "chatId": { "type": "string", "pattern": "^\\d*$", "example": "123456789" }, - "photo_url": { + "photoUrl": { "type": "string" }, "username": { @@ -18434,23 +18436,23 @@ "account": { "type": "string" }, - "auth_date": { + "authDate": { "type": "string", "pattern": "^\\d*$", "example": "123456789" }, - "first_name": { + "firstName": { "type": "string" }, "hash": { "type": "string" }, - "chat_id": { + "chatId": { "type": "string", "pattern": "^\\d*$", "example": "123456789" }, - "photo_url": { + "photoUrl": { "type": "string" }, "username": { @@ -18464,10 +18466,6 @@ "type": "string", "format": "date-time" }, - "publishedAt": { - "type": "string", - "format": "date-time" - }, "createdBy": { "type": "object", "properties": { @@ -23005,6 +23003,88 @@ "operationId": "get/notification-list/{account}" } }, + "/accounts/{account}/notifications": { + "get": { + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/NotificationResponse" + } + } + } + }, + "400": { + "description": "Bad Request", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + }, + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + }, + "403": { + "description": "Forbidden", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + }, + "404": { + "description": "Not Found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + }, + "500": { + "description": "Internal Server Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + } + }, + "tags": [ + "Notification" + ], + "parameters": [ + { + "name": "account", + "in": "path", + "description": "", + "deprecated": false, + "required": true, + "schema": { + "type": "number" + } + } + ], + "operationId": "get/accounts/{account}/notifications" + } + }, "/push-notifications": { "get": { "responses": {