mirror of
				https://gitlab.com/comunic/comunicapiv2
				synced 2025-10-30 17:14:43 +00:00 
			
		
		
		
	Return the choice of a user to a survey
This commit is contained in:
		| @@ -1,5 +1,6 @@ | ||||
| import { Survey, SurveyChoice } from "../entities/Survey"; | ||||
| import { RequestHandler } from "../entities/RequestHandler"; | ||||
| import { SurveyHelper } from "../helpers/SurveyHelper"; | ||||
|  | ||||
| /** | ||||
|  * Survey controller | ||||
| @@ -29,6 +30,9 @@ export class SurveyController { | ||||
|  | ||||
| 		survey.choices.forEach((c) => data.choices[c.id.toString()] = this.SurveyChoiceToAPI(c)) | ||||
|  | ||||
| 		if(h.signedIn) | ||||
| 			data.user_choice = await SurveyHelper.GetUserChoice(survey.id, h.getUserId()); | ||||
|  | ||||
| 		return data; | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -71,6 +71,24 @@ export class SurveyHelper { | ||||
| 		return survey; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Get the choice of a user for a survey | ||||
| 	 *  | ||||
| 	 * @param surveyID Target survey | ||||
| 	 * @param userID Target user | ||||
| 	 */ | ||||
| 	public static async GetUserChoice(surveyID: number, userID: number) { | ||||
| 		const result = await DatabaseHelper.QueryRow({ | ||||
| 			table: SURVEY_RESPONSE_TABLE, | ||||
| 			where: { | ||||
| 				ID_utilisateurs: userID, | ||||
| 				ID_sondage: surveyID | ||||
| 			} | ||||
| 		}); | ||||
|  | ||||
| 		return result == null ? 0 /* no response yet */ : result.ID_sondage_choix; | ||||
| 	} | ||||
|  | ||||
|  | ||||
| 	/** | ||||
| 	 * Turn a database entry into a survey object | ||||
|   | ||||
		Reference in New Issue
	
	Block a user