Spaces:
Running
Running
fix(tool): fix unfeature functionality
Browse files
src/routes/tools/[toolId]/+page.server.ts
CHANGED
@@ -118,23 +118,23 @@ export const actions: Actions = {
|
|
118 |
return fail(403, { error: true, message: "Permission denied" });
|
119 |
}
|
120 |
|
121 |
-
const
|
122 |
-
_id: new ObjectId(params.
|
123 |
});
|
124 |
|
125 |
-
if (!
|
126 |
-
return fail(404, { error: true, message: "
|
127 |
}
|
128 |
|
129 |
-
const result = await collections.
|
130 |
-
{ _id:
|
131 |
{ $set: { featured: false } }
|
132 |
);
|
133 |
|
134 |
if (result.modifiedCount === 0) {
|
135 |
-
return fail(500, { error: true, message: "Failed to unfeature
|
136 |
}
|
137 |
|
138 |
-
return { from: "unfeature", ok: true, message: "
|
139 |
},
|
140 |
};
|
|
|
118 |
return fail(403, { error: true, message: "Permission denied" });
|
119 |
}
|
120 |
|
121 |
+
const tool = await collections.tools.findOne({
|
122 |
+
_id: new ObjectId(params.toolId),
|
123 |
});
|
124 |
|
125 |
+
if (!tool) {
|
126 |
+
return fail(404, { error: true, message: "Tool not found" });
|
127 |
}
|
128 |
|
129 |
+
const result = await collections.tools.updateOne(
|
130 |
+
{ _id: tool._id },
|
131 |
{ $set: { featured: false } }
|
132 |
);
|
133 |
|
134 |
if (result.modifiedCount === 0) {
|
135 |
+
return fail(500, { error: true, message: "Failed to unfeature tool" });
|
136 |
}
|
137 |
|
138 |
+
return { from: "unfeature", ok: true, message: "Tool unfeatured" };
|
139 |
},
|
140 |
};
|