I have this endpoint in my express server:
app.post('/users', express.json(), async (request, response, next) => {
try {
console.log(`${request.method} ${request.url} was called.`);
let user: User = request.body;
let sessionId: string = request.query.sessionId as string;
let captcha: string = request.query.captcha as string;
let errors: string[] = await UserStore.CreateUser(elastic, smtp, user, sessionId, captcha);
response.status(errors.length <= 0 ? 201 : 400).send(errors);
}
catch (error) {
next(error);
}
});
Additionally, this is my User class:
export class User {
public Username: string;
public Password: string;
public Email: string;
public EmailVerified: boolean;
public Country: string;
public State: string;
public City: string;
public Gender: string;
public BirthdayTicks: number;
}
Is there a standard way in express or typescript to only parse and generate a whitelisted set of properties for a new User class from the JSON body, or do I have to new one up and set properties on it manually?
The problem right now is that request.body may have additional properties that don't exist in the model of a User or properties such as EmailVerified, which I don't want the user to be able to set themselves. If these go to the elastic server, they will be indexed.