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 ], ];