throw new ERR_INVALID_ARG_TYPE(propName, [‘string’, ‘Buffer’, ‘URL’], path); ^ TypeError [ERR_INVALID_ARG_TYPE]: The “path” argument must be str

Getting the error when uploading image from postman. I am creating backend for my ecommerce app and in Products database there is the error on uploading picture from postman.

const formidable = require('formidable');
const _ = require('lodash');
const fs = require('fs');
const Product = require('../models/product');

const {
    errorHandler
} = require('../helpers/dbErrorHandler');

exports.createProduct = (req, res) => {
    let form = new formidable.IncomingForm();
    form.keepExtensions = true;
    form.parse(req, (err, fields, files) => {
        if (err) {
            return res.status(400).json({
                error: 'Image failed to upload'
            });
        }
        let product = new Product(fields);
        if (files.photo) {
            product.photo.data = fs.readFileSync(files.photo.path);
            product.photo.contentType = files.photo.type;
        }
        product.save((err, result) => {
            if (err) {
                return res.status(400).json({
                    error: errorHandler(err)
                });
            }
            res.json(result);
        });
    });
};

Set icon to outline or fill if 2 ID’s from 2 arrays are the same

I have two separate arrays of data, the first array is the complete list of data from database, the second array is the data from the users favorites. I am outputting the first array in a Flatlist on screen and if the user favorites an item from that list, it saves the data from that item to the favorites array and displays on a different screen. I have an icon that I need to have filled or outline based on if that item is favorited or not (filled if favorited, outline if not). I am not sure the best way to go about this. I am currently trying to compare if each array contains the same ID’s. Also, I have tried using setState for the icon but if the ID’s match it sets every heart in the flatlist to fill. This is what I have currently.

list = [
{"id": 0, "firstName": "John", "lastName": "Smith"},
{"id": 1, "firstName": "Frank", "lastName": "White"},
]


favoritesList = [
{"favoritesId": 0, "firstName": "John", "lastName": "Smith"},
{"favoritesId": 1, "firstName": "Frank", "lastName": "White"},
]
  //Checking if favorite is checked
  let heartOutline = 'heart-outline';
  const favOutline = (favId)=> {
    favoritesId.forEach(el => {
      if (favId === el.favoritesId) {
        heartOutline = 'heart';
      } else {
        heartOutline = 'heart-outline';
      }
    });
  };
<FlatList
 data={list}
 keyExtractor={item => item.id}
 renderItem={({item}) => (
  <View>
   <Ionicons
   onPress={() => favOutline(item.id)}
   style={{alignItems: 'center', color: 'white'}}
   name={heartOutline}
   size={18}
   />
  </View>
 />

Exporting data from a Module

I’m pretty new to coding, so be patient with me please! ๐Ÿ™‚

I’m working with Firebase and am having trouble exporting vars from my module javascript. I know that modules are not part of the global vars so how would I go about exporting those vars? (or making them global?)

If the code could be simple so I can understand it that would be great! ๐Ÿ™‚

(This is just normal browser-based javascript by the way.)

Mutate Value Of Subscribe Object Without Convert It To Observable

I want to use these two solutions together with RxJS but I don’t know how to do it.

pipe each data that Observable emits and have ability to act like a Subject:

// Sample code, this does not work properly :(, because next is not defined on Observable
const dummy = new Subject<number>().pipe(
  map((num) => num + 1)
);

dummy.subscribe((number) => {
  // expects 4 but get 3
})

dummy.next(3)

I want to emit data everywhere even outside of observable construction like Subscribe, and operate on each data emit using pipe method like Observable.

I can implement an simple emitter class that simulate this behavior but I want an RxJS way.

GAS simple form to enter data into sheet, error illegal value property 1

As you can see this is a simple bootstrap form, to enter data into a sheet, I’ve done different forms and they all work fine, but this one is just made of dropdowns and for some reason, whenever I try to send it, it says illegal value property 1 in chrome’s console, I don’t understand it its just numbers, I’ve been looking for the error for a 2 hours now and I cant seem to find whats wrong

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>Bootstrap demo</title>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
  



    <script>                                        
    function AddRow()
    {
      var input1 = document.getElementById("input1").value;
      var input1 = document.getElementById("input2").value;
      var input1 = document.getElementById("input3").value;
      var input1 = document.getElementById("input4").value;
      var input1 = document.getElementById("input5").value;
      var input1 = document.getElementById("input6").value;
      var input1 = document.getElementById("input7").value;
      var input1 = document.getElementById("input8").value;
      var input1 = document.getElementById("input9").value;
      var input1 = document.getElementById("input10").value;
      var input1 = document.getElementById("input11").value;
      var input1 = document.getElementById("input12").value;
      var input1 = document.getElementById("input13").value;
      var input1 = document.getElementById("input14").value;
      var input1 = document.getElementById("input15").value;
      var input1 = document.getElementById("input16").value;
      
      if(input1 != '' && input2 != '' && input3 != '' && input4 != '' && input5 != '' && input6 != '' && input7 != '' && input8 != '' && input9 != '' && input10 != '' && input11 != '' && input12 != '' && input13 != '' && input14 != '' && input15 != '' && input16 != '')
      {
      google.script.run.AddRecord(input1, input2, input3, input4, input5, input6, input7, input8, input9, input10, input11, input12, input13, input14, input15, input16);
      document.getElementById("input1").value = '';
      document.getElementById("input2").value = '';
      document.getElementById("input3").value = '';
      document.getElementById("input4").value = '';
      document.getElementById("input5").value = '';
      document.getElementById("input6").value = '';
      document.getElementById("input7").value = '';
      document.getElementById("input8").value = '';
      document.getElementById("input9").value = '';
      document.getElementById("input10").value = '';
      document.getElementById("input11").value = '';
      document.getElementById("input12").value = '';
      document.getElementById("input13").value = '';
      document.getElementById("input14").value = '';
      document.getElementById("input15").value = '';
      document.getElementById("input16").value = '';

      document.getElementById("display_error").innerHTML = "";
      document.getElementById("display_sent").innerHTML = "Sent";
      }
      else
      {
      document.getElementById("display_error").innerHTML = "Enter All Information";
      }
    }
    </script>
  
  
  
  
  
  
  
  
  
  
  </head>
  <body class="bg-dark text-white">





    <div class="container d-flex justify-content-evenly p-4">
      <div class="card bg-dark p-2">
        <form>
          <div class="row">
            <div class="col p-2">
              <label for="input1" class="form-label">Lower body (compound)</label>
              <select class="form-select bg-dark text-white" id="input1">
              <option selected></option>
               <option value="0">0</option>
               <option value="1">1</option>
               <option value="2">2</option>
               <option value="3">3</option>
               <option value="4">4</option>
               <option value="5">5</option>
              </select>
            </div>
          </div>

          <div class="row">
            <div class="col p-2">
              <label for="input2" class="form-label">Lower back</label>
              <select class="form-select bg-dark text-white" id="input2">
               <option selected></option>
               <option value="0">0</option>
               <option value="1">1</option>
               <option value="2">2</option>
               <option value="3">3</option>
               <option value="4">4</option>
               <option value="5">5</option>
              </select>
            </div>
          </div>

          <div class="row">
            <div class="col p-2">
              <label for="input3" class="form-label">Glutes</label>
              <select class="form-select bg-dark text-white" id="input3">
               <option selected></option>
               <option value="0">0</option>
               <option value="1">1</option>
               <option value="2">2</option>
               <option value="3">3</option>
               <option value="4">4</option>
               <option value="5">5</option>
              </select>
            </div>
          </div>

          <div class="row">
            <div class="col p-2">
              <label for="input4" class="form-label">Quads</label>
              <select class="form-select bg-dark text-white" id="input4">
               <option selected></option>
               <option value="0">0</option>
               <option value="1">1</option>
               <option value="2">2</option>
               <option value="3">3</option>
               <option value="4">4</option>
               <option value="5">5</option>
              </select>
            </div>
          </div>

          <div class="row">
            <div class="col p-2">
              <label for="input5" class="form-label">Hams</label>
              <select class="form-select bg-dark text-white" id="input5">
               <option selected></option>
               <option value="0">0</option>
               <option value="1">1</option>
               <option value="2">2</option>
               <option value="3">3</option>
               <option value="4">4</option>
               <option value="5">5</option>
              </select>
            </div>
          </div>

          <div class="row">
            <div class="col p-2">
              <label for="input6" class="form-label">Push (compound)</label>
              <select class="form-select bg-dark text-white" id="input6">
               <option selected></option>
               <option value="0">0</option>
               <option value="1">1</option>
               <option value="2">2</option>
               <option value="3">3</option>
               <option value="4">4</option>
               <option value="5">5</option>
              </select>
            </div>
          </div>

          <div class="row">
            <div class="col p-2">
              <label for="input7" class="form-label">Pecs</label>
              <select class="form-select bg-dark text-white" id="input7">
               <option selected></option>
               <option value="0">0</option>
               <option value="1">1</option>
               <option value="2">2</option>
               <option value="3">3</option>
               <option value="4">4</option>
               <option value="5">5</option>
              </select>
            </div>
          </div>

          <div class="row">
            <div class="col p-2">
              <label for="input8" class="form-label  text-white bg-dark">Triceps</label>
              <select class="form-select bg-dark text-white" id="input8">
               <option selected></option>
               <option value="0">0</option>
               <option value="1">1</option>
               <option value="2">2</option>
               <option value="3">3</option>
               <option value="4">4</option>
               <option value="5">5</option>
              </select>
            </div>
          </div>

          <div class="row">
            <div class="col p-2">
              <label for="input9" class="form-label">Front Delts</label>
              <select class="form-select bg-dark text-white" id="input9">
               <option selected></option>
               <option value="0">0</option>
               <option value="1">1</option>
               <option value="2">2</option>
               <option value="3">3</option>
               <option value="4">4</option>
               <option value="5">5</option>
              </select>
            </div>
          </div>

          <div class="row">
            <div class="col p-2">
              <label for="input10" class="form-label">Row (compound)</label>
              <select class="form-select bg-dark text-white" id="input10">
               <option selected></option>
               <option value="0">0</option>
               <option value="1">1</option>
               <option value="2">2</option>
               <option value="3">3</option>
               <option value="4">4</option>
               <option value="5">5</option>
              </select>
            </div>
          </div>

          <div class="row">
            <div class="col p-2">
              <label for="input11" class="form-label">Erector spinae (upper back)*</label>
              <select class="form-select bg-dark text-white" id="input11">
               <option selected></option>
               <option value="0">0</option>
               <option value="1">1</option>
               <option value="2">2</option>
               <option value="3">3</option>
               <option value="4">4</option>
               <option value="5">5</option>
              </select>
            </div>
          </div>

          <div class="row">
            <div class="col p-2">
              <label for="input12" class="form-label">Lats</label>
              <select class="form-select bg-dark text-white" id="input12">
               <option selected></option>
               <option value="0">0</option>
               <option value="1">1</option>
               <option value="2">2</option>
               <option value="3">3</option>
               <option value="4">4</option>
               <option value="5">5</option>
              </select>
            </div>
          </div>

          <div class="row">
            <div class="col p-2">
              <label for="input13" class="form-label">Upper back (rhomboids, traps)</label>
              <select class="form-select bg-dark text-white" id="input13">
               <option selected></option>
               <option value="0">0</option>
               <option value="1">1</option>
               <option value="2">2</option>
               <option value="3">3</option>
               <option value="4">4</option>
               <option value="5">5</option>
              </select>
            </div>
          </div>

          <div class="row">
            <div class="col p-2">
              <label for="input14" class="form-label">Rotator Cuff</label>
              <select class="form-select bg-dark text-white" id="input14">
               <option selected></option>
               <option value="0">0</option>
               <option value="1">1</option>
               <option value="2">2</option>
               <option value="3">3</option>
               <option value="4">4</option>
               <option value="5">5</option>
              </select>
            </div>
          </div>

          <div class="row">
            <div class="col p-2">
              <label for="input15" class="form-label">Biceps</label>
              <select class="form-select bg-dark text-white" id="input15">
               <option selected></option>
               <option value="0">0</option>
               <option value="1">1</option>
               <option value="2">2</option>
               <option value="3">3</option>
               <option value="4">4</option>
               <option value="5">5</option>
              </select>
            </div>
          </div>

          <div class="row">
            <div class="col p-2">
              <label for="input16" class="form-label">Rear Delts</label>
              <select class="form-select bg-dark text-white" id="input16">
               <option selected></option>
               <option value="0">0</option>
               <option value="1">1</option>
               <option value="2">2</option>
               <option value="3">3</option>
               <option value="4">4</option>
               <option value="5">5</option>
              </select>
            </div>
          </div>

          <div class="row">
            <div class="col p-2">
              <div id="display_sent" style="color: white" ></div>
              <input type="button" value="Submit" class="btn btn-light" onclick="AddRow()" />
              <div id="display_error" style="color: red" ></div>
            </div>
          </div>
          



    

          
      </form>
    </div>
  </div>











    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
  </body>
</html>

Repeated Numbers javascript [closed]

Create a function called checkRepeat(lst) that takes a list of numbers and returns a new list that contains the numbers that appear more than once in the input list.

Ex:

lst = [1, 2, 3, 1, 2, 3, 4, 5] => Should return [1, 2, 3]
lst = [1, 1, 1, 1, 1, 1] => Should return [1]
lst = [1 , 2, 3, 4] => Should return [ ]
lst = [ ] => Should return [ ]

How to hard code a file object to a model attribute javascript

I have a file object like so in the browser memory:
enter image description here

The file is only added to the attribute on button click however I would like to hardcode the addition of that file object on the initialization of the view, so something like this:

initialize(options){
  this.model.add({
        "file": {},
        "name": "Saved file",
    })
}

However im not quite sure how to hardcode a File object for a specific file if that makes sense. How could I go about doing this? I realize I would probably need to make use of the javascript File object, but not quite sure how to hardcode for a specific file from my computer. Sorry if the question is weirdly worded kinda new to js.

How to add another property in css?

Suppose if we give some properties to all h1 tags using external css and we have to give one more property (not present in css) to only one of the h1 tag with same remaining properties in css.So do I have to write seperate code by giving that tag a id or there is any shorter way?

Creating tasks every N days Sequelize

In my application, the administrator has to create tasks for users every N days, and users have to complete them and upload photos of completed tasks. Days of created tasks must not fall on weekends. I created the sequelize model

const Task = sequelize.define('Task', {
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true
    },
    title: {
        type: DataTypes.STRING,
        allowNull: false
    },
    description: {
        type: DataTypes.STRING
    },
    users: {
        type: DataTypes.ARRAY(DataTypes.INTEGER),
        allowNull: false
    },
    status: {
        type: DataTypes.STRING,
        defaultValue: 'new',
        allowNull: false
    },
    deadline: {
        type: DataTypes.DATE
    }
})

and for Completed Tasks:

const Completed = sequelize.define(
    'Completed',
    {
        id: {
            type: DataTypes.INTEGER,
            primaryKey: true,
            autoIncrement: true
        },
        creator: {
            type: DataTypes.INTEGER,
            allowNull: false
        },
        photos: {
            type: DataTypes.ARRAY(DataTypes.STRING)
        }
    }
)

My problem is how can I implement scheduling tasks for users and create task function?

i’m using Node.js, Postgres, Sequelize & Express

Reset Input Value After Unchecking Box Javascript?

Here is my JS code

let items = 0;

document.addEventListener("click", ({ target }) => {
  if (target.className === "food" && target.checked) {
    items -= -target.value;
    console.log("I clicked the item", items);
  } else if (target.className === "food" && !target.checked) {
    items += +target.value;
    console.log("i unclicked", items);
  })}

HTML Input

 <input type="checkbox" name="item1" value="1000" class="food">
 <input type="checkbox" name="item2" value="2000" class="food">

Right now when I click a checkbox it will add 1000, then when I uncheck it to turns to 2000, then checking again it becomes 3000, and basically just keeps adding them regardless if I check or uncheck

How do I reset the value when I uncheck my input?

There is a problem with the delete function of the react component implemented through the map method

I am developing using react.
It is in the process of fetching the information contained in the db and displaying it on the web page through the map method.
If you delete one piece of information using onclick or the onClose method provided by antd, the function is also deleted from the db.
in the db, the function worked successfully. but the information at the bottom is deleted, not the deleted information in the web page.
If I refresh website, it is displayed normally, but I don’t want to use the window reload function.
I wonder why this is happening and what is the solution.
thank you!

AlertPage

import React, { useState } from "react";
import useSWR from "swr";
import axios from "axios";
import AlertComponent from "./Sections/AlertComponent";

const fetcher = async (url) =>
  await axios.get(url).then((response) => JSON.parse(response.data.alerts));

function AlertPage() {
  const { data = [], error } = useSWR("/api/streaming/getAlerts", fetcher, {
    refreshInterval: 1000,
  });

  const onClose = (data) => {
    axios.post(`/api/streaming/removeAlerts/${data._id.$oid}`).then(() => {
      console.log(`${data._id.$oid} deleted`);
    });
  };

  const renderAlerts = data.map((alert, index) => {
    return (
      <div key={index}>
        <AlertComponent alert={alert} index={index} onClose={onClose} />
      </div>
    );
  });

  if (error) return <div>failed to load</div>;
  if (data === []) return <div>loading...</div>;

  return <div>{renderAlerts}</div>;
}

export default AlertPage;

AlertComponent

import React, { useState } from "react";
import { Alert } from "antd";
import Marquee from "react-fast-marquee";

function AlertComponent(props) {
  const [alert, setalert] = useState(props.alert);
  const [index, setindex] = useState(props.index);

  return (
    <div
      className="alert"
      key={index}
      style={{ display: "flex" }}
      onClick={() => {
        props.onClose(alert);
      }}
    >
      <Alert
        message={`${alert.data.timestamp.$date.substr(0, 19)}`}
        description={
          <Marquee pauseOnHover speed={40} gradient={false}>
            {`<${alert.data.location}> <${alert.data.name}> <${alert.data.contents}> detected`}
          </Marquee>
        }
        banner
      />
    </div>
  );
}

export default AlertComponent;

Why in javascript, new Date EPOCH is not in UTC EPOCH?

I have trouble with time precision on my backend.
here is code sample:

const inputDateString = `2022-05-30 13:45:15` // assume it as UTC without specifying the timezone

// we use loadbalancing and auto-scale so our backend engine might be everywhere,
// so we dont take local time into account, we always treat date as UTC
let systemGetDate = new Date(inputDateString)

console.log(systemGetDate.valueOf()) // => 1653893115000, it should be 1653918315000
// 1653893115000 is GMT: Monday, 30 May 2022 06:45:15, but 2022-05-30 13:45:15 in my local time!
const inputDateStringWithTimezone = `2022-05-30 13:45:15+00`
systemGetDate = new Date(inputDateStringWithTimezone)
console.log(systemGetDate.valueOf()) // => 1653918315000, its right now. but only when timezone explicitly specified

Can we make new Date(string) always treat the input as UTC, without converting it as localtime? I’m fine the Date object is in localtime, but atleast the getTime or valueOf in UTC somehow.

Currently my workaround is by using moment.js library, it can resulting the output what I want.

but I know it will be bad to depends too much on other library, it may break or deprecated later.
(https://momentjs.com/docs/#/-project-status, the official itself explain it will be discontinued)

any better workaround to fix this issue? or I should scratch all this, and explicitly specify the timezone all around the system?

Google Sheets : add a row per day or week automatically for multiple years (w/ using script or function ?)

I’m looking for those who are very well comfortable with Google Sheets and its script part.
What I would like to do is to create a script or with a function that will add automatically the day, the month and the year per row for 4 years for example in order to make a calendar of shooting, pre production and post prod per film. It would be so long to do it manually and add each day per month for 4 or more years. If it’s done by a script it would be done instantly and would be possible to update later to add more years.

Example of what I’m looking for

If it’s too complicated per day, I can add per week. Like week 1 January 21, just like in the picture. But I really prefer if that’s possible to add a row per day to be the most accurate as possible.

If my question is not very clear for you, don’t hesitate to tell me and I’ll do my best to explain you better what I try to get.

I really thank you for your future help!
Best.

Louis

Get first div after button is clicked

I have the following bit about shop info:

<h3 class="-center"><shop>Shop name</shop></h3>
<button type="button" id="banff" onclick="showShop(this.id)"><shop-title><b>Bakery Shop</b></shop-title></button>
<p class="move-right"><shop-info>Shop Address ยท Shop number</shop-info></p>
  <div id="shop"  class="hidden">
    <p><shop-info>Opening soon</shop-info></p>
  </div>

What I’m trying to do is that once the button is clicked, it will get the first div after the button and toggle the hidden class without referencing the id, there will be multiple shops so I am trying to create one function which will work for all of them rather than create an individual function for each.

I thought I could do something like:

function showShop(id) {
const elem = document.getElementById(id);
 alert(id);
const div = elem.closest('div');
div.classList.toggle('hidden'); 

}

But it’s referencing the first div on the page rather than the first one after the button, where have I gone wrong here? Or do I need to go about this a different way?

Thanks in advance for any advice