Skip to content

Commit 3695d03

Browse files
committed
apply better survey type value
1 parent 858dd11 commit 3695d03

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

gateway/src/modules/public/services/surveys.service.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const sanitizeSurveySnapshot = (survey: SurveyDoc) => ({
8686
'name': survey.name,
8787
'description': survey.description || '',
8888
'questions': survey.questions,
89-
'type': 'survey'
89+
'type': survey.type
9090
});
9191

9292
const sanitizeTeam = (team: TeamDoc) => ({
@@ -183,6 +183,13 @@ export const createPublicSurveySubmission = async (req: Request, res: Response)
183183
});
184184
}
185185

186+
if (!answers.every((answer) => isValidAnswer(answer))) {
187+
return res.status(400).json({
188+
'error': 'Bad Request',
189+
'message': 'answers must include a response for each survey question'
190+
});
191+
}
192+
186193
const submission = buildPublicSubmission(survey, team, payload, configuration);
187194
const response = await submissionsDB.insert(submission as any);
188195

src/app/surveys/surveys.component.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
</button>
7676
</div>
7777
<div [matTooltip]="getActionTooltip(element, 'send')">
78-
<button mat-raised-button color="primary" *ngIf="!teamId && !routeTeamId" [matMenuTriggerFor]="sendMenu" [disabled]="!element.questions.length || element.isArchived || (element.teamId && isManagerRoute)">
78+
<button mat-raised-button color="primary" *ngIf="!teamId && !routeTeamId" [matMenuTriggerFor]="sendMenu" [disabled]="!element.questions?.length || element.isArchived || (element.teamId && isManagerRoute)">
7979
<mat-icon>send</mat-icon>
8080
<label *ngIf="!isMobile" i18n> Send</label>
8181
</button>
@@ -85,13 +85,13 @@
8585
<button mat-menu-item style="width: 100%;" (click)="openSendSurveyToTeamsDialog(element)" [disabled]="!element.teamShareAllowed" i18n>Team</button>
8686
</mat-menu>
8787
<div [matTooltip]="getActionTooltip(element, 'record')">
88-
<button mat-raised-button color="primary" (click)="recordSurvey(element)" [disabled]="!element.questions.length || element.isArchived || (element.teamId && isManagerRoute)">
88+
<button mat-raised-button color="primary" (click)="recordSurvey(element)" [disabled]="!element.questions?.length || element.isArchived || (element.teamId && isManagerRoute)">
8989
<mat-icon>fiber_manual_record</mat-icon>
9090
<label *ngIf="!isMobile" i18n> Record</label>
9191
</button>
9292
</div>
9393
<div *ngIf="element.teamId && (teamId || routeTeamId)" [matTooltip]="getActionTooltip(element, 'public')">
94-
<button mat-raised-button color="accent" (click)="element.publicAccess === true ? copyPublicSurveyLink(element) : toggleSurveyPublicAccess(element)" [disabled]="!element.questions.length || element.isArchived">
94+
<button mat-raised-button color="accent" (click)="element.publicAccess === true ? copyPublicSurveyLink(element) : toggleSurveyPublicAccess(element)" [disabled]="!element.questions?.length || element.isArchived">
9595
<mat-icon>{{ element.publicAccess === true ? 'link' : 'public' }}</mat-icon>
9696
<label *ngIf="!isMobile" i18n>{{ element.publicAccess === true ? 'Copy Public Link' : 'Generate Public Link' }}</label>
9797
</button>
@@ -111,7 +111,7 @@
111111
</div>
112112
</ng-container>
113113
<div [matTooltip]="getActionTooltip(element, 'submissions')">
114-
<button mat-raised-button color="primary" *ngIf="!teamId && !routeTeamId" (click)="viewSurveySubmissions(element)" [disabled]="!element.questions.length || !element.taken">
114+
<button mat-raised-button color="primary" *ngIf="!teamId && !routeTeamId" (click)="viewSurveySubmissions(element)" [disabled]="!element.questions?.length || !element.taken">
115115
<mat-icon>insert_drive_file</mat-icon>
116116
<label *ngIf="!isMobile" i18n> Submissions</label>
117117
</button>

0 commit comments

Comments
 (0)