# v1.17
## Feature and tasks
### Use localization objects for all API responses
* Update UI interface logic for using localizationMongoId from response
* Стандартизація API responses:
| method | status code | response format | description |
| ------ | ----------- | --------------- | ----------- |
| POST | 200 | ```{}``` | return object what was created or null
| GET | 200 | ```{} || [{}]``` | return object was founded or array of objects or null
| PUT, PATCH | 200 | ```{}``` | return current state of object what was updated
| * | 400 | ```{ message: localizaedMessageByDefaultLanguage, localizationId: mongoOjectId, code: number, data: {} }``` |
| * | 401 | ```{ message: localizaedMessageByDefaultLanguage, localizationId: mongoOjectId, data: {} }``` | повертається у випадку коли авторизаційний токен не є активний
| * | 403 | ```{ message: localizaedMessageByDefaultLanguage, localizationId: mongoOjectId, data: {} }``` | повертається у випадку коли авторизаційний токен не дає права на використання цього API запиту
| * | 404 | ```{ message: localizaedMessageByDefaultLanguage, localizationId: mongoOjectId, data: {} }``` | returned only in case when route was not found
| * | 500 | ```{ message: localizaedMessageByDefaultLanguage, localizationId: mongoOjectId, data: {}}``` | Повертається у випадку не передбачуваної помилки
* Винести кожне API повідомлення в локалізацію, і добавити в поле errorCode для відповідних локалізацій
* Зміни у структурі БД:
* localizations
```
before:
{
_id: mongoOjectId,
languages: [{ code: string, text: string }],
}
now:
{
_id: mongoOjectId,
languages: [{ code: string, text: string }],
errorCode: { type: number, unique: true },
systemReference: { type: string, unique: true }
}
```
* Додати в редіс кешований об'єкт кодів помилок відносно локалізації
```
localization_errorCode: {
[localizationMongoId]: { errorCode: number },
}
```
* Стоврити enum для простішого доступу до значень локалізацій. Використати схему з івентами
* Створити мідлвеєр який буде тягнути для кожного запиту системну стандартну мову
* Конвертувати усі API responses
```
before:
return res.status(400).send({ message: string, code?: number });
now:
return errorResponse(res, localizationMongoId, { [propertyName]: value })
Examples:
return res.status(400).send({ message: 'Field entityId was not found', code: 56});
return errorResponse(res, localizationEnum.http.missed, { field: 'entityId' })
return res.status(400).send({ message: 'Field workspaceId was not found', code: 56});
return errorResponse(res, localizationEnum.http.missed, { field: 'workspaceId' })
return res.status(400).send({ message: 'Field workspaceId has incorrect value format', code: 57});
return errorResponse(res, localizationEnum.http.typeMismatch, { field: 'workspaceId' })
```
### System events in RabbitMQ
* Create new service for rabbitmq events
* JIRA: https://chatbots-studio.atlassian.net/browse/W5GOL-2917
* service name: rabbitmq-events-handler
* ENV: google app engine
* Schema:

* Додати логіку по мінотирнгу стомп черг, да видалнню пустих. TTL: 30s
* Видалити логіку binding черги до топіка системних івентів на сервісах:
* main worker
* user app worker
* Додати логіку на redis-rabbitmq-event-handler для відловлювання стомп ключів
### External API "1 for all"
* Усі між системні(server-to-server) виклики будуть використовувати домени сервісів. Інтерфейси в свою чергу будуть використовувати https://api.rake.ai
* API documentation has complete method reference
- Get all API paramaters, request bodies, response bodies, and field descriptions into documentation
* Create Get Token method for using API
* Зміни у структурі БД:
* systemFunctions
```
before:
{
systemApplicationId": 0,
systemFunctionId": 535,
function": "/zapier",
description": "Zapier platform",
parentId": 66,
permissionLevel": "workspace",
availablePermissionTypeIds": [ 1, 2, 3, 4 ]
}
now:
{
systemApplicationId": 0,
systemFunctionId": 535,
function": "/zapier",
description": "Zapier platform",
parentId": 66,
permissionLevel": "workspace",
availablePermissionTypeIds": [ 1, 2, 3, 4 ],
regExp: "^/zapier$"
}
```
* Додати в редіс кешовані дані для регулярних виразів
```
systemFunctions_regExp: [{
regEx: systemFunction.regEx,
systemfunctionId: systemFunction.systemFunctionId
}]
```
## Create new service for handle request on domain: api.rake.ai
* JIRA:
* service name: api-service
* ENV:
* cloud run - простіший алгоритм маштабування, який базується на кількості конкуретних запитів на сервіс
* google app engine
* Schema

* Впершу чергу перевірити швидкість опрацювання запитів в сиутація, коли ми будем мати обробник з псевдо редірктом
* Convert Rake Direct call from secret to token/system function.
### System events
* add to each system event correct description in DB
* create documentation when this system event will be created
### Event triggers
* add to each event trigger correct description in
### Localizations
* Зміни у структурі БД:
```
before:
{
_id: mongoOjectId,
languages: [{ code: string, text: string }],
}
now:
{
_id: mongoOjectId,
languages: [{ code: string, text: string }],
systemAplicationIds: [number]
}
```
### Update invitation collection structure
We need to use the scope field.
Current structure:
```json=
{
"channelIds" : number[],
"invitationTypeId" : number,
"conditions" : number[],
"roleIds" : number[],
"token" : string,
"workspaceId" : number,
"projectId" : number,
"organizationId" : number,
"createdAt" : ISODate,
"invitationId" : number,
}
```
Must be:
```json=
{
"channelIds" : number[],
"invitationTypeId" : number,
"conditions" : number[],
"roleIds" : number[],
"token" : string,
"scope": {
"type": string, RENAME TO (typeId) as string =>
because in roles collections we have such naming,
it would be better to have consistent ???
"id": number
},
"createdAt" : ISODate,
"invitationId" : number,
}
```
Update structure of DB collection and write a script to convert existsting records
Update API methods where we use invitations(registration, system user permission(invite by link))
1) /projects/:projectId/system-users
2) /organizations/:organizationId/system-users
3) /workspaces/:workspaceId/system-users
4) /system-users/invite
5) /workspaces/:workspaceId/invitations POST, DELETE, GET, PUT
6) /workspaces/:workspaceId/invitations/default POST
7) /workspaces/:workspaceId/invitations/system-users/:systemUserId
8) /system-users/register