Cadastrando no banco

This commit is contained in:
Hugo Falcao
2022-04-17 22:41:01 -03:00
parent 2dde2de166
commit 373df29679
7 changed files with 3470 additions and 952 deletions

8
src/services/api.ts Normal file
View File

@@ -0,0 +1,8 @@
import axios from 'axios';
import apiConfig from '../config/api.config';
const instance = axios.create({
baseURL: apiConfig.getBaseUrl(),
});
export default instance;

46
src/services/users.ts Normal file
View File

@@ -0,0 +1,46 @@
import instance from '../services/api';
// import LocalStorage from '../LocalStorage';
let token:string;
let header:string;
function updateHeader() {
// token = LocalStorage.getToken();
header = `{
"Accept": 'application/json',
"Content-Type": 'application/json',
"Authorization": 'Bearer ' + token
}`
}
export interface CadastroResponse {
message?: string;
token?: {
token: string;
};
error?: string;
}
export interface CadastroRequest {
name: string;
username: string;
email: string;
birth_date: string;
password: string;
}
// export async function get(cpf) {
// updateHeader();
// const response = await instance.get(userRoutes.get.url + `/${cpf}`, { headers: header });
// return response.data;
// }
export async function create(CadastroRequest: any) {
updateHeader();
const response = await instance.post("http://localhost:3333/users/", CadastroRequest);
return response.data;
}