test01
This commit is contained in:
parent
aa77000150
commit
b5aefb147a
14
index.js
14
index.js
|
|
@ -146,10 +146,15 @@ let attributesData = {
|
|||
};
|
||||
|
||||
// CREATE - Add or update attributes dynamically from "activities"
|
||||
// POST /activities
|
||||
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;
|
||||
|
||||
if (!activities || typeof activities !== "object") {
|
||||
console.log("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,
|
||||
}));
|
||||
|
||||
console.log("Transformed Attributes:", attributes); // Log transformed attributes
|
||||
|
||||
// Add or update attributes
|
||||
for (const attribute of attributes) {
|
||||
const existingIndex = attributesData.attributes.findIndex(
|
||||
(item) => item.key === attribute.key
|
||||
);
|
||||
if (existingIndex !== -1) {
|
||||
console.log(
|
||||
`Updating existing attribute: ${attribute.key} with value: ${attribute.value}`
|
||||
);
|
||||
attributesData.attributes[existingIndex].value = attribute.value;
|
||||
} else {
|
||||
console.log(`Adding new attribute: ${attribute.key} with value: ${attribute.value}`);
|
||||
attributesData.attributes.push(attribute);
|
||||
}
|
||||
}
|
||||
|
||||
console.log("Updated Attributes Data:", attributesData.attributes); // Log updated attributes data
|
||||
|
||||
res.status(201).json({
|
||||
message: "Activities processed successfully",
|
||||
attributes: attributesData.attributes,
|
||||
});
|
||||
});
|
||||
|
||||
// READ - Get all attributes
|
||||
app.get("/attributes", (req, res) => {
|
||||
res.json({
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user