mirror of
				https://gitlab.com/comunic/comunicapiv2
				synced 2025-10-30 17:14:43 +00:00 
			
		
		
		
	Fix incorrect request
This commit is contained in:
		| @@ -7,6 +7,11 @@ import { conf } from "./ConfigHelper"; | ||||
|  * @author Pierre HUBERT | ||||
|  */ | ||||
|  | ||||
| export enum JoinType { | ||||
| 	NORMAL, | ||||
| 	LEFT | ||||
| } | ||||
|  | ||||
| export interface JoinTableInfo { | ||||
| 	table: string, | ||||
| 	tableAlias ?: string, | ||||
| @@ -16,6 +21,7 @@ export interface JoinTableInfo { | ||||
| export interface QueryInformation { | ||||
| 	table: string, | ||||
| 	tableAlias?: string, | ||||
| 	joinType ?: JoinType, | ||||
| 	joins ?: Array<JoinTableInfo>, | ||||
| 	fields ?: Array<string>, | ||||
| 	where ?: Object, | ||||
| @@ -98,6 +104,10 @@ export class DatabaseHelper { | ||||
|  | ||||
| 		// Joins condition | ||||
| 		if(info.joins) { | ||||
|  | ||||
| 			if(info.joinType == JoinType.LEFT) | ||||
| 				request += " LEFT "; | ||||
|  | ||||
| 			info.joins.forEach(join => { | ||||
| 				request += " JOIN " + join.table + (join.tableAlias ? " " + join.tableAlias : "") + " ON " + join.condition | ||||
| 			}); | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| import { Survey, SurveyChoice } from "../entities/Survey"; | ||||
| import { DatabaseHelper } from "./DatabaseHelper"; | ||||
| import { DatabaseHelper, JoinType } from "./DatabaseHelper"; | ||||
| import { NewSurvey } from "../entities/NewSurvey"; | ||||
| import { mysql_date } from "../utils/DateUtils"; | ||||
|  | ||||
| @@ -79,6 +79,7 @@ export class SurveyHelper { | ||||
| 		const choices = await DatabaseHelper.Query({ | ||||
| 			table: SURVEY_CHOICES_TABLE, | ||||
| 			tableAlias: "c", | ||||
| 			joinType: JoinType.LEFT, | ||||
| 			joins: [ | ||||
| 				{ | ||||
| 					table: SURVEY_RESPONSE_TABLE, | ||||
| @@ -90,7 +91,7 @@ export class SurveyHelper { | ||||
| 				"c.ID_sondage": survey.id | ||||
| 			}, | ||||
| 			groupBy: "c.ID", | ||||
| 			fields: ["c.*", "COUNT(*) AS count_choice"] | ||||
| 			fields: ["c.*", "COUNT(r.ID) AS count_choice"] | ||||
| 		}); | ||||
|  | ||||
| 		choices.forEach((row) => survey.choices.push(this.DBToSurveyChoice(row))); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user