diff --git a/server/src/projects.js b/server/src/projects.js index 074bc88..8580e95 100644 --- a/server/src/projects.js +++ b/server/src/projects.js @@ -1,7 +1,7 @@ import { addRecord, createCurriedQuery, - deleteRecord, + updateRecord, } from './utils/firestore-db.js'; import verifyFirebaseToken from './middleware/verify-token.js'; import generateRandomID from './utils/generateRandomID.js'; @@ -55,11 +55,15 @@ function registerProjectRoutes(app) { } }); - app.delete('/project/:projectId', verifyFirebaseToken, async (req, res) => { - const projectId = req.params.projectId; + app.post('/delete-project', verifyFirebaseToken, async (req, res) => { + const projectId = req.body?.projectId; try { - await deleteRecord('projects', projectId); + await updateRecord('projects', projectId, { + status: 'DELETE', + deletedOn: new Date(), + }); + res.status(200).send({ message: 'Project deleted successfully.', }); @@ -85,6 +89,7 @@ function registerProjectRoutes(app) { try { const projects = await createCurriedQuery('projects')([ ['uid', '==', uid], + ['status', '!=', 'DELETE'], ])('created')('desc')(); res.status(200).send({ diff --git a/server/src/utils/firestore-db.js b/server/src/utils/firestore-db.js index 1119247..6b51f00 100644 --- a/server/src/utils/firestore-db.js +++ b/server/src/utils/firestore-db.js @@ -33,20 +33,18 @@ async function readRecord(collectionName, docId) { } } -// async function updateRecord(collectionName, data, docId = null) { -// try { -// const docRef = docId -// ? db.collection(collectionName).doc(docId) -// : db.collection(collectionName).doc(); +async function updateRecord(collectionName, docId, data) { + try { + const docRef = db.collection(collectionName).doc(docId); -// await docRef.update(data); + await docRef.update(data); -// return docRef.id; -// } catch (error) { -// console.error('Error updating record:', error); -// throw error; -// } -// } + return docRef.id; + } catch (error) { + console.error('Error updating record:', error); + throw error; + } +} async function deleteRecord(collectionName, docId) { try { @@ -97,4 +95,10 @@ const createCurriedQuery = } }; -export { addRecord, readRecord, deleteRecord, createCurriedQuery }; +export { + addRecord, + readRecord, + updateRecord, + deleteRecord, + createCurriedQuery, +};