powr-sdk-api 4.8.6 → 4.8.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/routes/forms.js +70 -0
- package/package.json +1 -1
package/dist/routes/forms.js
CHANGED
|
@@ -241,6 +241,76 @@ router.post('/create-form', verifyToken, async (req, res) => {
|
|
|
241
241
|
}
|
|
242
242
|
});
|
|
243
243
|
|
|
244
|
+
// PUT /update-form/:formName - Update existing form schema
|
|
245
|
+
router.put('/update-form/:formName', verifyToken, async (req, res) => {
|
|
246
|
+
try {
|
|
247
|
+
const {
|
|
248
|
+
formName
|
|
249
|
+
} = req.params;
|
|
250
|
+
const projectId = req.projectId;
|
|
251
|
+
const {
|
|
252
|
+
formTitle,
|
|
253
|
+
formId,
|
|
254
|
+
description,
|
|
255
|
+
fields
|
|
256
|
+
} = req.body;
|
|
257
|
+
if (!(formTitle !== null && formTitle !== void 0 && formTitle.trim()) || !(formId !== null && formId !== void 0 && formId.trim())) {
|
|
258
|
+
return res.status(400).json({
|
|
259
|
+
success: false,
|
|
260
|
+
message: 'formTitle and formId are required'
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
if (!Array.isArray(fields) || fields.length === 0) {
|
|
264
|
+
return res.status(400).json({
|
|
265
|
+
success: false,
|
|
266
|
+
message: 'At least one field is required'
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
const db = await getDb();
|
|
270
|
+
const powrFormCollection = db.collection('powrForm');
|
|
271
|
+
const existingForm = await powrFormCollection.findOne({
|
|
272
|
+
formName,
|
|
273
|
+
projectId
|
|
274
|
+
});
|
|
275
|
+
if (!existingForm) {
|
|
276
|
+
return res.status(404).json({
|
|
277
|
+
success: false,
|
|
278
|
+
message: 'Form not found'
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
const updateData = {
|
|
282
|
+
formTitle: formTitle.trim(),
|
|
283
|
+
formId: formId.trim(),
|
|
284
|
+
description: (description === null || description === void 0 ? void 0 : description.trim()) || '',
|
|
285
|
+
fields,
|
|
286
|
+
updatedAt: new Date()
|
|
287
|
+
};
|
|
288
|
+
await powrFormCollection.updateOne({
|
|
289
|
+
formName,
|
|
290
|
+
projectId
|
|
291
|
+
}, {
|
|
292
|
+
$set: updateData
|
|
293
|
+
});
|
|
294
|
+
return res.status(200).json({
|
|
295
|
+
success: true,
|
|
296
|
+
message: 'Form updated successfully',
|
|
297
|
+
formName,
|
|
298
|
+
projectId,
|
|
299
|
+
data: {
|
|
300
|
+
...existingForm,
|
|
301
|
+
...updateData,
|
|
302
|
+
formName
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
} catch (error) {
|
|
306
|
+
return res.status(500).json({
|
|
307
|
+
success: false,
|
|
308
|
+
message: 'Error updating form',
|
|
309
|
+
error: error.message
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
|
|
244
314
|
// Get form submissions
|
|
245
315
|
router.get("/submissions", verifyToken, async (req, res) => {
|
|
246
316
|
const projectId = req.projectId; // Use middleware-injected projectId
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "powr-sdk-api",
|
|
3
|
-
"version": "4.8.
|
|
3
|
+
"version": "4.8.7",
|
|
4
4
|
"description": "Shared API core library for PowrStack projects. Zero dependencies - works with Express, Next.js API routes, and other frameworks. All features are optional and install only what you need.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|