py-match / src /app /question-answer /question-answer-service.service.ts
pykara's picture
Upload 5840 files
38fa174 verified
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);
}
}