1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2025-06-20 08:35: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

@ -9,6 +9,7 @@ import { UserController } from "./UserController";
import { PostsController } from "./PostsController";
import { CommentsController } from "./CommentsController";
import { LikesController } from "./LikesController";
import { SurveyController } from "./SurveyController";
/**
* Account controller
@ -240,7 +241,10 @@ export class AccountController {
comments: await CommentsController.CommentsToAPI(h, data.comments),
// User likes
likes: data.likes.map(LikesController.UserLikeToAPI)
likes: data.likes.map(LikesController.UserLikeToAPI),
// Responses to surveys
survey_responses: data.surveyResponses.map(SurveyController.SurveyResponseToAPI)
};

View File

@ -1,6 +1,7 @@
import { Survey, SurveyChoice } from "../entities/Survey";
import { RequestHandler } from "../entities/RequestHandler";
import { SurveyHelper } from "../helpers/SurveyHelper";
import { SurveyResponse } from "../entities/SurveyResponse";
/**
* Survey controller
@ -92,4 +93,19 @@ export class SurveyController {
responses: c.count
}
}
/**
* Turn a {SurveyResponse} object into an API entry
*
* @param r The survey response
*/
public static SurveyResponseToAPI(r: SurveyResponse) : any {
return {
id: r.id,
time_sent: r.timeSent,
userID: r.userID,
surveyID: r.surveyID,
choiceID: r.choiceID
}
}
}