mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-21 21:09:22 +00:00
Can block creation of new choices in survey
This commit is contained in:
parent
c4a507e25c
commit
6e5f166b84
@ -280,6 +280,8 @@ export const Routes : Route[] = [
|
||||
|
||||
{path: "/surveys/cancel_response", cb: (h) => SurveyController.CancelResponse(h)},
|
||||
|
||||
{path: "/survey/block_new_choices_creation", cb: (h) => SurveyController.BlockNewChoicesCreation(h)},
|
||||
|
||||
|
||||
// Notifications controller
|
||||
{path: "/notifications/count_unread", cb: (h) => NotificationsController.CountUnread(h)},
|
||||
|
@ -2,6 +2,7 @@ import { Survey, SurveyChoice } from "../entities/Survey";
|
||||
import { RequestHandler } from "../entities/RequestHandler";
|
||||
import { SurveyHelper } from "../helpers/SurveyHelper";
|
||||
import { SurveyResponse } from "../entities/SurveyResponse";
|
||||
import { PostAccessLevel } from "../entities/Post";
|
||||
|
||||
/**
|
||||
* Survey controller
|
||||
@ -43,6 +44,19 @@ export class SurveyController {
|
||||
h.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* Block the creation of new survey choices
|
||||
*
|
||||
* @param h Request handler
|
||||
*/
|
||||
public static async BlockNewChoicesCreation(h: RequestHandler) {
|
||||
const surveyID = await this.PostSurveyIDFromPostID(h, "postID", PostAccessLevel.FULL_ACCESS);
|
||||
|
||||
await SurveyHelper.BlockNewChoicesCreation(surveyID);
|
||||
|
||||
h.success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Turn a survey into an API entry
|
||||
@ -76,9 +90,11 @@ export class SurveyController {
|
||||
* @param h Request handler
|
||||
* @param field The name of the POST field containing the
|
||||
* POST id
|
||||
* @param minLevel Minimal access level to the post
|
||||
*/
|
||||
private static async PostSurveyIDFromPostID(h: RequestHandler, field: string) : Promise<number> {
|
||||
const postID = await h.postPostIDWithAccess(field);
|
||||
private static async PostSurveyIDFromPostID(h: RequestHandler, field: string,
|
||||
minLevel?: PostAccessLevel) : Promise<number> {
|
||||
const postID = await h.postPostIDWithAccess(field, minLevel);
|
||||
return await SurveyHelper.GetID(postID);
|
||||
}
|
||||
|
||||
|
@ -135,6 +135,23 @@ export class SurveyHelper {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Block new survey choices from being created
|
||||
*
|
||||
* @param surveyID Target survey ID
|
||||
*/
|
||||
public static async BlockNewChoicesCreation(surveyID: number) {
|
||||
await DatabaseHelper.UpdateRows({
|
||||
table: SURVEY_INFO_TABLE,
|
||||
where: {
|
||||
"ID": surveyID
|
||||
},
|
||||
set: {
|
||||
allow_new_choices: 0
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the survey associated to a post
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user