File size: 1,805 Bytes
38fa174
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from '../../environments/environment';
import { Observable } from 'rxjs';

export interface QAItem {
  label: string;
  input_type: 'text' | 'date' | 'select' | 'radio' | 'multiselect' | 'checkbox' | 'textarea' | 'number';
  options?: string[];
  column_key: string;
  category: string;
  required?: boolean;
  placeholder?: string;
}

export interface CategoryMeta {
  key: string;
  title: string;
}

@Injectable({ providedIn: 'root' })
export class QuestionAnswerService {
  private baseUrl: string;

  constructor(private http: HttpClient) {
    this.baseUrl = typeof location !== 'undefined' && location.hostname.endsWith('hf.space')
      ? 'https://pykara-py-match-backend.hf.space/api/questions'
      : 'http://127.0.0.1:5000/api/questions';
  }

  getQuestions(role: string): Observable<QAItem[]> {
    return this.http.get<QAItem[]>(`${this.baseUrl}/${role}`);
  }

  getCategories(role: string): Observable<CategoryMeta[]> {
    return this.http.get<CategoryMeta[]>(`${this.baseUrl}/categories/${role}`);
  }

  getExistingProfile(role: string, userId: number): Observable<any> {
    return this.http.get(`${this.baseUrl}/existing-profile/${role}/${userId}`);
  }

  submitAnswers(role: string, userId: number, fields: Record<string, any>): Observable<any> {
    const payload = { user_id: userId, ...fields };
    return this.http.post(`${this.baseUrl}/submit-answers/${role}`, payload);
  }

  updateAnswers(role: string, userId: number, fields: Record<string, any>): Observable<any> {
    const payload = { user_id: userId, ...fields };
    return this.http.put(`${this.baseUrl}/update-answers/${role}`, payload);
  }
}