---
# System prepended metadata

title: Rake subscription sub-system

---

# Rake subscription sub-system

![](https://i.imgur.com/Dniauvr.png)

> unreadMessageEvents
> add: systemEventId
> remove: systemEventId + 1

> sessionInactivity: systemEventId + 2
> sessionEntityInactivity: systemEventId + 3

## Collections subscriptions

### Collection eventSubscriptionTypes

Schema
```
{
    subscriptionTypeId: Number
    name: String,
    systemReference?: String
}
```

Values

| subscriptionTypeId | systemReference         | name |
| ------------------ | ----------------------- | ---- |
| 0                  | sessionInactivity       | Session inactivity 
| 1                  | sessionEntityInactivity | User in Session inactivity
| 2                  | unreadMessageChange     | Unread Messages Counter changes

### Collection eventSubscriptions

Schema
```
{
    eventIds: [Number],
    eventSubscriptionId: Number,
    eventSubscriptionTypeId: Number,
    createdAt: Date,
    updatedAt: Date,
    credentials: {
        appObjectId?: String,
        systemUserId?: Number,
    },
    returnData: {
        url: String,
    },
    
    data: { 
        sessionId: Number,
        timeout: Number
    }<subscriptionTypeId:0>,
    
    data: { 
        sessionId: Number,
        entityId: Number,
        timeout: Number
    }<subscriptionTypeId:1>,
    
    data: { 
        sessionId: Number,
        entityId: Number
    }<subscriptionTypeId:2>,
}
```

> returnData -- object for saving url where subscription values will be returned
> returnData.url -- url where subscription values will be returned
 
> data -- object containing different values depending on subscriptionTypeId
> data.sessionId -- value to know which session we are subscribed for
> data.entityId -- value to know which user we are subscribed for
> data.timeout -- value to know which time we need to use for inactivity event

> credentials -- object for saving information about access token that was used to create it
> credentials.moduleObjectId -- this value will be put, in case access token relates to module from our system
> credentials.systemUserId -- this value will be put, in case access token relates to API Credentials 



Values

| subscriptionId | subscriptionTypeId | credentials | returnData | data |
| -------------- | ------------------ | ----------- | ---------- | ---- |
| 0              | 0```<session inactivity>``` | { systemUserId: 56 } | { url: 'https://google.com/rake/sesison-inactivity'} | { sessionId: 34, timeout: 15 * 60 * 1000 } |
| 1              | 1```<session entity inactivity>``` | { moduleObjectId: '619257e300a9c1000a0339a3' } | { url: '/inactivity/session/entity' } | { sessionId: 78, entityId: 45, timeout: 60 * 1000 } |
| 2              | 2```<unread message counter changes>``` | { moduleObjectId: '619257e300a9c1000a0339a3'} | { url: '/messages/unreads/changes' } | { sessionId: 78, entityId: 45 } |
| 3              | 0```<session inactivity>``` | { moduleObjectId: '619257e300a9c1000a0339a3' } | { url: '/modules/:moduleFullName/sessions/:sessionId/inactivity-timeout-subscription'} | { sessionId: 123, timeout: 24 * 60 * 1000 } |
| 4              | 2```<unread message counter changes>``` | { systemUserId: 12 } | { url: 'https://google.com/rake/unread-messages'} | { sessionId: 123, entityId: 1970 } |

#### Rules
1. Session inactivity will be set false when session ends
2. User in Session inactivity will be set false when user deleted
3. Unread Messages Counter set 0 when session ends or user deleted

## API methods

host: core-service
access: workspace scope

| Verb    | Function | Description |
| ------- | -------- | -------- |
| POST    | /subscriptions     |Create subscription|
| GET     | /subscriptions/     |Get list of subscriptions|
| PUT     | /subscriptions/:subscriptionId |Update subscription|
| PATCH   | /subscriptions/:subscriptionId |Partialy update subscription|
| DELETE  | /subscriptions/:subscriptionId |Delete subscription|

### Create subscription

Metod:POST 
URL: /subscriptions
Headers: ```{ Authorization: UserAccessToken | ApiAccessToken }```
Body:
```
{
    subscriptionTypeId: Number,
    returnData: Object,
    data: Object
}
```

### GET subscription

Metod:GET
Headers: ```{ Authorization: UserAccessToken | ApiAccessToken }```
Query params:

| name | required | description 
| ---- | -------- | -----------
| sessionId | no  |
| entityId  | no  |

> Verification on what must be returned will be implemented on value of field: ```headers.Authorization```


### Update subscription

Metod:PUT
Headers: ```{ Authorization: UserAccessToken | ApiAccessToken }```
Body:
```
{
    returnData: Object,
    data: Object
}
```

### Partialy Update subscription

Metod:PATCH
Headers: ```{ Authorization: UserAccessToken | ApiAccessToken }```
Body:
```
{
    returnData?: Object,
    data?: Object
}
```

### Delete subscription

Metod:DELETE
Headers: ```{ Authorization: UserAccessToken | ApiAccessToken }```
