momentum-mod / website

Momentum Mod's main website.
https://momentum-mod.org
MIT License
58 stars 59 forks source link

Support arrays of DTOs on MapCredit and MapImage create/update/delete endpoints #808

Closed tsa96 closed 1 year ago

tsa96 commented 1 year ago

Currently when we update map images or credits on the frontend, we have to send a big batch of individual HTTP requests for each change. I really dislike this approach, as it spams our backend - with writes!

Array checks are one of least upsetting type-checks in JavaScript, we can easily allow these endpoints to receive and return DTO | DTO[] and do a type guard. The actual create/update/delete logic can be done in separate private functions which are either called once (individual DTOs) or multiple times (arrays).

We could only accept arrays, but we are an API, accepting single values seems reasonable.

Once the backend is refactored, update the frontend code to use arrays (singleton arrays ares fine of course). Should make that code significantly simpler, especially given some of the RxJS forkJoins we have to do because of the current system.

Note, for the new MapTestingRequest endpoints we'll be supporting this pattern out of the box.