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