Ensure Typescript Filters Out Unnecessary Data in POST Requests

When making a post request, the required fields are content_name, content_type, and content_json. However, adding an extra property could result in sending unwanted data. How can this be prevented?

Data Transfer Object (DTO):

content_name,
content_type,
Content_json,

An example of the JSON Request sent:

{
  "this_field_shouldnt_be_available" : "Zebb"
}

Request received:

{
  "this_field_shouldnt_be_available" : "Zebb",
  content_name: null,
  content_type: null,
  Content_json: null
}

Is there a way to make an exception using a DTO to only allow valid data without needing a schema? Can it be achieved simply by comparing to the DTO?

Answer №1

Incorporating a middleware that includes validation can ensure that every property key required in the DTO is present, and subsequently checking that the number of keys does not exceed the predetermined limit set for the DTO

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I'm looking to dynamically populate a DropDown list by utilizing Ajax in conjunction with a C# method. Can

Greetings, I have developed a C# method which looks like this: [WebMethod] protected static void populateDropdown(HiddenField hiddenControl, System.Web.UI.WebControls.DropDownList listinc) { int data = 0; string query; dat ...

When attempting to deploy a GitHub repository on Heroku, an error is encountered: error code H10 with description "Application crashed" is received when trying to access the root path ("/") with a GET method

I've encountered this issue and despite my efforts, I have not been able to find a solution that works in my specific scenario. My index.js file includes process.env.PORT, and my package.json already specifies the versions of Node and Yarn that I am ...

How to remove a specific type from a generic type in Typescript without using Exclude<>?

I am looking for a solution to prevent my function from working with Moment objects when storing values in local storage. Currently, the function dynamically stringifies and stores values, but I want to exclude Moment objects from being processed. Here is ...

Guide to setting a Spring form checkbox to read-only status using JavaScript

Is there a way to make a spring form:checkbox tag readonly through JavaScript instead of using the disable function like document.getElementById('id').disabled = true? When I use disable, it doesn't set the value to the command object. ...

Timer Tool: JavaScript Countdown Application

I am currently working on a JavaScript countdown timer, but I need help with setting it to only run for 48 hours every time the page is submitted. Right now, when I enter a time, the timer counts down to that specified time. Can someone please assist me ...

What is the best method for managing heavy loads of AJAX content: Unloading and reloading JavaScript, or

I have a webpage with multiple tabs, let's focus on two: Products and Services. Instead of loading all the tab content at once, I decided to load each tab's specific content only when the tab is clicked. This helps in improving the initial page ...

Dealing with multipart data (for uploading files) using Express

I need to implement file uploads in my Express application. Although I am able to access the uploaded file using request.files.MYFILE in a function uploadFile, the issue arises when this function is only called once the file has been completely uploaded. T ...

Navigate to the top of the screen while in the Bootstrap section

I have successfully created a tab using bootstrap 4 with the following code: <section class="main-section lightblue " id="wstabs"> <a class="anchor" id="description"></a> <div class="bg-dark nav-tabs fixed-top" id="wstabs2" dat ...

"Error: Node.js unable to load express, CSS, and JS files

When I use Express on Node.js, the HTML file I load doesn't seem to fetch JavaScript and CSS files. Here is my index.html code: <!DOCTYPE html> <html lang="en> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatibl ...

What is the reason behind Chrome's automatic scrolling to ensure the clicked element is fully contained?

Recently, I have observed that when performing ajax page updates (specifically appends to a block, like in "Show more comments" scenarios) Chrome seems to automatically scroll in order to keep the clicked element in view. What is causing this behavior? Wh ...

The Fundamentals of AngularJS Providers and Models

As a newcomer to the AngularJS framework, I am faced with a challenge in pulling complex data from a Web API backend into my application's $scope. My goal is to utilize this front-end library to display this data in a calendar widget. My issue lies i ...

Unable to establish express.static from a separate module

Successfully running: var express = require('express'); var app = express(); var request = require('request'); // setting up session require('./config/session.js')(app, function () { // configuring the app require(&a ...

Bring in 2 Angular applications into a different JavaScript project

In my current setup, I have 2 distinct Angular projects. To build each project, I execute the following CLI command: ng build --prod --output-hashing=none Following this command, the build process generates the below files for each project: runtime.js ...

Ways to decrease the size of this item while maintaining its child components?

Here is an object that I am working with: { "name": "A", "children": [ { "name": "B", "open": false, "registry": true, "children": [ { ...

How can I delay the ng-show element until the ng-hide CSS transition has finished?

Looking for a simple solution to my implementation issues. I'm faced with the following DOM setup: <h1 class="fade" ng-repeat="child in parent.children" ng-show="parent.activeChild == child">@{{ child.title }}</h1> How can I smoothly fad ...

Enhancing local storage arrays with Javascript

I am attempting to utilize JSON.parse and JSON.stringify to store and update an array in local storage. However, the process doesn't seem to be functioning as expected. let existingArray = JSON.parse(localStorage.getItem("yesArray")); existin ...

Incorporate a double column to a Sequelize database using the Postgres dialect

I am in the process of establishing a relationship between the parents table and the children table, and this is my approach: // 20210226075430-create-child.js (children migration file) module.exports = { up: async (queryInterface, Sequelize) => { ...

Display JSON data using Vue.js

Trying to display JSON file results using Vue.js, with the goal of showing the result in a value. Here is the code snippet: data () { return { fetchData: function () { var self = this; self.$http.get("/api/casetotalactivation", functio ...

Exploring Node and Express Request Query

I'm struggling with a specific endpoint setup in my code. // GET /api/logs/ app.get('/api/logs', function (req, res) { if (req.query.reverse === true) { res.send((mainModule.logs).reverse()); } else { res.send(mainModule.logs) ...

Invoke the designated JavaScript function within a subordinate <frame>

Below is an example of the standard HTML structure for a parent page named "index.html": <html> <head> <title>test title</title> </head> <frameset cols="150,*"> <frame name="left" src="testleft.html"> ...