1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-12-28 14:38:52 +00:00

Fix incorrect request

This commit is contained in:
Pierre HUBERT 2020-03-20 13:36:30 +01:00
parent 167373c578
commit e8233bc24c
2 changed files with 13 additions and 2 deletions

View File

@ -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
});

View File

@ -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)));