smk-chat/docs.md

140 lines
3.6 KiB
Markdown
Raw Normal View History

2024-06-21 13:01:40 +03:00
# Docs for smk-chat
## API
### /api/getCredentialsById/:userId
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
IN: _userId_ (in route)
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
OUT: _lastname_, _firstname_, _middlename_
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Return credentials of the user whose id is userId.
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Return -1 if no such user exist.
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Requires client to be logged in.
### /api/getIdByCredentials
IN: _lastname_, _firstname_, _middlename_
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
OUT: _UserID_
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Returns an ID of the user, whose lastname, firstname and middlename were passed.
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Returns -1 if user does not exist.
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Requires client to be logged in.
### /api/getMessagesFromChat/by-amount
IN: _chatId_, _amount_
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
OUT: array of objects that represent a message, like {"author_id": ..., time_sent: ..., content: ...}
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Returns an array of last _amount_ ordered by date of described objects if everything is okay
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Returns HTTP/1.1 400 "Chat with id _ID_ does not exist." if no chat with supplied id does not exist.
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Returns HTTP/1.1 403 "You are not a member of this chat" if the statement is true ;)
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Requires client to be logged in.
### /api/getMessagesFromChat/by-time
IN: _chatId_, _fromTimestamp_, _toTimestamp_
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
OUT: array of objects that represent a message, like {"author_id": ..., time_sent: ..., content: ...}
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
_fromTimestamp_ must be lower that _toTimestamp_, otherwise it might return nothing.
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Returns an array of described objects if everything is okay
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Returns HTTP/1.1 400 "Chat with id _ID_ does not exist." if no chat with supplied id does not exist.
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Returns HTTP/1.1 200 and an empty string if no messages in chat are found /shrug.
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Requires client to be logged in.
### /api/getChats
IN: _UserID_
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
OUT: Array of chat IDs
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Returs an array with ids of chats which user with passed ID is member in.
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Return empty string if user has no membership in any chat.
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Requires client to be logged in.
### /api/getChatInfo/:chatId
IN: _chatId_ (in route)
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
OUT: JSON describes a chat with id: {name: ..., admins: ..., members: ...}
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Note: JSON does not include messages. You have to use __/api/getMessagesFromChat__ to query messages.
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Returns aforementioned json if the chat exists and user is a member of this chat.
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Returns -1 if chat does not exist
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Return -2 if user is not a member of the chat
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Requires client to be logged in.
### /api/createChat
IN: _UserId_, array of UserIDs that are to be invited.
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
OUT: "Ok" if successful, "User with id _MEMBERID_ does not exist."
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Return -1 if amout of users to invite is 0.
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Requires client to be logged in
### /api/logout
IN: none.
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
OUT: redirect to __/login__.
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Removes client's session, thus unlogging a user.
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Requires client to be logged in.
### /api/register
IN: _lastname_, _firstname_, _middlename_, _password_
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
OUT: redirect to __/__
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Checks if user exist. If so, returns 400 with response "Such user exists.".
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Otherwise, registers a user with given data.
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Requires clinet to be not logged in.
### /api/login
IN: _lastname_, _firstname_, _middlename_, _password_
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
OUT: redirect to __/__
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Checks if user exists. If not, returns 400 with response "No such user.".
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Otherwise, compares passwords
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
If passwords match, creating session and redirects to __/__
2024-06-21 13:05:19 +03:00
2024-06-21 13:01:40 +03:00
Requires client to be not logged in.
2024-06-21 16:26:34 +03:00
## Deployment
### Traditional
To deploy an application in traditional way, follow these steps:
1. edit ``config.json`` to your needs.
2. Install dependencies: ``npm i``
3. Run __src/index.js__. Use ``npm run prod`` if you want to run it as a production and ``npm run dev`` if you want to run it with nodemon.
### Docker
To deploy an application with Docker, you need to:
1. edit ``config.json`` to your needs ( do not forget that backend must be able to connect to db container.)
2. edit ``docker-compose.yml`` as with the data you've wrote to ``config.json``
3. Build and launch: ``docker-compose up --build``