This commit is contained in:
Kajal Thakur 2025-01-21 15:41:35 +05:30
parent aa77000150
commit b5aefb147a

View File

@ -146,10 +146,15 @@ let attributesData = {
}; };
// CREATE - Add or update attributes dynamically from "activities" // CREATE - Add or update attributes dynamically from "activities"
// POST /activities
app.post("/activities", (req, res) => { app.post("/activities", (req, res) => {
console.log("POST /activities hit");
console.log("Request Body:", req.body); // Log the entire request body
const { activities } = req.body; const { activities } = req.body;
if (!activities || typeof activities !== "object") { if (!activities || typeof activities !== "object") {
console.log("Error: Activities must be an object");
return res.status(400).json({ error: "Activities must be an object" }); return res.status(400).json({ error: "Activities must be an object" });
} }
@ -159,24 +164,31 @@ app.post("/activities", (req, res) => {
value, value,
})); }));
console.log("Transformed Attributes:", attributes); // Log transformed attributes
// Add or update attributes // Add or update attributes
for (const attribute of attributes) { for (const attribute of attributes) {
const existingIndex = attributesData.attributes.findIndex( const existingIndex = attributesData.attributes.findIndex(
(item) => item.key === attribute.key (item) => item.key === attribute.key
); );
if (existingIndex !== -1) { if (existingIndex !== -1) {
console.log(
`Updating existing attribute: ${attribute.key} with value: ${attribute.value}`
);
attributesData.attributes[existingIndex].value = attribute.value; attributesData.attributes[existingIndex].value = attribute.value;
} else { } else {
console.log(`Adding new attribute: ${attribute.key} with value: ${attribute.value}`);
attributesData.attributes.push(attribute); attributesData.attributes.push(attribute);
} }
} }
console.log("Updated Attributes Data:", attributesData.attributes); // Log updated attributes data
res.status(201).json({ res.status(201).json({
message: "Activities processed successfully", message: "Activities processed successfully",
attributes: attributesData.attributes, attributes: attributesData.attributes,
}); });
}); });
// READ - Get all attributes // READ - Get all attributes
app.get("/attributes", (req, res) => { app.get("/attributes", (req, res) => {
res.json({ res.json({