diff --git a/mobile/src/contexts/data_context.tsx b/mobile/src/contexts/data_context.tsx index 8ec516ce6050a56eb1fd1b005f74dd5ae39f56ac..e216b1c88d40cb59714756d2163de3f4880d290f 100644 --- a/mobile/src/contexts/data_context.tsx +++ b/mobile/src/contexts/data_context.tsx @@ -22,7 +22,7 @@ const DataContext = createContext({ export const DataContextProvider = ({ children }: DataContextProviderProps) => { const statesDataSource = new StateDataSourceDev(); const statesRepository = new StateRepositoryImpl(statesDataSource); - const authDataSource = new AuthDataSourceDev(); + const authDataSource = new AuthDatasourceProd(); const authRepository = new AuthRepositoryImpl(authDataSource); diff --git a/mobile/src/infrastructure/datasource/prod/auth_datasource.ts b/mobile/src/infrastructure/datasource/prod/auth_datasource.ts index 123b1890563fe7a2615bef292439cca4262239dd..37714d19fb570ba22eb2c831e372e7c2158d4f49 100644 --- a/mobile/src/infrastructure/datasource/prod/auth_datasource.ts +++ b/mobile/src/infrastructure/datasource/prod/auth_datasource.ts @@ -6,6 +6,7 @@ import { userRegisterEntityToUserRegisterModel } from "../../utils/prod/user_uti import { API_URL } from "../../../constants/api"; import { LoginUserModel } from "../../models/prod/login_user_model"; import { UserInfoEntity } from "../../../domain/entities/user_info_entity"; +import { RegisterResponseModel } from "../../models/prod/register_user_model"; export class AuthDatasourceProd implements AuthDataSource { login: (email: string, password: string) => Promise = async (email, password) => { @@ -14,32 +15,35 @@ export class AuthDatasourceProd implements AuthDataSource { password }; //TODO: Hacer el login info model y el user info model cuando se termine la documentación - const { data, status } = await axios.post<{ token: string, user: UserInfoEntity }>(`${API_URL}/user/signin`, loginInfo); - if (status !== 200) { + const { data, status } = await axios.post(`${API_URL}/user/signin`, loginInfo); + if (status !== 201) { throw new Error("Error logging in"); } const loginResponse: LoginInfoEntity = { - token: data.token, - user: data.user + token: data.user.token, + user: { + id: data.user.userId, + email: data.user.email, + name: data.user.name, + lastName: data.user.lastName, + } } return loginResponse; }; register: (user: RegisterInfoEntity) => Promise = async (user) => { const newUser = userRegisterEntityToUserRegisterModel(user); - const { data, status } = await axios.post<{ token: string }>(`${API_URL}/user/signup`, newUser); - //TODO: Falta regresar el id del usuario + const { data, status } = await axios.post(`${API_URL}/user/signup`, newUser); if (status !== 201) { throw new Error("Error registering user"); } const registeredUser: LoginInfoEntity = { - token: data.token, + token: data.user.token, user: { - id: 1, - email: newUser.email, - name: newUser.name, - lastName: newUser.lastName, - birthDate: new Date(newUser.birthDate) + id: data.user.userId, + email: data.user.email, + name: data.user.name, + lastName: data.user.lastName } } return registeredUser; diff --git a/mobile/src/infrastructure/models/prod/register_user_model.ts b/mobile/src/infrastructure/models/prod/register_user_model.ts index 259450eb1a7e51ab9310e9ef9602d9a651cf082e..5098002a7bd23e1735dbfc5ccad5e810a5e5008b 100644 --- a/mobile/src/infrastructure/models/prod/register_user_model.ts +++ b/mobile/src/infrastructure/models/prod/register_user_model.ts @@ -4,4 +4,14 @@ export interface RegisterUserModel { name: string; lastName: string; birthDate: string; +} + +export interface RegisterResponseModel { + user: { + userId: number; + email: string; + name: string; + lastName: string; + token: string; + } } \ No newline at end of file