Global

Members

(constant) addFollower

Middleware to add a follower to a user.
Source:

(constant) checkAdminPermission

Middleware to check if the current user is an admin of a chat group.
Source:

(constant) checkBlockedInChat

Middleware to check if the user has been blocked from a specific chat group.
Source:

(constant) checkChatOwnership

Middleware to check if the current user is the owner of a chat message.
Source:

(constant) checkChatPermission

Middleware to check if the user allows chats from non-followers.
Source:

(constant) checkGroupMembership

Middleware to check if the user is a member of a chat group.
Source:

(constant) checkRole

Middleware to check if a user has a specific role (e.g., MODERATOR, ADMIN, OWNER) in a chat group.
Source:

(constant) createChatGroup

Create a new chat group.
Source:

(constant) createComment

Create a new comment.
Source:

(constant) createPost

Create a new post.
Source:

(constant) deleteChat

Delete a chat message by ID.
Source:

(constant) deleteChatGroup

Delete a chat group by ID.
Source:

(constant) deleteComment

Delete an existing comment.
Source:

(constant) deletePost

Delete an existing post.
Source:

(constant) getAllPosts

Get all posts with optional filtering.
Source:

(constant) getChatsByGroup

Get all chats in a chat group by chatGroupId.
Source:

(constant) getCommentsByPost

Get all comments for a specific post.
Source:

(constant) getPost

Get a single post by ID.
Source:

(constant) joinChatGroup

Join a chat group.
Source:

(constant) leaveChatGroup

Leave a chat group.
Source:

(constant) login

Login a user.
Source:

(constant) register

Register a new user.
Source:

(constant) removeFollower

Middleware to remove a follower from a user.
Source:

(constant) sendChat

Send a new message in a chat.
Source:

(constant) updateChat

Update a chat message.
Source:

(constant) updateChatGroup

Update a chat group.
Source:

(constant) updateComment

Update an existing comment.
Source:

(constant) updatePost

Update an existing post.
Source:

Methods

(async) authMiddleware(req, res, next) → {Promise.<void>}

Middleware for authenticating users by verifying JWT tokens. The middleware extracts the token from the `Authorization` header, verifies it, and attaches the user object to the request. If the token is missing, invalid, or if the user is not found, a 401 Unauthorized response is returned.
Parameters:
Name Type Description
req CustomRequest Express request object, extended to include the user property.
res Response Express response object.
next NextFunction Express next middleware function.
Source:
Returns:
- Calls `next()` if the token is valid, otherwise returns a 401 Unauthorized response.
Type
Promise.<void>
Example
// Use authMiddleware in a route
app.get('/protected', authMiddleware, (req, res) => {
  res.json({ message: 'Protected resource' });
});

canPerformAction(userRole, requiredRole) → {boolean}

Utility function to check if a user can perform an action based on their role.
Parameters:
Name Type Description
userRole ChatRole The role of the user.
requiredRole ChatRole The minimum role required for the action.
Source:
Returns:
- True if the user has sufficient permissions, false otherwise.
Type
boolean

(async) checkBlocked(req, res, next) → {Promise.<void>}

Middleware to check if the user is blocked by the author or banned from the site. This middleware checks if the current user is blocked by the author (based on `authorId` from the request body) or if the user is banned (temporarily or permanently) from the platform. If the user is blocked or banned, a 403 Forbidden response is returned. Otherwise, the request proceeds to the next middleware.
Parameters:
Name Type Description
req CustomRequest Express request object, extended to include the user property.
res Response Express response object.
next NextFunction Express next middleware function.
Source:
Returns:
- Calls `next()` if the user is not blocked or banned, otherwise returns a 403 Forbidden response.
Type
Promise.<void>
Example
// Use checkBlocked middleware in a route
app.post('/messages', checkBlocked, sendMessage);

checkOwnership(resourceType, userIdField) → {function}

Middleware to check if the user is the owner of a resource.
Parameters:
Name Type Description
resourceType string The Prisma model (e.g., 'post', 'comment', 'chat').
userIdField string The field representing the owner (e.g., 'authorId').
Source:
Returns:
Express middleware function.
Type
function
Example
router.delete('/:id', checkOwnership('chat', 'authorId'), deleteChat);

checkRole(roles) → {function}

Middleware to check if the user has the necessary role to access the resource. This middleware verifies if the user's role matches any of the allowed roles. If the user's role is included in the allowed roles, the request proceeds to the next middleware or route handler. Otherwise, a 403 Forbidden response is returned.
Parameters:
Name Type Description
roles Array.<string> Array of allowed roles (e.g., ['ADMIN', 'MODERATOR']).
Source:
Returns:
Express middleware function.
Type
function
Example
// Use checkRole in a route to allow only admins and moderators
app.post('/admin', checkRole(['ADMIN', 'MODERATOR']), adminHandler);