From 4f1ed265320b98baa197602876e9667f5bc72687 Mon Sep 17 00:00:00 2001 From: svendanis Date: Sat, 3 Dec 2022 16:05:30 +0100 Subject: [PATCH] chore: add, edit, remove, bulk remove #447 --- .../mongo-firebase/mongo-database.service.ts | 18 ++++++++++++++---- server/index.ts | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/client/projects/cms/integrations/mongo-firebase/mongo-database.service.ts b/client/projects/cms/integrations/mongo-firebase/mongo-database.service.ts index 02215057..e72407d0 100644 --- a/client/projects/cms/integrations/mongo-firebase/mongo-database.service.ts +++ b/client/projects/cms/integrations/mongo-firebase/mongo-database.service.ts @@ -17,6 +17,7 @@ import { where } from '@angular/fire/firestore'; import {Functions, httpsCallableData} from '@angular/fire/functions'; +import {Router} from '@angular/router'; import {FilterMethod, SHARED_CONFIG} from '@definitions'; import {Parser} from '@jaspero/form-builder'; import {from, Observable, of} from 'rxjs'; @@ -33,7 +34,8 @@ export class MongoDatabaseService extends DbService { constructor( private firestore: Firestore, private functions: Functions, - private http: HttpClient + private http: HttpClient, + private router: Router ) { super(); } @@ -45,7 +47,11 @@ export class MongoDatabaseService extends DbService { } setDocument(moduleId, id, data) { - return this.http.post(`/api/document/${moduleId}`, data); + if (this.router.url.includes('new')) { + return this.http.post(`/api/document/${moduleId}`, data) + } else { + return this.http.put(`/api/document/${moduleId}/${id}`, data) + } } url(url: string) { @@ -82,8 +88,12 @@ export class MongoDatabaseService extends DbService { } return data.data.map(it => ({ - id: it.id, - ref: it, + id: it._id, + ref: { + parent: { + path: moduleId + } + }, data: () => it, })); })); diff --git a/server/index.ts b/server/index.ts index bad1ca9f..15692ad9 100644 --- a/server/index.ts +++ b/server/index.ts @@ -46,7 +46,7 @@ app.post('/api/document/:moduleId', (req, res) => { .catch(); }); -app.put('/api/document/:moduleId', (req, res) => { +app.put('/api/document/:moduleId/:documentId', (req, res) => { return db.collection(req.params.moduleId).updateOne({_id: new ObjectId(req.params.documentId)}, { $set: req.body })