1

I have a document collection "Projects", a document collection "Sheets" and a edge collection "ProjectToSheets".

When posting a new sheet I want to insert the sheet in the sheet collection and add an edge between the (existing) project and the new sheet in the ProjectToSheet collection.

In the post route of the sheet service I could copy paste the code of the projectToSheet route like this (simplyfied):

router.post(function (req, res) {
  const sheet = req.body;
  let meta;
  try {
     meta = Sheets.save(sheet);
     //Copy&Paste code. Bad :-(
     meta = ProjectToSheets.save(projectToSheet._from, projectToSheet._to, projectToSheet); 
     ...

But I'm pretty sure there must be a better way to do this and avoid copy&paste.

Sven Bardos
  • 872
  • 10
  • 27
  • Hi, please give a complete example. You are using variables that are defined outside of the code you have provided. – Jan Christoph Uhde Jan 29 '18 at 11:01
  • @JanChristophUhde: I don't think the exact code is important here. It's more a general question: How to re-use code of one router in another and avoid duplicating code. – Sven Bardos Jan 29 '18 at 14:21

0 Answers0