JavaScript Date UTC datetime-local

I have a form where user can introduce date and time with input format datetime-local. When the form is summited a problem appears for the start-date “Value must 11:52 AM or earlier”, my local time is 13:52″. So i have to select -2 hours. How can I remove this problem. The form is limited for the start date to select only today and last 72 hours, same for end time.
The code is the following:

 <input type="datetime-local" name="start_timestamp" id="start_timestamp" required>
 <input type="datetime-local" name="end_timestamp" id="end_timestamp" required>

<script>
    //Do not let to select END-TIME and START TIME  in the PAST
    var today = new Date();
    var past = new Date(today.setDate(today.getDate() - 3)).toISOString().slice(0, 16);
    var today = new Date().toISOString().slice(0, 16);

    document.getElementsByName("start_timestamp")[0].min = past;
    document.getElementsByName("start_timestamp")[0].max = today;
</script>

<script>
    var today = new Date();
    var future = new Date(today.setDate(today.getDate() + 3)).toISOString().slice(0, 16);
    var today = new Date().toISOString().slice(0, 16);

    document.getElementsByName("end_timestamp")[0].min = today;
    document.getElementsByName("end_timestamp")[0].max = future;
</script>

I have an image also:

enter image description here

firestore query wait for nested foreach loop

I’m trying to populate an array with names from all documents in a collection, and also populate another array with all the subcollection documents from those parent documents.

  let data = []
  let names = []
  
  const suppliers = await db.collection('suppliers').get()
  
  suppliers.forEach(async supplier => {

    names.push({name: supplier.data().name, id: supplier.id })

    const deliveries = await db.collection('suppliers').doc(supplier.id).collection('deliveries').get()
    
    deliveries.forEach(delivery => {
      
      data.push(delivery.data())
    })
  })

  console.log(names) // Populated
  console.log(data) // Empty

The problem is that it doesn’t wait for the inner loop to finish before executing the code outside. The names array gets populated but the the data array is empty. How can i make the nested loop finish before executing the outside code?

How to pass a value between two different nodejs functions called by 2 different graphql mutations?

I’m trying to pass the data between two things. I will now explain it in detail. First graphql query calls a function func1() which is like

func1(){
  const a = await func2();
  return a;
}

func2(){
  return 7;
}

func3(value){
  return value
}

this func2 is returning an integer for example 7. For now I was using console input but now I want to get this result from another graphql mutation which calls a function func3(). I pass the required value for example 7 in the graphql mutation arguments which gets passed to function func3. How can I wait for this func3’s value in func1? Please help and if you want me to elaborate any specific thing, I’d be happy to do so.

Mocha async with await

According to this https://mochajs.org/#using-async-await when using await to test async function, there is no need to call done(). But with my code below it is complaining
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
I don’t want to use the hack to increase timeout.

describe('test', function () {
  it('upload all', async () => {
    const c = await setup();
    const files = await Test(c);
    expect(files.length).to.equal(3); 
  })
})

Any help is much appreciated

Each value can’t be stored in a variable?

You can keep almost anything in variables just by assigning the new value for a named variable with an equal sign. Also, following PEP 8, one space before and after the assignment sign is considered good practice.

Does someone know some value that is not allowed?

Thanks

React Router without Hooks – ID dynamic routes

i’m totally beginner in react.
I tried to improve my skill day after day.
Today im stuck on problem, i want to create dynamic route with JSON characters (here dragon ball z)
My routes are correct but i want to show biography on only clicked characters like “i click on goku show goku bio”
I want to make it without REACT HOOKS (dont useLocation, useParams ect..).
At moment i’m totally stuck

Can you help me ? how can i do?

Thanks for help 🙂

here is the blitzstack of my project:

REACT ROUTER DBZ EXERCICE – WITHOUT HOOKS

React MUI 4 SelectInput.js:340 Uncaught TypeError: Cannot read properties of undefined (reading ‘value’)

This error happens when you provide an empty array as options.

The error log:

SelectInput.js:340 Uncaught TypeError: Cannot read properties of undefined (reading 'value')
    at SelectInput.js:340:1
    at Array.map (<anonymous>)
    at SelectInput.js:339:1
    at invokePassiveEffectCreate (react-dom.development.js:23487:1)
    at HTMLUnknownElement.callCallback (react-dom.development.js:3945:1)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:3994:1)
    at invokeGuardedCallback (react-dom.development.js:4056:1)
    at flushPassiveEffectsImpl (react-dom.development.js:23574:1)
    at unstable_runWithPriority (scheduler.development.js:468:1)
    at runWithPriority$1 (react-dom.development.js:11276:1)
    at flushPassiveEffects (react-dom.development.js:23447:1)
    at performSyncWorkOnRoot (react-dom.development.js:22269:1)
    at react-dom.development.js:11327:1
    at unstable_runWithPriority (scheduler.development.js:468:1)
    at runWithPriority$1 (react-dom.development.js:11276:1)
    at flushSyncCallbackQueueImpl (react-dom.development.js:11322:1)
    at flushSyncCallbackQueue (react-dom.development.js:11309:1)
    at flushPassiveEffectsImpl (react-dom.development.js:23620:1)
    at unstable_runWithPriority (scheduler.development.js:468:1)
    at runWithPriority$1 (react-dom.development.js:11276:1)
    at flushPassiveEffects (react-dom.development.js:23447:1)
    at react-dom.development.js:23324:1
    at workLoop (scheduler.development.js:417:1)
    at flushWork (scheduler.development.js:390:1)
    at MessagePort.performWorkUntilDeadline (scheduler.development.js:157:1)

i want to check if current user is following other user

i want to check if current user is following other use lets say check if user A is following user B.

User Model:-

const UserSchema = new Schema({
    email: {
        required: true,
        type: String,
        unique: true,
        lowercase: true,
        validate: (value) => {
            if (!validator.isEmail(value)) {
                throw new Error('Invalid email address.');
            }
        }
    },
    fullName: {
        required: true,
        type: String,
    },
    username: {
        required: true,
        type: String,
        unique: true,
        lowercase: true,
        minlength: 3,
    },
    password: {
        type: String,
        minlength: 8,
    },
    avatar: String,
    bio: {
        type: String,
        default: null,
        maxlength:300,
    },
    location: {
        type: String,
        default: 'Bangalore'
    },
    website: {
        type: String,
        default: null,
    },
    joindate: {
        type: Date,
        default: new Date()
    },
    isVerified:{
        type:Boolean,
        default:false,
    }

})

const UserModel = mongoose.model('User', UserSchema);
module.exports = UserModel;

Followings Model:-


const FollowingsSchema = new Schema({
    user: {
        ref: 'User',
        unique:true,
        type: Schema.Types.ObjectId,
    },
    followings: [{
        user: {
            type: Schema.Types.ObjectId,
            ref: 'User'
        }
    }]
})

const Followings = mongoose.model('Followings', FollowingsSchema);
module.exports = Followings;

Followers Model:-



const FollowersSchema = new Schema({
    user: {
        ref: 'User',
        unique:true,
        type: Schema.Types.ObjectId,
    },
    followers: [{
        user: {
            type: Schema.Types.ObjectId,
            ref: 'User'
        }
    }]
})

const Followers = mongoose.model('Followers', FollowersSchema);
module.exports = Followers;

currently i was able to achieve this by iterating through each follower and check if user exist in that user followers list.
i want to achieve this with mongodb aggregation ,im new to mongob

WebBluetooth API writeValueWithoutResponse does not seem to have an effect on connected device

I am trying to connect to a Buwizz V2 hub (and start a motor) via BLE on a windows machine via WebBluetooth in Google Chrome Browser.

The API for the Buwizz is https://buwizz.com/BuWizz_2.0_API_1.3_web.pdf

The result of my code is

ble.html:21 discoverDevicesOrDisconnect
ble.html:31 discoverDevices
ble.html:40 > Name: BuWizz
ble.html:41 > Id: NtY+vKj4GR1vb/VowbQdJw==
ble.html:42 > Connected: false
ble.html:44 BluetoothDevice {id: ‘NtY+vKj4GR1vb/VowbQdJw==’, name: ‘BuWizz’, gatt: BluetoothRemoteGATTServer, ongattserverdisconnected: null, watchingAdvertisements: false, …}
ble.html:74 connecting
ble.html:77 Connected to NtY+vKj4GR1vb/VowbQdJw==
ble.html:78 connected=true
ble.html:96 discoverSvcsAndChars server=[object BluetoothRemoteGATTServer]
ble.html:102 Got 1 services
ble.html:109 Getting Characteristics for service 4e050000-74fb-4481-88b3-9919b1676e93
ble.html:111 > Service: 4e050000-74fb-4481-88b3-9919b1676e93
ble.html:117 >> Characteristic: 000092d1-0000-1000-8000-00805f9b34fb
ble.html:125 FINISHED DISCOVERY
ble.html:54 Try to startMotor
ble.html:55 Will send command to Characteristic:000092d1-0000-1000-8000-00805f9b34fb
ble.html:56 Characteristic has writeWithoutResponse ability:true
ble.html:60 Motor command ->16,127,127,127,127,0

So I can discover and connect to the device, find the Service 4e050000-74fb-4481-88b3-9919b1676e93, find the characteristic 000092d1-0000-1000-8000-00805f9b34fb and check that is has writeWithoutResponse.

Since the motor is not running after sending the command, I have obviously made something wrong.

And I guess that it is somewhere around here:

  console.log("Try to startMotor");
        console.log("Will send command to Characteristic:" + motor_characteristic.uuid);
        console.log("Characteristic has writeWithoutResponse ability:" + motor_characteristic.properties.writeWithoutResponse);

        let full_ahead_command_data = new Uint8Array;
        full_ahead_command_data =  Uint8Array.of(0x10, 0x7F, 0x7F, 0x7F, 0x7F, 0x00);
        console.log('Motor command ->' + full_ahead_command_data);

        motor_characteristic.writeValueWithoutResponse(full_ahead_command_data.buffer)
            .then(_ => { })
            .catch(error => {
                console.log('Error: ' + error);
                alert('Error: ' + error);
                return;
            });

I checked the hub and motor with the official app. Both are working fine, so i would appreciate hints where I made something wrong or made a wrong assumption.

array updates in delay on checkbox click

im trying to create an array of user premissions, which can be controled by a set of checkboxes.
when i check a box and console.log() the array it looks just fine with all the premissions i checked, but when i uncheck the box, the console.log() returns the previus array value and it will be ubdated only on the next click

  const [prems, setPrems] = useState([]);

  const handleCheckbox = (e) => {
    let arr = prems
    if (e.target.checked) {
      arr.push(e.target.value)
      setPrems(arr)
      console.log(prems) //shwos the array with all the checked values
    } else {
      let newArr = arr.filter((item) => {
        return item !== e.target.value
      })
      setPrems(newArr)
      console.log(prems) //shows the array still with the value i unchecked
    }
  };

the event on the checkboxes is onChange and it works the same with onClick

How to convert a numeric property of an object in a class to a number and add with other numbers in JS?

I want to add 2 values together at the method in the customer class. one of them is a number and the other is an object property stored in a new class, the send method(a-b) works well, but the receive method(a+b) doesn’t work as a number because it’s an object and it is like a string in js, what is the solution?

export class Customer {
  constructor(name, password, balance) {
    {
      this.name = name;
      this.password = password;
      this.balance = balance;
    }

    this.send = function (amount) {
      return (this.balance -= amount);
    };
    this.receive = function (amount) {
      return (this.balance += amount);
    };
  }
}

export let student = new Customer("alex", "alex", 200);
export let victim1 = new Customer("tom", "cat", 1000);
export let victim2 = new Customer("jerry", "mous", 500);