You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

31 lines
978 B

import * as api from '../../client/src/api/api';
import { EndpointError, EndpointHandler, handleErrorsInEndpoint } from './types';
import Knex from 'knex';
import { sha512 } from 'js-sha512';
import { createUser } from '../db/User';
export const RegisterUser: EndpointHandler = async (req: any, res: any, knex: Knex) => {
if (!api.checkRegisterUserRequest(req)) {
const e: EndpointError = {
name: "EndpointError",
message: 'Invalid RegisterUser request',
httpStatus: 400
};
throw e;
}
const reqObject: api.RegisterUserRequest = req.body;
console.log("Register User: ", reqObject);
try {
await createUser(reqObject, knex);
res.status(200).send();
} catch (e) {
handleErrorsInEndpoint(e);
}
}
export const userEndpoints: [ string, string, boolean, EndpointHandler ][] = [
[ api.RegisterUserEndpoint, 'post', false, RegisterUser ],
];