How to call the validateRecruiters function with different parameters

How to call the validateRecruiters function in the following code depending on the interview type (TECHNICAL_INTERVIEW or HR_INTERVIEW). Notice that the validateRecruiters function takes more parameters in the HR_INTERVIEW call. Could you suggest which design pattern to use so that will be universal in every case?

import { getHrRecruiters, getRecruiters } from '../queue';
import { validateTechnicalInterview } from './validateTechnicalInterview';
import { matchHrRecruiters } from './matchHrRecruiters';
import { THrInterviewer, THrRecruit, TRecruit } from '../../types';

export const recruitersCategoryHandlers = {
  TECHNICAL_INTERVIEW: {
    getter: getRecruiters,
    setter: {
      validateRecruiters: (
        recruiters: THrInterviewer[],
        recruit: TRecruit | THrRecruit
      ) => validateTechnicalInterview(recruiters, recruit),
    },
  },
  HR_INTERVIEW: {
    getter: getHrRecruiters,
    setter: {
      validateRecruiters: (
        recruiters: THrInterviewer[],
        recruit: TRecruit | THrRecruit,
        param3: any,
        param4: any
      ) => matchHrRecruiters(recruiters, recruit as THrRecruit, param3, param4),
    },
  },
};
const matchedSlots = getMatchingSlots(
          recruitersCategoryHandlers[
            interviewCategory as EInterviewCategory
          ].setter.validateRecruiters(???),
          slotsWithEmail
        );

The solution works when I have the same parameters. Unfortunately, I’m not sure how to do this with different parameters.

How does using the useState hook compare to the formData method for handling form data in React?

I’m looking forward for the easiy and understandable explanation of the difference between useState and formData method for handling form data in React.

Example code with useState:

const InitialForm = {
  amount: 0,
  descritpion: "",
};
export default function TransactionForm({ fetchTransaction, editTransaction }) {
  const [form, setForm] = useState(InitialForm);
  function handleInput(e) {
    setForm({ ...form, [e.target.name]: e.target.value });
  }
 <form onSubmit={handleSubmit}>
          <TextField
            type="number"
            name="amount"
            value={form.amount}
            onChange={handleInput}
          />
          <TextField
            name="descritpion"
            value={form.descritpion}
            onChange={handleInput}
          />
          <Button type="submit">Submit</Button>
          )}
  </form>
}

Example code with Form Data:


export default function TransactionForm({ fetchTransaction, editTransaction }) {
  function handleInput(e) {
    const data = new FormData(event.currentTarget);
  }
 <form onSubmit={handleSubmit}>
          <TextField
            type="number"
            name="amount"
            value={form.amount}
            onChange={handleInput}
          />
          <TextField
            name="descritpion"
            value={form.descritpion}
            onChange={handleInput}
          />
          <Button type="submit">Submit</Button>
          )}
  </form>
}

Thank you in advance

I’m looking forn better solution for handling form data in React

What’s the best way to create a shopping list that allows users to add and store items with HTML, CSS, and JavaScript? [closed]

I am working on a project that is just something to learn a little and I’m stuck. I am trying to code something that allows the users to type in a text area and when clicking the submit button it adds the text from text area to a list (I don’t have a preference as to ordered or unordered list). I have messed around and got the box to submit one item, but I am trying to make something that stores pervious input and just adds news ones when submitting another input from user.
This is what i have so far:

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Shopping list</title>
<link rel="stylesheet" href="https://jsfiddle.net/Andmack/fsyw15ak/66/show_css">
</head>
<body style='background-color: #626567;'>
<h1 style='background-color: #1B2631; color: white; text-align: center;'>
Shopping List </h1>
<form>
<label><b>What items I Need:</b></label>
<input type="text-area" name="lsit" id="user_input">
</form>
</body>
</html>

CSS
label {
  background-color: lightBlue;
  color: black;
  text-align: center;
}

I have tried making a button that takes date but I don’t quite now how to get it to display onscreen and store date until cleared.

I am just learning to code don’t judge LOL.

-thinks in advance.

The compression JavaScript file failed from using Combres DLL in Asp.Net MVC 4

I have used Combres Dll to compress the javascript file but an exception occurred i. e. “EcmaScript.NET.EcmaScriptRuntimeException”
Combres.xml file code is below,

<?xml version="1.0" encoding="utf-8" ?>
<!--
  This file contains basic settings needed for most web apps.
  For full Combres settings (with explanation), refer to the sample definition file: combres_full_with_annotation.xml
  Also, refer to Combres' documentation: http://combres.codeplex.com/documentation  
-->
<combres xmlns='urn:combres'>
  <filters>
    <filter type="Combres.Filters.FixUrlsInCssFilter, Combres" />
  </filters>
  <resourceSets url="~/combres.axd"
                defaultDuration="30"
                defaultVersion="auto"
                defaultDebugEnabled="false"
                defaultIgnorePipelineWhenDebug="true"
                localChangeMonitorInterval="30"
                remoteChangeMonitorInterval="60"
                >
    <resourceSet name="siteCss" type="css">
      <resource path="~/content/bootstrap.css" />
      <resource path="~/content/Site.css" />
    </resourceSet>
    <resourceSet name="siteJs" type="js">
      <resource path="~/scripts/bootstrap.bundle.min.js" />
    </resourceSet>
  </resourceSets>
</combres>

Note It easily compresses all CSS files but returns the above exception when compressing JavaScript files.

I tried different versions of Combres Dll but every version return the same exception.

I expect that my JavaScript file easily compress using Combres Dll or any alternative way to compress JavaScript files.
I expect a suitable and accurate solution.

Unexpected end of JSON input from AWS API Gateway

I’m trying to setup an API Gateway REST API that prompts a Lambda function and returns some items from a DynamoDB table.

When I test the API in the AWS API Gateway console I am getting the correct data back, but getting a Unexpected end of JSON input error trying in JavaScript (just trying in JS Fiddle).

Here is my fetch function:

function fetchData(){
    fetch("https://abcd1234.execute-api.region.amazonaws.com/stage/product?productId=1234"
    ).then(response => {
        return response.json()
    }).then(jsonData => {
        console.log('success:', jsonData)
    }).catch(e => {
        console.log('error:', e.message)
        return e
    })
}

It’s a get method in the Lambda function and I’m newer to this, so not sure what I’m doing wrong. If it was a CORS issue would I get a different message back?

Forbidden 403 when trying to update via Google Calendar API

Trying to update a calendar event, with Googles API. It’s not working out for some reason… It’s just telling me “forbidden”, and I can’t find anything on Googles error handling documentation that matches this error message.

A few important key points:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "forbidden",
    "message": "Forbidden"
   }
  ],
  "code": 403,
  "message": "Forbidden"
 }
}

The data I’m trying to send:

let data = {
    'start': {
        dateTime: event_data.start.dateTime //This data is correct and is formatted to rfc3339
    },
    'end': {
        'dateTime': new Date().toISOString()
    } 
};

return new Promise((resolve, reject) => {

    xhr.onreadystatechange = (e) => {
      if (xhr.readyState !== 4) {
        return;
      }

      if (xhr.status === 200) {
        resolve(JSON.parse(xhr.responseText));
      } else {
        console.warn('request_error');
      }
    };

    xhr.open('PUT', 'https://www.googleapis.com/calendar/v3/calendars/'+calendar_id+'/events/'+event_id);
    xhr.setRequestHeader('Authorization', 'Bearer ' + access_token);
    xhr.send(JSON.stringify(data));
});

How to enable TypeScript to infer the exact shape of data objects in a generic HttpServiceMock using Typescript Generics and Interfaces?

I am currently working with TypeScript and I want to achieve something that I don’t really know if it is possible (I trust it is).

I have this code as example:

interface HttpServiceMockData<T> {
  status: number;
  data: T;
  url: string;
}

export function createHttpServiceMock<T>(data: HttpServiceMockData<T>[]) {
  return {
    get: async (url: string): Promise<{ data: T }> => {
      const res = data.find((d) => d.url === url);
      if (!res) {
        throw new Error(`No data found for url ${url}`);
      }
      return {
        data: res.data,
      };
    },
  };
}

const service = createHttpServiceMock([
  {
    url: '/users/1',
    data: {
      id: 1,
      username: 'test',
    },
    status: 200,
  },
  {
    url: 'test',
    data: {
      id: 1,
      username: 'test',
      lastname: 'test',
    },
    status: 200,
  },
]);

const res = service.get('test').then((res) => {
  res.data // I want typescript to know the exact type here ( inference power )
});

At the moment TypeScript knows what to return but it doesn’t know what shape exactly the data object has and it gives me lastname as optional, which I don’t want.
I want to pass the URL and TypeScript should understand what I want to get.

Any idea?

How to create NX lib without changing package.json and upgrading dependencies

I am trying up create a new lib in a big project. When I generate a lib it upgrades react,typescript and other packages in package.json which is something I don’t want in a global project.
I’ve tried using the extension and it does the same. Even with the –skipPackageJson it upgrades some devDependencies.

these are some commands that I used :
1:nx g lib name –features/project
2:nx generate @nx/react:library name –unitTestRunner=jest –bundler=vite –direnctory=features/project –skipPackageJson

What am I doing wrong?

How to use a local filename as a url in Javascript?

`function create() {
            win = window.open();
            win.document.body.style.margin = '0';
            win.document.body.style.height = '100vh';
            win.document.body.style.width = '100vw';

            var icon = win.document.createElement('link')
            icon.rel = "shortcut icon"
            icon.href = window.location.origin+"https://spheredata.github.io/Media/classroom.png"
            icon.type = "image/png"
            win.document.head.appendChild(icon)

            var title = win.document.createElement('title')
            title.innerText = "Classroom"
            win.document.head.appendChild(title)

            var url = "https://spheredata.github.io/launcher.html";

            var iframe = win.document.createElement('iframe');
            iframe.style.border = 'none';
            iframe.style.width = '100%';
            iframe.style.height = '100%';
            iframe.style.margin = '0';
            iframe.id = 'content';
            iframe.src = url;
            win.document.body.appendChild(iframe);

        }`

Can is there a way to replace url with launcher.html instead of https://spheredata.github.io/launcher.html? Whenever I try, it just breaks.

When I just do it, it launches about:blank, but without the iframe that I want.

How to use .css files alongside your .ts(x) files with tsdx

I am currently writing a custom component library in React. Obviously, this requires styling of the components. So each component, like <Button /> has an accompanying CSS file which is imported in each component by import ./styles.css.

However, when I try to build the library, I am getting

Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
at C:Users…srcatmosbase-textstyles.css:1:0

And it gives me syntax highlight

1: .button-container {
   ^
2:     font-family: var(--main-font);
3: }

This is my tsdx.config.js file

/* eslint-disable @typescript-eslint/no-var-requires */
const postcss = require('rollup-plugin-postcss');
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');

module.exports = {
    /**
     * @param {import('rollup/dist/rollup').InputOptions} config
     */
    rollup(config, options) {
        config.plugins.push(
            postcss({
                modules: true,
                plugins: [
                    autoprefixer(),
                    cssnano({
                        preset: 'default',
                    }),
                ],
                sourceMap: true,
                inject: true,
                extract: false,
            })
        );
        return config;
    },
};

How can I include .css files into my library?

How to compare and get specific values from JSON array

I am trying to get all departments that’s not belongs in the dep_log array and have deleted=1 then I am trying to push them in new json object in javascript or jquery.

var departments=[{"department_id": "1"},{"department_id": "2"},{"department_id": "3"}]

var dep_log =[{"department_id": "3", "creation_date": "2023-05-13 17:59:27", "created_by": "1", "deleted": "1"},{"department_id": "2", "creation_date": "2023-05-13 17:59:11", "created_by": "1", "deleted": "0"},{"department_id": "2", "creation_date": "2023-05-13 09:46:25", "created_by": "1", "deleted": "0"}]

Query to identify parent in Query on the M2O, O2M, M2M, M2A relation

Context: If we have an item from the collection A, which it is related to the collections N, then return all the collections N where this item is related until find the top parent.

In the middle there are many relationship that could be related through differents kind of relationship.

How can I do that?

Many of my relationship are made of M2A.

I found this as well https://discord.com/channels/725371605378924594/1019641731332976722/threads/1034741934415167498

I tried with this API in a descending order:
https://discord.com/channels/725371605378924594/1019641731332976722/threads/1034741934415167498