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 80d6c2b8..1db0ca16 100644 --- a/client/projects/cms/integrations/mongo-firebase/mongo-database.service.ts +++ b/client/projects/cms/integrations/mongo-firebase/mongo-database.service.ts @@ -1,3 +1,4 @@ +import {HttpClient} from '@angular/common/http'; import {Injectable} from '@angular/core'; import { collection, @@ -32,11 +33,20 @@ import {environment} from '../../src/environments/environment'; export class MongoDatabaseService extends DbService { constructor( private firestore: Firestore, - private functions: Functions + private functions: Functions, + private http: HttpClient ) { super(); } + removeDocument(moduleId, id) { + return this.http.delete(`/api/document/${moduleId}/${id}`); + } + + setDocument(moduleId, id, data) { + return this.http.post(`/api/document/${moduleId}`, data); + } + url(url: string) { if (environment.origin) { @@ -61,22 +71,8 @@ export class MongoDatabaseService extends DbService { source?, collectionGroup? ) { - const sources = { - server: getDocsFromServer, - cache: getDocsFromCache - }; - const method = source ? sources[source] : getDocs; - - return from( - method( - this.collection(moduleId, pageSize, sort, cursor, filters, collectionGroup) - ) - ) - .pipe( - map((res: any) => - res.docs - ) - ); + console.log(moduleId); + return this.http.get(`/api/documents/${moduleId}`); } getStateChanges( @@ -209,31 +205,31 @@ export class MongoDatabaseService extends DbService { ); } - setDocument(moduleId, documentId, data, options) { - return from( - setDoc( - doc( - this.firestore, - moduleId, - documentId - ), - data, - options || {} - ) - ); - } + // setDocument(moduleId, documentId, data, options) { + // return from( + // setDoc( + // doc( + // this.firestore, + // moduleId, + // documentId + // ), + // data, + // options || {} + // ) + // ); + // } - removeDocument(moduleId, documentId) { - return from( - deleteDoc( - doc( - this.firestore, - moduleId, - documentId - ) - ) - ); - } + // removeDocument(moduleId, documentId) { + // return from( + // deleteDoc( + // doc( + // this.firestore, + // moduleId, + // documentId + // ) + // ) + // ); + // } createUserAccount(email: string, password: string) { return this.callFunction('cms-createUser', {email, password}) as any; diff --git a/server/index.ts b/server/index.ts index c53c4145..60f0efed 100644 --- a/server/index.ts +++ b/server/index.ts @@ -2,7 +2,7 @@ import * as express from "express"; import {MongoClient, ObjectId} from 'mongodb'; const app = express(); -const port = 5200; +const port = 4200; app.use(express.json()); @@ -20,6 +20,18 @@ app.get('/api/document/:moduleId/:documentId', (req, res) => { .catch(); }); +app.get('/api/documents/:moduleId', (req, res) => { + async function exec() { + const cursor = db.collection(req.params.moduleId).find({}); + const data = await cursor.toArray(); + console.log(data); + return data + } + + exec().then((data) => res.json(data)).catch(); + +}); + app.post('/api/document/:moduleId', (req, res) => { async function exec() { return db.collection(req.params.moduleId).insertOne(req.body) @@ -40,12 +52,12 @@ app.put('/api/document/:moduleId', (req, res) => { .catch(); }); -app.delete('/api/document/:moduleId', (req, res) => { +app.delete('/api/document/:moduleId/:documentId', (req, res) => { return db.collection(req.params.moduleId).deleteOne({_id: new ObjectId(req.params.documentId)}) .then((data) => res.json(data)) .catch(); }); app.listen(port, () => { - console.log(`[server]: Server is running at https://localhost:${port}`); + console.log(`[server]: Server is running at http://localhost:${port}`); });