javascript – What’s the proper way to do MongoDB aggregation query with optional parameters?

I have this api endpoint where i want to lookup a user or multiple users schedule and also specify the month or/and the day when doing the query. My code works, but i feel like there is a better, cleaner way to do this.

From the frontend i do a get request that has the following query params.

http://localhost:5000/api/schedule/?name=John Doe&name=Sam Smith&month=July 2020&day=Wed Jul 15 2020 00:00:00 GMT+0300

then this api controller will take the req.query obj and use it to do a custom query. I wanted the options like month or day to be optional and still get a result if they are omitted.

    exports.find_by_query = async (req, res) => {
      let day;
      let month;
      let name;
      const query = ({ $match: {} });
      const filter = { name: {} };
    
      if (req.query.name) {
        name = req.query.name;
        filter.name = { $in: name };
        query(0).$match = filter;
      }
    
      if (req.query.day) {
        const date = new Date(req.query.day);
        date.setHours(0, 0, 0, 0);
        day = date.toString().split("(Eastern European Summer Time)")(0).trim();
      }
    
      if (req.query.month) {
        month = req.query.month;
      }
    
       if (month !== undefined && day === undefined) {
    query.push({
      $group: {
        _id: `$shifts.${month}`,
        count: { $sum: 1 },
        result: { $push: { name: "$name" } },
      },
    });
  }
  if (day !== undefined) {
    query.push({
      $group: {
        _id: `$shifts.${month}.${day}`,
        count: { $sum: 1 },
        result: { $push: { name: "$name", shift: `$shifts.${month}.${day}` } },
      },
    });
  }
      
    
      Schedule.aggregate(query, function (err, user) {
        if (err) {
          res.send(err);
        }
        res.json(user);
      });
    };

This is what the returned json looks like for one user, without specifying the month or day.

(
    {
        "_id": "5f00b12a1607ad69f866cc49",
        "name": "John Doe",
        "shifts": {
            "July 2020": {
                "Wed Jul 01 2020 00:00:00 GMT+0300": {
                    "start": "09:00 AM",
                    "end": "06:00 PM"
                },
                "Thu Jul 02 2020 00:00:00 GMT+0300": {
                    "start": "09:00 AM",
                    "end": "06:00 PM"
                },
                "Fri Jul 03 2020 00:00:00 GMT+0300": {
                    "start": "09:00 AM",
                    "end": "06:00 PM"
                },
                "Sat Jul 04 2020 00:00:00 GMT+0300": {
                    "start": "DO",
                    "end": "DO"
                },

So while this works, i feel that there’s too many steps and doesn’t look readable enough.

gui design – Make Optional Buttons More Clickable

I currently have a UI where I have three optional buttons. By clicking on a button, it will go to another user flow and the button is “completed”. Unclicked buttons are considered “incomplete”. In the photo, the middle button is considered completed, while the 1st and 3rd are considered incomplete, and all are optional buttons to be clicked on.

I’m trying to style my buttons so that the incomplete buttons entice the user to click on them, despite them being optional. I’ve thought about lowering the opacity of the incomplete options, but I’ve received feedback that it hasn’t been enticing for users.

I’m also trying to style the complete buttons so that they look complete, but also communicate “I don’t need to be clicked anymore”.

Any ideas how I can communciate these intents? Icon change? Changes in color or border? enter image description here

How to visualize optional fields in a horizontal searchform

The user does not have to fill in the date/adults/childs/rooms, they are optional. The user can also search with only filling in the destination (left box).

How would you visualize that?

enter image description here

Form validation when the field is optional

I am working on a form where the phone number is optional.
What is the best practice regarding a validation mechanism that checks if it’s a correct phone number (over 10 digits):

  1. No form of validation for an optional item
  2. Use validation once the field is not empty
  3. “Optional” validation – Are you sure you want to submit this? It doesn’t seem like a correct number

design – What’s the best way to output optional information to the screen of a console application, throughout the entire program?

I’m creating a console program where the user has the option of making the output more verbose when the system processes their requests.

There will always be an output, but the verbose output would be an additional set of printing to the screen.

Making the output more verbose is a setting that they can change. It corresponds with a class variable.

Right now, verbose outputs are printed by using if statements throughout the entire program (essentially “if verbose output is on, print this statement”), but I feel like they are taking up too much space, and could be formatted better.

At the end of the day, I suppose it doesn’t matter, but I am inexperienced when working on large programs. Is there a better way than using a slew of if statements related to a class variable?

dnd 5e – Does the optional Overrun rule override the creature size requirements on moving through a hostile creature’s space?

The standard rule on moving through other creatures’ spaces state that in order to move through a hostile creature’s space, a creature must be two sizes larger or smaller than the one whose space they want to pass through.

The optional overrun rules in the DMG (p. 272, in chapter 9) now require a roll, but does it remove the size differential as well and completely replace the rules around moving through other creatures’ spaces?

dnd 5e – Does the optional Overrun rule override the creature size requirements?

The standard moving through creatures spaces rules state that in order to do this, a creature must be two sizes larger than the one they want to pass through.

The optional overrun rules in the DMG (chapter 9) now require a roll, but does it remove the size differential as well and completely replace the rules around moving through other creatures?

forms – What is a better way to indicate an optional message reminder when food order is ready

I’m designing a mobile website for a food ordering service. There is a feature at the last step of the ordering flow where the user can choose to be messaged once their order is ready. This is optional and the user can ignore it if they want.

How can i improve the following design to let the user know that entering their number is optional. However if they don’t enter their number they will need to check the collection counter display to know when their number shows up.

enter image description here

forms – How is a better way to indicate an optional message reminder when food order is ready

I’m designing a mobile website for a food ordering service. There is a feature at the last step of the ordering flow where the user can choose to be messaged once their order is ready. This is optional and the user can ignore it if they want.

How can i improve the following design to let the user know that entering their number is optional. However if they don’t enter their number they will need to check the collection counter display to know when their number shows up.

enter image description here

probability theory – Optional sampling theorem for bounded stopping times in continuous time

Establish the optional sampling theorem for a right-continuous submartingale ${X_{t},mathcal{F}_{t}, t in (0,infty)}$ under either of the following conditions:

$a)$ $T$ is a bounded optional time
$b)$ there exists and integrable random variable $Y$ such that $X_{t} leq E(Y|mathcal{F}_{t})$ a.s $P$ for all $t geq0$

I assumed the filtration is right continuous, so $T$ and $S$ are in fact, stopping times. For $a)$, let ${S_{n}}$ and ${T_{n}}$ be stopping times taking values in a countable set which approximate $S$ and $T$ from above such that $S_{n} leq T_{n}$. From the discrete optional sampling theorem for bounded stopping times, we have,
$$
E(X_{T_{n}}|mathcal{F}_{S_{n}}) geq X_{S_{n}}
$$

Now, $A in mathcal{F}_{S} implies A in mathcal{F}_{S_{n}}$ for all $n geq 1$ as $mathcal{F}_{S}=bigcap_{n=1}^{infty}mathcal{F}_{S_{n}}$. Hence,
$$
int_{A}X_{T_{n}} geq int_{A}X_{S_{n}} hspace{0.5cm} forall hspace{0.1
cm} ngeq1
$$

Now I want to take pass the limit inside but for that I need uniform integrability. Since both $S$ and $T$ are bounded, I can assume both $S_{n}$ and $T_{n}$ are uniformly bounded by a constant, say $M$. So,
$$
E(X_{M}|mathcal{F}_{S_{n}})geq X_{S_{n}}.$$
But this does not guarantee uniform integrability for submartingales (it does for martingales). I don’t know how to proceed from here.

For $b)$, I run into a similar situation as above. I can’t prove the uniform integrability of ${X_{S_{n}}}$ where
$$
E(Y|mathcal{F}_{S_{n}}) geq X_{S_{n}}
$$

Any help would be appreciated.