Loading mobile/src/profile/infrastructure/datasources/prod/profile_datasource.ts +55 −15 Original line number Diff line number Diff line Loading @@ -2,25 +2,65 @@ import axios from "axios"; import { IOption } from "../../../../common/domain/entities/option"; import { ProfileDataSource } from "../../../domain/datasources/profile_datasource"; import { API_URL } from "../../../../common/constants/api"; import { CategoryModel } from "../../model/categorie_model"; import { categoryModelToOption } from "../../utils/category"; export class ProfileDataSourceProd implements ProfileDataSource { private readonly lang: string; constructor(lang: string) { this.lang = lang; } async getUserInterests(): Promise<IOption[]> { const {data, status} = await axios.get<CategoryModel[]>(`${API_URL}/user/prefered-categories?lang=${this.lang}`); if (status !== 200) { throw new Error("Error getting user interests"); } const categories = data.map(categoryModelToOption); return categories.map((category) => ({ ...category, isSelected: true, })); } async getInterests(): Promise<IOption[]> { throw new Error('Method not implemented.'); //TODO: Implement this method const { status, data } = await axios.get<CategoryModel[]>( `${API_URL}/category?lang=${this.lang}` ); if (status !== 200) { throw new Error("Error getting interests"); } return data.map(categoryModelToOption); } async saveInterests(options: IOption[]): Promise<void> { throw new Error('Method not implemented.'); const payload = { idCategories: options.map((option) => option.id), }; const { status } = await axios.patch( `${API_URL}/user/update-prefered-categories`, payload ); if (status !== 200) { throw new Error("Error updating interests"); } } async setUpProfile(birthdate: string, interests: IOption[]): Promise<void> { throw new Error('Method not implemented.'); throw new Error("Method not implemented."); } async changePassword(oldPassword: string, newPassword: string): Promise<void> { const {status, data} = await axios.patch(`${API_URL}/user/change-password`, { async changePassword( oldPassword: string, newPassword: string ): Promise<void> { const { status, data } = await axios.patch( `${API_URL}/user/change-password`, { prevPassword: oldPassword, newPassword: newPassword }) newPassword: newPassword, } ); console.log(status, data); } } Loading
mobile/src/profile/infrastructure/datasources/prod/profile_datasource.ts +55 −15 Original line number Diff line number Diff line Loading @@ -2,25 +2,65 @@ import axios from "axios"; import { IOption } from "../../../../common/domain/entities/option"; import { ProfileDataSource } from "../../../domain/datasources/profile_datasource"; import { API_URL } from "../../../../common/constants/api"; import { CategoryModel } from "../../model/categorie_model"; import { categoryModelToOption } from "../../utils/category"; export class ProfileDataSourceProd implements ProfileDataSource { private readonly lang: string; constructor(lang: string) { this.lang = lang; } async getUserInterests(): Promise<IOption[]> { const {data, status} = await axios.get<CategoryModel[]>(`${API_URL}/user/prefered-categories?lang=${this.lang}`); if (status !== 200) { throw new Error("Error getting user interests"); } const categories = data.map(categoryModelToOption); return categories.map((category) => ({ ...category, isSelected: true, })); } async getInterests(): Promise<IOption[]> { throw new Error('Method not implemented.'); //TODO: Implement this method const { status, data } = await axios.get<CategoryModel[]>( `${API_URL}/category?lang=${this.lang}` ); if (status !== 200) { throw new Error("Error getting interests"); } return data.map(categoryModelToOption); } async saveInterests(options: IOption[]): Promise<void> { throw new Error('Method not implemented.'); const payload = { idCategories: options.map((option) => option.id), }; const { status } = await axios.patch( `${API_URL}/user/update-prefered-categories`, payload ); if (status !== 200) { throw new Error("Error updating interests"); } } async setUpProfile(birthdate: string, interests: IOption[]): Promise<void> { throw new Error('Method not implemented.'); throw new Error("Method not implemented."); } async changePassword(oldPassword: string, newPassword: string): Promise<void> { const {status, data} = await axios.patch(`${API_URL}/user/change-password`, { async changePassword( oldPassword: string, newPassword: string ): Promise<void> { const { status, data } = await axios.patch( `${API_URL}/user/change-password`, { prevPassword: oldPassword, newPassword: newPassword }) newPassword: newPassword, } ); console.log(status, data); } }