mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-06-20 08:35:17 +00:00
Can create new Surveys
This commit is contained in:
@ -17,6 +17,7 @@ import { check_string_before_insert, check_youtube_id, checkURL } from "../utils
|
||||
import { pathUserData } from "../utils/UserDataUtils";
|
||||
import { statSync } from "fs";
|
||||
import { lookup } from "mime-types";
|
||||
import { NewSurvey } from "../entities/NewSurvey";
|
||||
|
||||
/**
|
||||
* Posts controller
|
||||
@ -108,6 +109,9 @@ export class PostsController {
|
||||
// Determine the target for the new post
|
||||
let kindPage: PostPageKind;
|
||||
let pageID: number;
|
||||
|
||||
let survey : NewSurvey | undefined = undefined;
|
||||
|
||||
switch(h.postString("kind-page")) {
|
||||
|
||||
// If the post is targetting a user
|
||||
@ -255,6 +259,22 @@ export class PostsController {
|
||||
newPost.timeEnd = h.postInt("time-end");
|
||||
break;
|
||||
|
||||
|
||||
// Survey controller
|
||||
case PostKind.POST_KIND_SURVEY:
|
||||
|
||||
// Create the survey
|
||||
survey = new NewSurvey({
|
||||
question: h.postString("question"),
|
||||
userID: h.getUserId(),
|
||||
choices: h.postString("answers").split("<>")
|
||||
})
|
||||
|
||||
if(survey.choices.length < 2)
|
||||
h.error(401, "Survey must have at least two answers!");
|
||||
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
h.error(500, "Unsupported kind of post!");
|
||||
@ -263,6 +283,13 @@ export class PostsController {
|
||||
// Create the post
|
||||
const postID = await PostsHelper.Create(newPost);
|
||||
|
||||
// Create associated survey (if any)
|
||||
if(survey != undefined) {
|
||||
survey.postID = postID;
|
||||
SurveyHelper.Create(survey);
|
||||
}
|
||||
|
||||
|
||||
// TODO : create a notification
|
||||
|
||||
h.send({
|
||||
|
Reference in New Issue
Block a user