UNPKG

@replyke/express

Version:

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

38 lines (37 loc) 1.33 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 } = 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; } // Search for the list using Sequelize's findOne method. let list = (await models_1.List.findOne({ where: { projectId, // Ensure the types match userId: loggedInUserId, 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, }); } };