Best practice to schedule events in MongoDB / Node app

I’m writing a test app and realised I have no idea how to schedule events. I wanted to send a reminder email to a user 1 week after an entry is made to MongoDB but I have no idea how to go about this.
Usually I would create a cron job for handling timing events but this doesn’t seem to be a realistic way of handling this task – if it was a real production app there could be thousands of them. Is there a best practice for this sort of feature?

I suppose I could just set a reminder date in the database when the entry is originally made and then have 1 cron job that calls an API endpoint once a day which checks for reminders, mails them all and updates the database that a reminder was sent. But is there a way to avoid Cron completely? Maybe some feature of Mongo?

Thanks!

Mathematical operations for each tag in Vue 3?

There are 3 separate tags in my modal. I want to do different mathematical operations in each tag. There are 3 inputs in each tag. 2 of them to enter numbers and the other to give the result. For example, I have x + y = z problem in the first tag and I have to find the z value. In the second tag, let the formula x+y=z be the problem again, I have to enter the x and z values and find the y value.In the third tag I have to enter the y and z values in it and find the x value.My question is, I cannot write the values I need to find in 3 separate tags in a single computed?

Output:

enter image description here

Template:

           <form>
                <div class="row">
                  <div class="mb-3 col-sm-4 col-xs-12">
                    <h6 class="text-dark" for="purchasePrice">x</h6>
                    <input
                      type="text"
                      class="form-control"
                      autocomplete="off"
                      v-model="x"
                    />
                  </div>
                  <div class="mb-3 col-sm-4 col-xs-12">
                    <h6 class="text-dark" for="salePrice">y</h6>
                    <input
                      type="text"
                      class="form-control"
                      autocomplete="off"
                      v-model="y"
                    />
                  </div>
                  <div class="mb-3 col-sm-4 col-xs-12">
                    <h6 class="text-dark" for="marginResult">z</h6>
                    <input
                      type="text"
                      class="form-control"
                      autocomplete="off"
                      disabled
                      v-model="z"
                    />
                  </div>
                </div>
              </form>

Script

  data() {
    return {
      x: 0,
      y: 0,
      z: 0,
    };
  },
  computed:{
  },

How to render three dots in custom pagination in React

I have looked everywhere, watched videos and still couldn’t get the logic behind adding ellipsis in pagination.

I have created this component Pagination (please note this is just a sample component to demonstrate my question)

export const Pagination (props) {
const {maxPages, pageNumber} = props

const totalPageNumbers = []

for(let i = 1; i<= maxPages; i++){
totalPageNumbers.push(i)
} 

return (
<div>
<button disabled={pageNumber === 1}>prev</button>

{
totalPageNumbers.map(item, i) => (
<button onClick={() => someFunction()}> {item} </button>)
}
<button disabled={pageNumber === maxPages}>prev</button>
</div>

)}
  • totalPageNumbers is an array of the total pages
  • maxPages is a string of the total number
  • pageNumber is the current page

I would like to show something like this if total pages are 5 or more
1, 2, 3, 4, …, 5

if less than 5, it should be
1, 2, 3, 4

Right now everything works fine, but all pages are listed due to the map method above, so if I have 100, it will list 100. I would like to limit that number so it’s cleaner.
ellipsis no need to be clickable as long as they look like the example above, I will be super happy. Thanks a lot in advance!

Please help me with this logic, I have been stuck at this for the last 5 hours 🙁

StencilJS @Prop() variable is undefined

I created a stencil component () that uses another stencil component () in the rendered template.

One of the props (key: string) passed from smg-compound-filter to smg-filter is undefined, whereas the other props are well defined. I made sure that {filter.key} is defined in the template of smg-compound-filter, and i even tried to pass a literal string to smg-filter, but it’s undefined in this component. I think i am missing something. If someone could give me an insight, it will be bery helpful.

smg-compound-filter.ts (render function)

  render() {
    return (
        <div class="smg-filter-container">

            <div class={`filters`}>
                    this.filters.map(filter => {
                        return (
                            <div class='filter'>
                                <smg-filter
                                    key={filter.key} // even "str" doesn't work
                                    label={filter.label}
                                    target={filter.target}
                                    options={filter.options}
                                    customClasses='secondary'
                                    onFilterChanged={(event) => {this.toggleOption(event)}}
                                >
                                </smg-filter>
                            </div>
                        );
                    })
            </div>
        </div>
    );
  }

smg-filter.ts

export class SmgFilter {
  @State() filter: Filter;

  @State() showOptions: boolean;

  /** custom classes to adapt style */
  @Prop() customClasses: string;

  /** smartsheet column linked to the filter */
  @Prop() key: string;

  /** label of the filter */
  @Prop() label: string;

  /** options */
  @Prop() options: FilterOption[];

  /** type of products to be filtered: 'master' or 'product' */
  @Prop() target: FilterTarget;

  @Event() filterChanged: EventEmitter<Filter>;

  componentWillLoad() {
    console.log(this.key); // undefined

    this.showOptions = !isSecondary ? true : false;
    this.filter = {
        key: this.key,
        target: this.target,
        label: this.label,
        options: this.options,
    };
  }

adding data table as an item in select box – vue

In my application, I have a select box. This select box consists of data table in select box’s container. Now, i am not able to understand how to show the table while expanding the select box. Previously, for array of items it was taking. Now, i have tried using slot to add the data table.

But, it is not working properly. How to add the data table into Select box?

Here is my code:

    <template>
  <div class="main_container" :class="dropClass">
    <div
      class="dropdown__title"
      :class="dropTitleClass"
      @click="toggleItem"
      tabindex="0"
      @keydown="dropKeydown"
    >
      <slot name="selected" :item="selItem" :getText="getText">
        <div class="dropdown__selected" :title="getText(selItem)">
          <slot name="item-text" :item="selItem" :getText="getText"
            ><span>{{ getText(selItem) }}</span></slot
          >
        </div>
      </slot>
      <icon-wrapper class="dropdown__title-icon">
        <my-icon
          class="dropdown__icon"
          icon="expand_menu"
          size="10px"
          :style="caretStyle"
        />
      </icon-wrapper>
    </div>
    <div
      class="dropdown__items"
      :class="itemsClass"
      :style="itemsWidth"
      ref="floating"
      v-click-outside.anchor="close"
    >
      <!--<div class="dropdown__item" v-for="(item, idx) in items" @click.stop="clickParentItem(item)" :key="idx"
                 :class="[!isItemSelectable(item) ? 'dropdown__item-unselectable' : '', dropdownItemSize]" >
                <div class="dropdown__label" :class="{'dropdown__selected': isSelectedItem(item) }">
                    <span class="line-break">
                      <slot name="item-text" :item="item" :getText="getText">{{getText(item)}}</slot>
                    </span>
                </div>
            </div> 
            --> 
        // Here i am not able to understand that how to intorduce Data table inside select box
      <template slot="item" slot-scope="item">
        <my-table
          :items="item.items"
          :headers="item.headers"
          v-model="selected"
          multi-select
          @change="changeRowPerPage"
        >
        </my-table>
      </template>
    </div>
  </div>
</template>

Any suggestion on this kind of custom select component?

Typescript: Defining an interface for an array of objects from a google JSON?

I’m looping over my data that’s returned from a Google API to receive the city and state, but I keep receiving this error

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Geocode'.
  No index signature with a parameter of type 'string' was found on type 'Geocode'.

Which appears when I try to loop the data:

data[key].address_components.forEach

So far I looked at “Indexing objects” and using a interface, but I’m still not sure how to use them

Here is my code so far:

type Geocode = {
  data?: google.maps.GeocoderResult | null;
  error: string | null;
};

export interface CityState {
  city?: string;
  state?: string;
}

export const parseForCityAndState = (data: Geocode): CityState => {
  const cityState = {
    city: '',
    state: '',
  };

  if (data) {
    for (const key in data) {
      data[key].address_components.forEach((ele: {types: string | string[]; short_name: string}) => {
        if (ele.types.includes('sublocality') || ele.types.includes('locality')) {
          cityState.city = ele.short_name;
        }

        if (ele.types.includes('administrative_area_level_1')) {
          cityState.state = ele.short_name;
        }
      });
    }
  }

  return cityState;
};

Here is how the google JSON returns the data:

{
    "data": {
        "address_components": [
            {
                "long_name": "254",
                "short_name": "254",
                "types": [
                    "street_number"
                ]
            },
            {
                "long_name": "Broadway",
                "short_name": "Broadway",
                "types": [
                    "route"
                ]
            },
            {
                "long_name": "Manhattan",
                "short_name": "Manhattan",
                "types": [
                    "political",
                    "sublocality",
                    "sublocality_level_1"
                ]
            },
            {
                "long_name": "New York",
                "short_name": "New York",
                "types": [
                    "locality",
                    "political"
                ]
            },
            {
                "long_name": "New York County",
                "short_name": "New York County",
                "types": [
                    "administrative_area_level_2",
                    "political"
                ]
            },
            {
                "long_name": "New York",
                "short_name": "NY",
                "types": [
                    "administrative_area_level_1",
                    "political"
                ]
            },
            {
                "long_name": "United States",
                "short_name": "US",
                "types": [
                    "country",
                    "political"
                ]
            },
            {
                "long_name": "10007",
                "short_name": "10007",
                "types": [
                    "postal_code"
                ]
            }
        ],
        "formatted_address": "254 Broadway, New York, NY 10007, USA",
        "geometry": {
            "location": {
                "lat": 40.7129032,
                "lng": -74.0063033
            },
            "location_type": "ROOFTOP",
            "viewport": {
                "south": 40.7115542197085,
                "west": -74.0076522802915,
                "north": 40.7142521802915,
                "east": -74.00495431970849
            }
        },
        "place_id": "ChIJzwO0CyJawokRoSRPRCTv9II",
        "plus_code": {
            "compound_code": "PX7V+5F New York, NY, USA",
            "global_code": "87G7PX7V+5F"
        },
        "types": [
            "street_address"
        ]
    },
    "error": null
} 

How to filter between 2 array of object

I have 2 array of objects:

 let mapper = [
 {
  "request": "ABC",
  "status": "In Process"
 },
 {
  "request": "DEF",
  "status": "NA"
 }
]

and

let TrackDetails =  [
{
    "trackNumber": "1",
    "request": "ABC"
},
{
    "trackNumber": "2",
    "request": "ABC"
},
{
    "trackNumber": "3",
    "request": "DEF"
},
{
    "trackNumber": "4",
    "request": "DEF"
},
{
    "trackNumber": "4",
    "request": "ABC"
},
{
    "trackNumber": "6",
    "request": "DEF"
},
{
    "trackNumber": "6",
    "request": "ABC"
},
{
    "trackNumber": "8",
    "request": "ABC"
}
]

I want to filter out all the TrackDetails objects whose status for the request is “NA”. The mapper object should be used to compare 2 arrays of objects.

Required output:

let result = [
{
    "policyNumber": "1",
    "request": "ABC"
},
{
    "policyNumber": "2",
    "request": "ABC"
},
{
    "policyNumber": "4",
    "request": "ABC"
},
{
    "policyNumber": "6",
    "request": "ABC"
},
{
    "policyNumber": "8",
    "request": "ABC"
}
]

React Web alternative to Android RecyclerView and Flutter ListView

I’m working on a React web project and I wanted to create a list similar to Android’s RecyclerView and Flutter’s ListView. I know I can do this with a bunch of HTML li tags. However, I’d love to know if there are any libraries dedicated to this functionality. I looked at the recyclerlistview library but it seems to be built for react-native. I need a library built for React Web. Thank you.

find if html class exist

I have a class:

<style>
.jonny {
 color:"red"
}
</style>

in my element:

 <div class=jonny>abc</div> 

I want to check via JavaScript if class jonny have a content. sometime I want even to check where in my source it define. In which .css file it define.

Thank you
j.r

Is there any possibility to avoid multiple ../ when we are importing a function?

I want to avoid this thing at importing a function

const ApiError = require('../../../../classes/ErrorClass');

Is any possibility to use,I don’t know Ex:

require('mypath/ErrorClass')

If I have 11 imports I don’t want to have something like this

const ApiError = require('../../../../classes/ErrorClass');
const ApiError = require('../../../classes/ApiClass');
const ApiError = require('../../../../utils/utils');
const ApiError = require('../../../etc/etc');
const ApiError = require('../../../../../etc/etc');
const ApiError = require('../../../../etc/etc');
const ApiError = require('../../../../etc/etc');
const ApiError = require('../../../../etc/etc');

Thank you!

My Users datas are coming in html but html page does not show users data

İ trying to do when some one open users page Person will see the users details but this html page is not working like this.Users details are coming in database to html page like firstname,id or email but when i tring to see these datas i cannot see

i getting like this picture

but i wanna see like this

this are my html codes

<div *ngIf="dataLoaded==false" class="spinner-border text-primary" role="status">
  <span class="visually-hidden">Loading...</span>
</div>

 


<table *ngIf="dataLoaded==true" class="table">
  <thead>
    <tr>
      <th scope="col">Email</th>
      <th scope="col">Id</th>
      <th scope="col">Adı</th>
      <th scope="col">Soyadı</th>
       
       
     
    </tr>
  </thead>
  <tbody>
 
    <tr *ngFor="let user of users ;">
      
      <td>{{ user.Email }}</td>
      <td>{{ user.Id }}</td> 
      <td>{{ user.FirstName }}</td>
      <td>{{ user.LastName }}</td>
      
     
    </tr>
  </tbody>
   
  


</table>

this are my typescript codes

import { Component, OnInit } from "@angular/core";
 import { Users } from "src/app/models/Users";
import { AuthService } from "src/app/services/auth.service";
import { ActivatedRoute } from '@angular/router';
import { ToastrService } from 'ngx-toastr';
 
 

 

@Component({
  selector: 'app-users',
  templateUrl: './users.component.html',
  styleUrls: ['./users.component.css'],
})
export class UsersComponent implements OnInit {
  user: Users   ;
  users : Users[] = []
  dataLoaded = false;
 

  constructor(private authservice: AuthService,
    private activatedRoute :ActivatedRoute, private toastrService:ToastrService
   ) {}

    
  ngOnInit(): void {
    this.activatedRoute.params.subscribe(params=>{
      if(params["Id"]){
        this.GetUserById(params["Id"])
      }else{
        this.getusers()
      }
    })
}



  getusers() {
    this.authservice.getusers().subscribe(response=>{
      this.users = response.data
      console.log(this.users)
      this.dataLoaded = true;
    })   
  }

  GetUserById(Id:number) {
    this.authservice.GetUserById(Id).subscribe(response=>{
      this.user= response.data
      this.dataLoaded = true;
      console.log(this.users)
 
    })   
  }
  

}

this is my console log

[webpack-dev-server] Live Reloading enabled. index.js:551
Array [ {…}, {…} ]
​
0: Object { id: 3002, firstName: "striasd", lastName: "stringwww", … }
​​
email: "[email protected]"
​​
firstName: "striasd"
​​
id: 3002



lastName: "stringwww"


 ​​
status: true
​​
<prototype>: Object { … }
​

1: Object { id: 4002, firstName: "stringq", lastName: "stringq", … }
​
length: 2
​
<prototype>: Array []

So what should i do or what is my fault