Commit 458f4e46 authored by Lorenzo Trujillo Rojas's avatar Lorenzo Trujillo Rojas
Browse files

Se implementó el metodo para obtener los intereses del usuario en el datasource de produccion

parent 78ed4316
Loading
Loading
Loading
Loading
+55 −15
Original line number Diff line number Diff line
@@ -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);
  }
}