fix: allow folderId in updateDocument and pass it through route handler
- Add folderId parameter to updateDocument service method - Extract folderId from request body in PUT /documents/:id route - Fixes move document to folder functionality
This commit is contained in:
@@ -78,7 +78,7 @@ router.get('/:id', async (req, res) => {
|
|||||||
// PUT /documents/:id - Update document
|
// PUT /documents/:id - Update document
|
||||||
router.put('/:id', async (req, res) => {
|
router.put('/:id', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { title, content, tags, type, priority, status } = req.body;
|
const { title, content, tags, type, priority, status, folderId } = req.body;
|
||||||
const docService = getDocumentService();
|
const docService = getDocumentService();
|
||||||
const doc = await docService.updateDocument(req.params.id, {
|
const doc = await docService.updateDocument(req.params.id, {
|
||||||
title,
|
title,
|
||||||
@@ -87,6 +87,7 @@ router.put('/:id', async (req, res) => {
|
|||||||
type,
|
type,
|
||||||
priority,
|
priority,
|
||||||
status,
|
status,
|
||||||
|
folderId,
|
||||||
});
|
});
|
||||||
res.json(doc);
|
res.json(doc);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -469,7 +469,7 @@ export class DocumentService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateDocument(docId, { title, content, tags, type, priority, status }) {
|
async updateDocument(docId, { title, content, tags, type, priority, status, folderId }) {
|
||||||
const found = this._findDocById(docId);
|
const found = this._findDocById(docId);
|
||||||
if (!found) {
|
if (!found) {
|
||||||
throw new NotFoundError('Document');
|
throw new NotFoundError('Document');
|
||||||
@@ -484,6 +484,7 @@ export class DocumentService {
|
|||||||
if (priority !== undefined) meta.priority = priority;
|
if (priority !== undefined) meta.priority = priority;
|
||||||
if (status !== undefined) meta.status = status;
|
if (status !== undefined) meta.status = status;
|
||||||
if (tags !== undefined) meta.tags = tags.filter(t => t);
|
if (tags !== undefined) meta.tags = tags.filter(t => t);
|
||||||
|
if (folderId !== undefined) meta.folderId = folderId;
|
||||||
meta.updatedAt = now;
|
meta.updatedAt = now;
|
||||||
|
|
||||||
// Rewrite markdown file
|
// Rewrite markdown file
|
||||||
|
|||||||
Reference in New Issue
Block a user