How do I filter out a value returned from a GET method?

27 Views Asked by At

In my backend, I have a method that retrieves a list of reasons that I create in the admin application. With those reasons created, in my client application I can select the reason for void.

The problem: I have a reason called: "Host System" which needs to be excluded from the UI when the client is selecting a reason for voiding.

This is my .get method:

// Get all.
            .get("/", async (ctx) => {
                // Get all void reasons.
                const voidReasons: TypeAssertion.FriendlyObjectType[] = [];
                for (const markerVoidReason of await MarkerVoidReasonRepository.instance.getList(VoidReasonTypes.Void)) {
                    voidReasons.push(this.mapFrom(markerVoidReason));
                }

                ctx.response.body = voidReasons;
            })

What I tried: I tried excluding the reason from the get method like this:

// Get all.
            .get("/", async (ctx) => {
                // Get all void reasons.
                const voidReasons: TypeAssertion.FriendlyObjectType[] = [];
                for (const markerVoidReason of await MarkerVoidReasonRepository.instance.getList(VoidReasonTypes.Void)) {
                    if (markerVoidReason.name !== "Host System"){
                        voidReasons.push(this.mapFrom(markerVoidReason));
                    }
                }

                ctx.response.body = voidReasons;
            })

This solution also removed the reason from the admin application which I don't want. I want to keep the reason in the UI of the admin application but should be removed from the client application as a reason. The client and main use the same endpoint which I think could be the problem. I'm assuming the solution would be to add another get method that calls the client screen and exclude the reason but how can I do that if the endpoint is universal?

0

There are 0 best solutions below