UNPKG

@replyke/express

Version:

Replyke: Build interactive apps with social features like comments, votes, feeds, user lists, notifications, and more.

41 lines (40 loc) 1.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const models_1 = require("../../../models"); exports.default = async (req, res) => { try { const { username } = req.query; const projectId = req.project.id; if (!username || typeof username !== "string") { res.status(400).json({ error: "Username is required and must be a string.", code: "username/invalid-input", }); return; } // Check if the username is taken within the specified project const user = await models_1.User.findOne({ where: { projectId, username, }, }); if (user) { res.status(200).json({ available: false, }); return; } res.status(200).json({ available: true, }); } catch (error) { console.error("Error checking username availability:", error); res.status(500).json({ error: "An error occurred while checking username availability.", code: "username/server-error", details: error.message, }); } };