mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-26 07:19:23 +00:00
Return the choice of a user to a survey
This commit is contained in:
parent
24d3102d49
commit
03459cd3a0
@ -1,5 +1,6 @@
|
|||||||
import { Survey, SurveyChoice } from "../entities/Survey";
|
import { Survey, SurveyChoice } from "../entities/Survey";
|
||||||
import { RequestHandler } from "../entities/RequestHandler";
|
import { RequestHandler } from "../entities/RequestHandler";
|
||||||
|
import { SurveyHelper } from "../helpers/SurveyHelper";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Survey controller
|
* Survey controller
|
||||||
@ -29,6 +30,9 @@ export class SurveyController {
|
|||||||
|
|
||||||
survey.choices.forEach((c) => data.choices[c.id.toString()] = this.SurveyChoiceToAPI(c))
|
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;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,6 +71,24 @@ export class SurveyHelper {
|
|||||||
return survey;
|
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
|
* Turn a database entry into a survey object
|
||||||
|
Loading…
Reference in New Issue
Block a user