1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2025-09-19 05:38:48 +00:00

Can create new Surveys

This commit is contained in:
2020-03-20 13:28:01 +01:00
parent 547d66e4dd
commit 167373c578
3 changed files with 80 additions and 0 deletions

View File

@@ -1,5 +1,7 @@
import { Survey, SurveyChoice } from "../entities/Survey";
import { DatabaseHelper } from "./DatabaseHelper";
import { NewSurvey } from "../entities/NewSurvey";
import { mysql_date } from "../utils/DateUtils";
/**
* Survey helper
@@ -27,6 +29,31 @@ const SURVEY_RESPONSE_TABLE = "sondage_reponse";
*/
export class SurveyHelper {
/**
* Create a new survey
*
* @param survey Information about the survey to create
*/
public static async Create(survey: NewSurvey) {
// Insert main row
const surveyID = await DatabaseHelper.InsertRow(SURVEY_INFO_TABLE, {
ID_utilisateurs: survey.userID,
ID_texte: survey.postID,
date_creation: mysql_date(),
question: survey.question
})
// Process choices
for(const choice of survey.choices) {
await DatabaseHelper.InsertRow(SURVEY_CHOICES_TABLE, {
ID_sondage: surveyID,
date_creation: mysql_date(),
Choix: choice
});
}
}
/**
* Get information about the survey of a post
*