1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2025-06-20 00:25:17 +00:00

Can respond to survey

This commit is contained in:
2020-03-21 16:34:20 +01:00
parent 75c49ee136
commit 0e3bbd2125
3 changed files with 82 additions and 1 deletions

View File

@ -73,7 +73,7 @@ export class SurveyHelper {
*
* @param postID Target post ID
*/
private static async GetID(postID: number) : Promise<number> {
public static async GetID(postID: number) : Promise<number> {
const info = await DatabaseHelper.QueryRow({
table: SURVEY_INFO_TABLE,
where: {
@ -88,6 +88,51 @@ export class SurveyHelper {
return info.ID;
}
/**
* Cancel the response of a user to a survey
*
* @param userID Target user ID
* @param surveyID Target survey
*/
public static async CancelResponse(userID: number, surveyID: number) {
await DatabaseHelper.DeleteRows(SURVEY_RESPONSE_TABLE, {
ID_sondage: surveyID,
ID_utilisateurs: userID
});
}
/**
* Check out whether a choice for the survey exists or not
*
* @param surveyID Target survey ID
* @param choiceID Target choice ID
*/
public static async ChoiceExists(surveyID: number, choiceID: number) : Promise<boolean> {
return await DatabaseHelper.Count({
table: SURVEY_CHOICES_TABLE,
where: {
ID_sondage: surveyID,
ID: choiceID
}
}) > 0;
}
/**
* Save user response to a survey
*
* @param userID Target user
* @param surveyID Target survey
* @param choiceID Selected choice
*/
public static async SendResponse(userID: number, surveyID: number, choiceID: number) {
await DatabaseHelper.InsertRow(SURVEY_RESPONSE_TABLE, {
ID_utilisateurs: userID,
ID_sondage: surveyID,
ID_sondage_choix: choiceID,
date_envoi: mysql_date()
});
}
/**
* Delete the survey associated to a post
*