nexusbert commited on
Commit
a90efcb
·
1 Parent(s): 0db47ae

push delete

Browse files
Files changed (1) hide show
  1. src/routes/wardrobe.ts +64 -0
src/routes/wardrobe.ts CHANGED
@@ -70,6 +70,70 @@ router.get("/", authenticateToken, async (req: AuthRequest, res) => {
70
  }
71
  });
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  export default router;
74
 
75
 
 
70
  }
71
  });
72
 
73
+ /**
74
+ * @openapi
75
+ * /api/wardrobe/{id}:
76
+ * delete:
77
+ * summary: Delete a wardrobe item
78
+ * tags: [Upload]
79
+ * security:
80
+ * - bearerAuth: []
81
+ * parameters:
82
+ * - in: path
83
+ * name: id
84
+ * required: true
85
+ * schema:
86
+ * type: integer
87
+ * description: Wardrobe item ID
88
+ * responses:
89
+ * 200:
90
+ * description: Item deleted successfully
91
+ * content:
92
+ * application/json:
93
+ * schema:
94
+ * type: object
95
+ * properties:
96
+ * success:
97
+ * type: boolean
98
+ * message:
99
+ * type: string
100
+ * 401:
101
+ * description: Unauthorized
102
+ * 403:
103
+ * description: Forbidden (item doesn't belong to user)
104
+ * 404:
105
+ * description: Item not found
106
+ * 500:
107
+ * description: Server error
108
+ */
109
+ router.delete("/:id", authenticateToken, async (req: AuthRequest, res) => {
110
+ try {
111
+ const userId = req.userId!;
112
+ const itemId = parseInt(req.params.id, 10);
113
+
114
+ if (isNaN(itemId)) {
115
+ return res.status(400).json({ success: false, error: "Invalid item ID" });
116
+ }
117
+
118
+ const repo = AppDataSource.getRepository(WardrobeItem);
119
+ const item = await repo.findOne({
120
+ where: { id: itemId, userId: userId },
121
+ });
122
+
123
+ if (!item) {
124
+ return res.status(404).json({ success: false, error: "Item not found" });
125
+ }
126
+
127
+ // Delete the item (cascade will handle related data if any)
128
+ await repo.remove(item);
129
+
130
+ res.json({ success: true, message: "Item deleted successfully" });
131
+ } catch (error: any) {
132
+ console.error("Wardrobe delete error:", error);
133
+ res.status(500).json({ success: false, error: error.message || "Failed to delete item" });
134
+ }
135
+ });
136
+
137
  export default router;
138
 
139