3 Docs
leca edited this page 2024-06-21 16:27:01 +03:00

Docs for smk-chat

API

/api/getCredentialsById/:userId

IN: userId (in route)

OUT: lastname, firstname, middlename

Return credentials of the user whose id is userId.

Return -1 if no such user exist.

Requires client to be logged in.

/api/getIdByCredentials

IN: lastname, firstname, middlename

OUT: UserID

Returns an ID of the user, whose lastname, firstname and middlename were passed.

Returns -1 if user does not exist.

Requires client to be logged in.

/api/getMessagesFromChat/by-amount

IN: chatId, amount

OUT: array of objects that represent a message, like {"author_id": ..., time_sent: ..., content: ...}

Returns an array of last amount ordered by date of described objects if everything is okay

Returns HTTP/1.1 400 "Chat with id ID does not exist." if no chat with supplied id does not exist.

Returns HTTP/1.1 403 "You are not a member of this chat" if the statement is true ;)

Requires client to be logged in.

/api/getMessagesFromChat/by-time

IN: chatId, fromTimestamp, toTimestamp

OUT: array of objects that represent a message, like {"author_id": ..., time_sent: ..., content: ...}

fromTimestamp must be lower that toTimestamp, otherwise it might return nothing.

Returns an array of described objects if everything is okay

Returns HTTP/1.1 400 "Chat with id ID does not exist." if no chat with supplied id does not exist.

Returns HTTP/1.1 200 and an empty string if no messages in chat are found /shrug.

Requires client to be logged in.

/api/getChats

IN: UserID

OUT: Array of chat IDs

Returs an array with ids of chats which user with passed ID is member in.

Return empty string if user has no membership in any chat.

Requires client to be logged in.

/api/getChatInfo/:chatId

IN: chatId (in route)

OUT: JSON describes a chat with id: {name: ..., admins: ..., members: ...}

Note: JSON does not include messages. You have to use /api/getMessagesFromChat to query messages.

Returns aforementioned json if the chat exists and user is a member of this chat.

Returns -1 if chat does not exist

Return -2 if user is not a member of the chat

Requires client to be logged in.

/api/createChat

IN: UserId, array of UserIDs that are to be invited.

OUT: "Ok" if successful, "User with id MEMBERID does not exist."

Return -1 if amout of users to invite is 0.

Requires client to be logged in

/api/logout

IN: none.

OUT: redirect to /login.

Removes client's session, thus unlogging a user.

Requires client to be logged in.

/api/register

IN: lastname, firstname, middlename, password

OUT: redirect to /

Checks if user exist. If so, returns 400 with response "Such user exists.".

Otherwise, registers a user with given data.

Requires clinet to be not logged in.

/api/login

IN: lastname, firstname, middlename, password

OUT: redirect to /

Checks if user exists. If not, returns 400 with response "No such user.".

Otherwise, compares passwords

If passwords match, creating session and redirects to /

Requires client to be not logged in.

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