dataSource flag in typeorm cli

I’m starting a project with typeorm. My configuration file looks like this:

ormconfig.js

import dotenv from 'dotenv'
dotenv.config();


const {
    DATABASE_HOST,
    DATABASE_PORT,
    DATABASE_NAME,
    DATABASE_PASSWORD
} = process.env




export default {
    type: 'postgres',
    host: DATABASE_HOST,
    port: DATABASE_PORT,
    database: DATABASE_NAME,
    password: DATABASE_PASSWORD,
    entities: [
        "./api/modules/documents/entity/*.js",
    ],
    migrations: [
        "./api/database/migrations/*.js",
    ],
    cli: {
        migrationsDir: "./api/database/migrations",
        entitiesDir: "api/database/modules/**/entity"
    }
}

package.json scripts

"scripts": {
    "gulp": "node_modules/gulp-cli/bin/gulp.js",
    "start": "nodemon ./src/app.js",
    "start:api": "nodemon ./api/server.js",
    "typeorm": "node ./node_modules/typeorm/cli.js --config ./ormconfig.js"
},

When i try to run the command yarn typeorm migration:run its show this message:

Runs all pending migrations.

Opções:
  -h, --help         Exibe ajuda                                      [booleano]
  -d, --dataSource   Path to the file where your DataSource instance is defined.
                                                                   [obrigatório]
  -t, --transaction  Indicates if transaction should be used or not for
                     migration run. Enabled by default.      [padrão: "default"]
  -v, --version      Exibe a versão                                   [booleano]

Missing required argument: dataSource

What would be datasource flag?
I tried with typeorm cli installed globally, same problem happens

Can’t modify a property of an object in an array after using the filter method

I have 2 arrays of objects (the same): 1 (artificesToAdd[]) which can contain 0 or more objects and the 2nd (newFilter[]) which can also contain 0 to a couple of objects, based on a search performed by a user.

The goal is that for each object contained in the artificesToAdd[] array, I check if this object also exists in the newFilter[] array.
If so, I need to update the ‘qtyToAdd’ property to indicate the quantity that is initially in my first array.

Unfortunately I get this error :

'Uncaught TypeError: Cannot add property qtyToAdd, object is not extensible'

My understanding is that this array can’t be modified because it’s in reference but I’m not sure about this and I don’t know how to resolve it?
Should I create another array and push items needed inside?

The error occur on this particular line: newFilter[artIndex].qtyToAdd = item.qty;

    const handleFilter = (event: any) => {
    const searchWord: string = event.target.value;
    const newFilter = artifices.filter((value) => {
        return value.codeGF.toUpperCase().includes(searchWord.toUpperCase());
    });
    // Now let's add ART who had a qty
    if (artificesToAdd.length > 0) {
        let artIndex: number;

        artificesToAdd.forEach(function (item) {
            artIndex = newFilter.findIndex((i) => i.id === item.id);
            if (artIndex === -1 || artIndex === undefined) return;
            console.log(newFilter[artIndex]);
            newFilter[artIndex].qtyToAdd = item.qty;
        });
    }
    setFilteredArtifices(newFilter);
};

sort the menu alphabetically in angular

am trying to figure out if there’s a to sort the items(buttons) inside the menu in alphabetical order by means of a function in the typescript file, please the following code which uses angular material.

<mat-menu #menu3="matMenu" [overlapTrigger]="false">
   <button mat-menu-item [routerLink]="['A']">A</button>
   <button mat-menu-item [routerLink]="['C']">C</button>
   <button mat-menu-item [routerLink]="['D']">D</button>
   <button mat-menu-item [routerLink]="['B']">B</button>  
</mat-menu>

Add a notification after logging in on google login PHP

What I am trying to achieve is that if you are not on the array list of people you cannot login even if you used google login so here is my code

<?php
$emails = array("[email protected]","[email protected]","[email protected]","[email protected]","[email protected]");


if(in_array($_SESSION['user_email_address'], $emails, TRUE))
    {
      $user->registerLogs($_SESSION['user_email_address'],' has logged in!');
      header('location: daily_quotes.php');
    }
    else
    {
      $google_client->revokeToken($_SESSION['access_token']);

      $helper = array_keys($_SESSION);
      foreach($helper as $key)
      {
          unset($_SESSION[$key]);
      }
    }

 $login_button = '<a class="btn btn-lg btn-google btn-block text-uppercase btn-outline swalDefaultSuccess" href="'. $google_client->createAuthUrl().'"><img src="VHSZf.png"/></a>';
?>

<script>
$(function (){
    var Toast = Swal.mixin({
        toast: true,
        position: 'top-end',
        showConfirmButton: false,
        timer: 3000
      });
      
    $('.swalDefaultSuccess').click(function() {
      Toast.fire({
        icon: 'error',
        title: 'You are not allowed because you are not in the list!'
      })
      });
  });
</script>

To explain further I just need a notification or just even an alert after I log in and detect that you are not on the list then show the alert/swalalert. That’s it.

Populating a form in React with information from an useEffect function

everyone!

I am developing an app for an ecommerce platform (VTEX), and right now I’m facing a roadblock on how to populate a form with info from an API Call. The code goes as follows:

import React, { useEffect, useState } from 'react';
import { useRuntime } from 'vtex.render-runtime';
import axios from 'axios';

import GetOrderInfo from './GetOrderInfo';

const Generate = () => {
  const { query } = useRuntime();
  const order_id = query!.order_id

  useEffect(() => {
    const order_data = GetOrderInfo(order_id);

    console.log(order_data);
  }, []);

  // State variables based on the form
  const [order_number, setOrderNumber] = useState<string>(`${order_id}`);
  const [personal_data, setPersonalData] = useState<string>("");

The API Call happens in the GetOrderInfo function, passing the order_id from the URL params. The code for this function is:

import axios from "axios"

const GetOrderInfo = async (_order_id: string) => {

    const options = {
        path: `/api/oms/pvt/orders/${_order_id}`,
        headers: {
            "X-VTEX-API-AppToken": process.env.APP_TOKEN,
            "X-VTEX-API-AppKey": process.env.APP_KEY,
            "X-Vtex-Use-Https": "true"
        }
    };

    const { data } = await axios({
        method: "GET",
        url: `${options.path}`,
        responseType: "json",
        headers: options.headers
    })

    return data;

}

How do I return info from the useEffect in order to use it to pass it on the state of personal_data, so the info will be displayed in the form when the user finally loads it?

open links in iframe one by one when press button

i’ve a array of three links for a button which i’m using in footer and when i press the button again and again , array will work one by one good ..and every time it shows a link when press the button. That is good.
but i want , when i click on button that “link” should open in “iframe” … i used iframe code to pass them src= button id but not working.. please below code and help..
.
my button code with array

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.footer {
   position: fixed;
   left: 0;
   bottom: 0;
   width: 100%;
   background-color: red;
   color: white;
   text-align: center;
}
</style>

<script>
let link = new Array()
link[0] = "https://www.clc-uk.org.uk/cms/cms.jsp?menu_id=26131&postcode=AL3+8QE&distance=20"
link[1] = "https://www.clc-uk.org.uk/cms/cms.jsp?menu_id=26131&postcode=AL5+3NG&distance=20"
link[2] = "https://www.clc-uk.org.uk/cms/cms.jsp?menu_id=26131&postcode=AL4+3NS&distance=20"

let intlinkIndex = 0;

function writeLink() {
  if (intlinkIndex >= link.length) {
    let btn = document.getElementById('btn');
    btn.style.display = 'none';
    mylink.style.display = 'none';
  }
    document.getElementById('mylink').innerHTML = '<a href="' + link[intlinkIndex] + '">' + link[intlinkIndex] + '</a>';
    intlinkIndex++;



}
</script>





</head>
<body>



<div class="footer"> 

<button id="btn" onclick="writeLink();">Click Me</button>

<div id="mylink"></div>

<br>


<iframe id="iframe" src="mylink" width="100%" height="400"></iframe>

</div>

</body>
</html> 

     

React modal context hook fails to open more than one modal

My context for displaying modals works perfectly when used to display a single modal. However, when I try open a modal on top of a modal, nothing happens. Setting a breakpoint in showDialog reveals that the function is triggered when opening the first modal, but not for successive modals as long as the first one remains open. I do not understand this behavior. Why does it not trigger?

type DialogComponent = (onClosed: () => void) => JSX.Element;

interface DialogState {
    showDialog: (dialog: DialogComponent) => void;
    clearDialogs: () => void;
}

const DialogContext = createContext<DialogState>({
    showDialog: (_dialog) => {},
    clearDialogs: () => {},
});

export const useDialog = () => useContext(DialogContext);

export const DialogProvider = ({ children }: PropsWithChildren<{}>) => {
    const [dialogs, setDialogs] = useState<Array<DialogComponent>>([]);

    const showDialog = (dialog: DialogComponent) => {
        setDialogs([dialog, ...dialogs]);
    };

    const closeDialog = (dialog: DialogComponent) =>
        setDialogs(dialogs.filter((d) => d !== dialog));

    return (
        <>
            {dialogs.map((dialog) => (
                <div key={UniqueId()}>{dialog(() => closeDialog(dialog))}</div>
            ))}

            <DialogContext.Provider
                value={{
                    showDialog,
                    clearDialogs: () => setDialogs([]),
                }}
            >
                {children}
            </DialogContext.Provider>
        </>
    );
};

Prevent original array from getting changed

I have an array that consists of some geoJSON data. I want to create a new array consisting of the data with one more key in the properties section. But it keep changing the original array. How can I prevent it from changing the orignial array?

const [citys, setCitys] = useState(someGeoJson)
const [manipulatedArray, setManipulatedArray] = useState([])

function createManiArray() {
  citys.features.forEach((city) => {
    let currentCity = city
    currentCity.properties = { ...city.properties,
      value: Math.random()
    }
    manipulatedArray.push(currentCity)
    //My problem now is that this changes the orginal city array, how can i prevent that from happening?
  })
}

create a simple waiting lobby

I am trying to create a waiting lobby in which when i fire a post request on the api it stores the data of the player and then wait for another player to join. when new player joins then it pairs the players and then returns them in the the response of both players.
But problem i am facing is that when i am firing the request from the first player it is not waiting and instantly returning 404 error.

This is the code:-

this is the function that runs when the api is called:-

startGame(ctx) {
const player = ctx.request.body;
addToPlayers(player);
messageBus.on('match', (data) => {
  return data;
})}

this is the helper functions and emitters:-

var players = [];
var EventEmitter = require('events').EventEmitter;
var messageBus = new EventEmitter();
messageBus.setMaxListeners(100);

// function to manage players array
function addToPlayers(player) {
if (!player) {
return;
}
players.push(player)
if (players.length >= 2) {
const player1 = players.shift();
const player2 = players.shift();
messageBus.emit('match', {player1, player2});
}}

the post request consists of:-
{
“id”: “1”,
“amount”: “1000”
}

Method check close status of tab Error When check with link Google search

var link1="https://www.google.com/search?q=marketing";
//var link2="https://stackoverflow.com/";
var tab=window.open(link1,"_blank");
setInterval(function(){checkTabsClosed()},3000);
function checkTabsClosed()
{
if (tab.closed)
    console.log("close");
else 
    console.log("open");
}

When I user link2, it is ok. But I user link1, it is not ok.
Please help me code to check tab in this case link1.

how to write html with jquery inside angular

Due to certain dependencies I have to write some html code using using jquery like this inside my component.ts file:

 var serial = '<td><label for="SN_' + this.prevRowCount + '" (mouseenter)="testFunc();" (mouseleave)="toolTipClear(this);">Serial Number:</label><input id="SN_' + this.prevRowCount + '" size="15" name="SN_' + this.prevRowCount + '" type="text" value="" /></td>';

In this I am trying to call testFunc() on mouse enter event:

testFunc(){
console.log('Inside this test fucntion---> ')

}

But this function is not being called. How can I implement this?
Also if I want to pass the element reference using $event, is it possible?

How to fix React Apex Chart initial mount delay?

I am using React Apex chart library in my project.I’ve figured that the library charts have a small delay before rendering on initial mount.

This issue harms the UX because the component that renders ApexCharts won’t be displayed until after the delay.

import React from "react";
import Chart from "react-apexcharts";

function MixedChart() {
    const data = {
      options: {
        chart: {
          id: "basic-bar"
        },
        xaxis: {
          categories: [1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999]
        }
      },
      series: [
        {
          name: "series-1",
          data: [30, 40, 45, 50, 49, 60, 70, 91]
        }
      ]
    };

    return (
         <div className="mixed-chart">
           <Chart
             options={data.options}
             series={data.series}
             type="bar"
             width="500"
           />
         </div>
    );

}

export default MixedChart;

Is there a way to fix this ?

How can I make an image file appear by default in my Upload component? (React.js)

I am attempting to create an image file uploader with React that displays a preview of the file that is selected by the user. I was able to make it so that when a user selects an image, that image is previewed and is displayed correctly. However, I want a default image that I have in my ‘/images/user-solid.jpeg’ path to appear by default, and for it to be replaced by whatever image the user selects. How can I accomplish this? Any information would be appreciated, thank you!

Upload.jsx:

import '../../components/pages/styles/Uploads.css';
import {useEffect, useState} from 'react';
import {} from 'react-router-dom';
import {useSelector} from 'react-redux';
import axios from 'axios';
import authHeader from '../../services/auth-header';

function Uploads() {
    const {user: currentUser} = useSelector((state) => state.auth);
    const [file, setFile] = useState();
    const [description, setDescription] = useState('');
    const [loading, setLoading] = useState(false);
    const [content, setContent] = useState('');
  
    const imageSubmit = async (event) => {
        event.preventDefault();

        const formData = new FormData();
        formData.append('file', file);

        const result = await axios.post(
            API_URL + '/image/upload',
            formData,
            {
                headers: {...authHeader(), 'Content-Type': 'multipart/form-data'},
            }
        );
        console.log(result.data);
    };

    return (
        <div className='page'>
            <div className='upload-card'>
                {file && (
                    <div id='preview'>
                        <img
                            src={URL.createObjectURL(file)}
                            id='image'
                            alt='Thumbnail'
                            className='user-post'
                        />
                    </div>
                )}
            </div>
            <div className='upload-container'>
                <div className='post-form-container'>
                    <p id='upload-form-label'>
                        Hello, {currentUser.username} feel free to post an image!
                    </p>
                    <form
                        onSubmit={profileImageSubmit}
                        // onSubmit={'return Validate(this);'}
                        className='upload-form'
                    >
                        <div className='panel'>
                            <div className='button_outer'>
                                <div className='btn_upload'>
                                    <input
                                        filename={file}
                                        onChange={(e) => setFile(e.target.files[0])}
                                        type='file'
                                        accept='image/*'
                                        id='image-selection-btn'
                                        Upload
                                        Image
                                    ></input>
                                    Choose your Art
                                </div>
                            </div>
                        </div>
                        <button type='submit' id='post-upload-btn'>
                            Upload Image
                        </button>
                    </form>
                </div>
            </div>
        </div>
    );
}

export default Uploads;

Insert data after event.target (Owl Carousel)

I am following this codepen here to insert the current and total number of slides on an Owl carousel. Trouble is it targets a div with ID #counter. So if there are multiple carousels on the same page then the value is always overwritten for both and not the current slider.

I dont seem to be able to manipulate the contents of event.target as it appears to be read only.

I have found if I change this line:

$('#counter').html("item "+item+" of "+items)

To this then it works. But the new value is always appended and I don’t seem to be able to replace it.

$(event.target).append(item+" - "+items);