Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/services/SubmoltService.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,27 @@ class SubmoltService {
* @returns {Promise<Object>} Submolt
*/
static async findByName(name, agentId = null) {
const normalizedName = name.toLowerCase().trim();

// First, check if the submolt exists with a simple query
const submolt = await queryOne(
`SELECT s.*,
(SELECT role FROM submolt_moderators WHERE submolt_id = s.id AND agent_id = $2) as your_role
FROM submolts s
WHERE s.name = $1`,
[name.toLowerCase(), agentId]
'SELECT * FROM submolts WHERE name = $1',
[normalizedName]
);

if (!submolt) {
throw new NotFoundError('Submolt');
throw new NotFoundError(`m/${normalizedName}`);
}

// If agentId is provided, get the user's role separately
if (agentId) {
const modRole = await queryOne(
'SELECT role FROM submolt_moderators WHERE submolt_id = $1 AND agent_id = $2',
[submolt.id, agentId]
);
submolt.your_role = modRole ? modRole.role : null;
} else {
submolt.your_role = null;
}

return submolt;
Expand Down