SO, turns out project_4 is quite messy, and I don't wanna overwhelm you guys with another 50+ file changes in a single PR, so I decided to clean up and split it up to smaller merges.
This PR is really just defining server endpoints for Destination API.
Defined some destination routes that we are/will probably use in frontend. So far, these three endpoints:
createDestination
getDestinationByTrecipeId: this one is implemented by first finding the trecipe document with given uuid, then using mongoose's populate method to fill in its destinations field. Since each destWithStatus object in destinations field has a virtual field acting as foreign key to actual destination mode, MongoDB is able to populate the field with actual destinations document.
getDestinationById
Other notable changes:
We currently have just too many versions of interfaces representing the same model! One on client, one on server, one for OpenAPI documentation..... Everytime there's a change in model we end up having to duplicate the updates. So, I decided to move the files defining models into a shared folder, which is supposed to be both accessible from the server and the client.
I've already switched the server to use the models in the shared folder, but I haven't touched the client. Will do that in next PR (which is to connect the endpoints up)
Flipped the order of some then and catch blocks in server services. The reason being, if in a then block, we return a promise rejection and there is a catch block following, then the rejection just gets caught immediately by that following catch block (rather than the catch block of the calling method).
SO, turns out project_4 is quite messy, and I don't wanna overwhelm you guys with another 50+ file changes in a single PR, so I decided to clean up and split it up to smaller merges.
This PR is really just defining server endpoints for Destination API.
Defined some destination routes that we are/will probably use in frontend. So far, these three endpoints:
createDestination
getDestinationByTrecipeId
: this one is implemented by first finding the trecipe document with given uuid, then using mongoose'spopulate
method to fill in itsdestinations
field. Since eachdestWithStatus
object indestinations
field has a virtual field acting as foreign key to actual destination mode, MongoDB is able to populate the field with actual destinations document.getDestinationById
Other notable changes:
shared
folder, which is supposed to be both accessible from the server and the client. I've already switched the server to use the models in the shared folder, but I haven't touched the client. Will do that in next PR (which is to connect the endpoints up)