UNPKG

@replyke/express

Version:

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

53 lines (52 loc) 1.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const sequelize_1 = require("sequelize"); const models_1 = require("../../../models"); exports.default = async (req, res) => { try { // Extract projectId and userId from query parameters. const { entityId, userId: userIdProp } = req.query; const loggedInUserId = req.userId; const projectId = req.project.id; if (!entityId || typeof entityId !== "string") { res.status(400).json({ error: "Missing or invalid entityId in query", code: "list/invalid-entity-id", }); return; } let userId = null; if ((req.isMaster || req.isService) && typeof userIdProp === "string") { userId = userIdProp; } else if (loggedInUserId) { userId = loggedInUserId; } // Validate the presence of userId. if (typeof userId !== "string") { res.status(400).json({ error: "Missing userId", code: "list/missing-data", }); return; } // Search for the list using Sequelize's findOne method. let list = (await models_1.List.findOne({ where: { projectId, // Ensure the types match userId, entityIds: { [sequelize_1.Op.contains]: [entityId] }, }, })); // Return the list with a 200 (OK) status. res.status(200).json(!!list); } catch (err) { console.error("Error checking if entity is saved: ", err); res.status(500).json({ error: "Internal server error.", code: "list/server-error", details: err.message, }); } };