Everything is validated now
This commit is contained in:
@@ -9,7 +9,7 @@ export const auth_login = (
|
||||
| Responses.Auth.TfaRequiredResponse
|
||||
| Responses.ErrorResponse
|
||||
> =>
|
||||
post<Requests.Auth.AuthLoginRequest>('/api/auth/login', {
|
||||
post<Requests.Auth.LoginRequest>('/api/auth/login', {
|
||||
username: username,
|
||||
password: password,
|
||||
otp: otp
|
||||
@@ -19,7 +19,7 @@ export const auth_signup = (
|
||||
username: string,
|
||||
password: string
|
||||
): Promise<Responses.Auth.SignupResponse | Responses.ErrorResponse> =>
|
||||
post<Requests.Auth.AuthSignUpRequest>('/api/auth/signup', {
|
||||
post<Requests.Auth.SignUpRequest>('/api/auth/signup', {
|
||||
username: username,
|
||||
password: password
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import axios from 'axios';
|
||||
import { Requests, Responses } from 'dto';
|
||||
export { Requests, Responses };
|
||||
import { validateSync } from 'class-validator';
|
||||
|
||||
export const post = <T extends Requests.BaseRequest>(url: string, data: T) =>
|
||||
axios
|
||||
@@ -11,17 +10,12 @@ export const post = <T extends Requests.BaseRequest>(url: string, data: T) =>
|
||||
.then((res) => res.data)
|
||||
.catch((err) => err.response.data);
|
||||
|
||||
export function post_token<T extends Requests.BaseRequest>(
|
||||
export const post_token = <T extends Requests.BaseRequest>(
|
||||
url: string,
|
||||
data: T,
|
||||
token: string
|
||||
) {
|
||||
const errors = validateSync(data);
|
||||
if (errors.length > 0) {
|
||||
console.error('Validation failed, errors: ', errors);
|
||||
throw new Error('Validation failed');
|
||||
}
|
||||
return axios
|
||||
) =>
|
||||
axios
|
||||
.post(url, data, {
|
||||
headers: {
|
||||
Authorization: 'Bearer ' + token,
|
||||
@@ -30,7 +24,6 @@ export function post_token<T extends Requests.BaseRequest>(
|
||||
})
|
||||
.then((res) => res.data)
|
||||
.catch((err) => err.response.data);
|
||||
}
|
||||
|
||||
export const post_token_form = (
|
||||
url: string,
|
||||
|
||||
Reference in New Issue
Block a user