Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: get active or archived notification by id #398

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions apps/api/OsmoX-API.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,52 @@
"description": "Allows successfully fetching all notifications based on the options passed."
},
"response": []
},
{
"name": "Fetch Active or Archived Notification by Id",
"event": [
{
"listen": "test",
"script": {
"exec": [
""
],
"type": "text/javascript",
"packages": {}
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "Bearer {{auth-token}}"
},
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "graphql",
"graphql": {
"query": "query {\r\n notification(\r\n notificationId: 150\r\n ) {\r\n applicationId\r\n channelType\r\n createdBy\r\n createdOn\r\n data\r\n deliveryStatus\r\n id\r\n providerId\r\n result\r\n status\r\n updatedBy\r\n updatedOn\r\n }\r\n}",
"variables": ""
}
},
"url": {
"raw": "{{base_url}}/graphql",
"host": [
"{{base_url}}"
],
"path": [
"graphql"
]
},
"description": "Allows successfully fetching single notification based on the options passed."
},
"response": []
}
],
"description": "These API calls are responsible for fetching notifications and related details."
Expand Down
128 changes: 126 additions & 2 deletions apps/api/OsmoX.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -2863,10 +2863,9 @@
" var jsonData = pm.response.json();",
" pm.expect(jsonData.data).to.have.property(\"login\").to.be.an(\"object\");",
"});",
"pm.test(\"Response contains valid 'token' and 'user' values\", function () {",
"pm.test(\"Response contains valid 'token' value\", function () {",
" var jsonData = pm.response.json();",
" pm.expect(jsonData.data.login).to.have.property(\"token\").to.be.a(\"string\");",
" pm.expect(jsonData.data.login).to.have.property(\"user\").to.be.a(\"string\");",
"});"
],
"type": "text/javascript",
Expand Down Expand Up @@ -3193,6 +3192,131 @@
],
"description": "Collection of requests pertaining to fetching all notifications."
},
{
"name": "Fetch Active or Archived Notification by Id",
"item": [
{
"name": "Fetch Active or Archived Notification by Id - Success",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Response is valid JSON\", function () {",
" pm.response.to.be.json;",
"});",
"pm.test(\"Response has valid 'data' property\", function () {",
" var jsonData = pm.response.json();",
" pm.expect(jsonData).to.have.property(\"data\").to.be.an(\"object\");",
"});",
"pm.test(\"Response contains a valid 'notification' object\", function () {",
" var jsonData = pm.response.json();",
" pm.expect(jsonData.data).to.have.property(\"notification\").to.be.an(\"object\");",
"});",
""
],
"type": "text/javascript",
"packages": {}
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "Bearer {{auth-token}}"
},
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "graphql",
"graphql": {
"query": "query {\r\n notification(\r\n notificationId: 150\r\n ) {\r\n applicationId\r\n channelType\r\n createdBy\r\n createdOn\r\n data\r\n deliveryStatus\r\n id\r\n providerId\r\n result\r\n status\r\n updatedBy\r\n updatedOn\r\n }\r\n}",
"variables": ""
}
},
"url": {
"raw": "http://localhost:3000/graphql",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"graphql"
]
},
"description": "Allows successfully fetching of a notification."
},
"response": []
},
{
"name": "Fetch Active or Archived Notification by Id - Not found exception",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Response is valid JSON\", function () {",
" pm.response.to.be.json;",
"});",
"pm.test(\"Response has valid 'errors' and 'data' properties\", function () {",
" var jsonData = pm.response.json();",
" pm.expect(jsonData).to.have.property(\"data\");",
" pm.expect(jsonData).to.have.property(\"errors\").to.be.an(\"array\");",
"});",
"pm.test(\"String Response in error message\", function () {",
" pm.expect(pm.response.json().errors).to.be.an(\"array\");",
" pm.expect(pm.response.json().errors[0].message).to.be.a(\"string\");",
"});",
""
],
"type": "text/javascript",
"packages": {}
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "Bearer {{auth-token}}"
},
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "graphql",
"graphql": {
"query": "query {\r\n notification(\r\n notificationId: -1\r\n ) {\r\n applicationId\r\n channelType\r\n createdBy\r\n createdOn\r\n data\r\n deliveryStatus\r\n id\r\n providerId\r\n result\r\n status\r\n updatedBy\r\n updatedOn\r\n }\r\n}",
"variables": ""
}
},
"url": {
"raw": "http://localhost:3000/graphql",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"graphql"
]
},
"description": "Allows representing failure when fetching a notification when using invalid/bad request."
},
"response": []
}
],
"description": "Collection of requests pertaining to fetching a singe active/archived notification."
},
{
"name": "All Archived Notifications",
"item": [
Expand Down
75 changes: 75 additions & 0 deletions apps/api/docs/api-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,81 @@ curl --location 'http://localhost:3000/graphql' \
}
```

### Fetch active or archived Notification by Id

Allows the user to fetch a single notification present in either `notify_notifications` or `notify_archived_notifications` table by passing notificationId. Requires passing bearer token for authorization.

The required parameter for fetching a single active or archived notification is as follows:

- `notificationId`

**Endpoint:** `http://localhost:3000/graphql`

**Method:** `POST`

**Body:** `graphql`

```graphql
query {
notification(
notificationId: 150
) {
applicationId
channelType
createdBy
createdOn
data
deliveryStatus
id
providerId
result
status
updatedBy
updatedOn
}
}
```

**cURL**

```sh
curl --location 'localhost:3000/graphql' \
--header 'Authorization: Bearer mysecuretoken' \
--header 'Content-Type: application/json' \
--data '{"query":"query {\r\n notification(\r\n notificationId: 150\r\n ) {\r\n applicationId\r\n channelType\r\n createdBy\r\n createdOn\r\n data\r\n deliveryStatus\r\n id\r\n providerId\r\n result\r\n status\r\n updatedBy\r\n updatedOn\r\n }\r\n}","variables":{}}'
```

**Sample response**

```json
{
"data": {
"notification": {
"applicationId": 3,
"channelType": 11,
"createdBy": "Test3",
"createdOn": "2025-02-14T12:25:23.000Z",
"data": {
"from": "fromtestmail@gmail.com",
"to": "totestmail@gmail.co",
"subject": "Test subject",
"text": "This is a test notification",
"html": "<b>This is a test notification</b>"
},
"deliveryStatus": 5,
"id": 150,
"providerId": 16,
"result": {
"result": "This is a test mode notification. Notification was not delivered to recipient."
},
"status": 1,
"updatedBy": "Test3",
"updatedOn": "2025-02-14T12:25:23.000Z"
}
}
}
```

## Archived Notifications

This sections lists notification related requests such as fetching all archived notifications.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ArchivedNotificationsResolver } from './archived-notifications.resolver
forwardRef(() => NotificationsModule),
],
providers: [ArchivedNotificationsService, ArchivedNotificationsResolver, Logger, ConfigService],
exports: [ArchivedNotificationsService],
exports: [TypeOrmModule, ArchivedNotificationsService],
controllers: [ArchivedNotificationsController],
})
export class ArchivedNotificationsModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,17 @@ export class ArchivedNotificationsService extends CoreService<ArchivedNotificati
);
return new ArchivedNotificationResponse(items, total, options.offset, options.limit);
}

async getArchivedNotificationFromNotificationId(
notificationId: number,
): Promise<ArchivedNotification | null> {
this.logger.log(`Getting notification with id: ${notificationId} from archive table.`);
const archivedNotification = await this.archivedNotificationRepository.findOne({
where: {
notificationId: notificationId,
status: Status.ACTIVE,
},
});
return archivedNotification;
}
}
Loading
Loading