Skip to content

Commit

Permalink
chore: add, edit, remove, bulk remove #447
Browse files Browse the repository at this point in the history
  • Loading branch information
svendjanis committed Dec 3, 2022
1 parent dd80141 commit 4f1ed26
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();
}
Expand All @@ -45,7 +47,11 @@ export class MongoDatabaseService extends DbService {
}

setDocument(moduleId, id, data) {
return this.http.post<any>(`/api/document/${moduleId}`, data);
if (this.router.url.includes('new')) {
return this.http.post<any>(`/api/document/${moduleId}`, data)
} else {
return this.http.put<any>(`/api/document/${moduleId}/${id}`, data)
}
}

url(url: string) {
Expand Down Expand Up @@ -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,
}));
}));
Expand Down
2 changes: 1 addition & 1 deletion server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down

0 comments on commit 4f1ed26

Please sign in to comment.