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

Export all responses of user to surveys

This commit is contained in:
2020-03-26 12:11:06 +01:00
parent 1626b49c37
commit 7e9e35765e
6 changed files with 86 additions and 1 deletions

View File

@ -10,6 +10,7 @@ import { AccountExport } from "../entities/AccountExport";
import { PostsHelper } from "./PostsHelper";
import { CommentsHelper } from "./CommentsHelper";
import { LikesHelper } from "./LikesHelper";
import { SurveyHelper } from "./SurveyHelper";
/**
* Account helper
@ -398,6 +399,9 @@ export class AccountHelper {
// Export user likes
likes: await LikesHelper.ExportAllUser(userID),
// Export all responses of user to surveys
surveyResponses: await SurveyHelper.ExportAllUserResponses(userID)
})

View File

@ -2,6 +2,7 @@ import { Survey, SurveyChoice } from "../entities/Survey";
import { DatabaseHelper, JoinType } from "./DatabaseHelper";
import { NewSurvey } from "../entities/NewSurvey";
import { mysql_date } from "../utils/DateUtils";
import { SurveyResponse } from "../entities/SurveyResponse";
/**
* Survey helper
@ -217,6 +218,20 @@ export class SurveyHelper {
return result == null ? 0 /* no response yet */ : result.ID_sondage_choix;
}
/**
* Export all the responses to surveys of a user
*
* @param userID The ID of the target user
*/
public static async ExportAllUserResponses(userID: number) : Promise<SurveyResponse[]> {
return (await DatabaseHelper.Query({
table: SURVEY_RESPONSE_TABLE,
where: {
ID_utilisateurs: userID
}
})).map(this.DBTosurveyResponse)
}
/**
* Turn a database entry into a survey object
@ -246,4 +261,19 @@ export class SurveyHelper {
count: row.count_choice
};
}
/**
* Turn a database entry into a survey response object
*
* @param row The row
*/
private static DBTosurveyResponse(row: any) : SurveyResponse {
return new SurveyResponse({
id: row.ID,
timeSent: new Date(row.date_envoi).getTime()/1000,
userID: row.ID_utilisateurs,
surveyID: row.ID_sondage,
choiceID: row.ID_sondage_choix
});
}
}