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:
@ -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)
|
||||
})
|
||||
|
||||
|
||||
|
@ -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
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user