|
|
|
@ -2343,6 +2343,7 @@ class BaseModelSqlv2 {
|
|
|
|
|
value: Record<string, unknown>[]; |
|
|
|
|
}[] |
|
|
|
|
> { |
|
|
|
|
try { |
|
|
|
|
const column = await this.model |
|
|
|
|
.getColumns() |
|
|
|
|
.then((cols) => cols?.find((col) => col.id === args.groupColumnId)); |
|
|
|
@ -2354,8 +2355,10 @@ class BaseModelSqlv2 {
|
|
|
|
|
// extract distinct group column values
|
|
|
|
|
let groupingValues; |
|
|
|
|
if (column.uidt === UITypes.SingleSelect) { |
|
|
|
|
const colOptions = await column.getColOptions<SelectOption[]>(); |
|
|
|
|
groupingValues = colOptions?.map((opt) => opt.title); |
|
|
|
|
const colOptions = await column.getColOptions< |
|
|
|
|
SelectOption[] & { options } |
|
|
|
|
>(); |
|
|
|
|
groupingValues = colOptions.options.map((opt) => opt.title); |
|
|
|
|
} else { |
|
|
|
|
groupingValues = ( |
|
|
|
|
await this.dbDriver(this.model.table_name) |
|
|
|
@ -2432,7 +2435,9 @@ class BaseModelSqlv2 {
|
|
|
|
|
// if autogenerated string sort by created_at column if present
|
|
|
|
|
if (this.model.primaryKey && this.model.primaryKey.ai) { |
|
|
|
|
qb.orderBy(this.model.primaryKey.column_name); |
|
|
|
|
} else if (this.model.columns.find((c) => c.column_name === 'created_at')) { |
|
|
|
|
} else if ( |
|
|
|
|
this.model.columns.find((c) => c.column_name === 'created_at') |
|
|
|
|
) { |
|
|
|
|
qb.orderBy('created_at'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -2448,7 +2453,9 @@ class BaseModelSqlv2 {
|
|
|
|
|
...groupingValues.map((r) => { |
|
|
|
|
const query = qb.clone().where(column.title, r); |
|
|
|
|
|
|
|
|
|
return this.isSqlite ? this.dbDriver.select().from(query) : query; |
|
|
|
|
return this.isSqlite |
|
|
|
|
? this.dbDriver.select().from(query) |
|
|
|
|
: query; |
|
|
|
|
}), |
|
|
|
|
], |
|
|
|
|
!this.isSqlite |
|
|
|
@ -2464,10 +2471,8 @@ class BaseModelSqlv2 {
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// todo: handle null values
|
|
|
|
|
const groupedResult: Record<string, Record<string, unknown>[]> = _.groupBy( |
|
|
|
|
result, |
|
|
|
|
column.title |
|
|
|
|
); |
|
|
|
|
const groupedResult: Record<string, Record<string, unknown>[]> = |
|
|
|
|
_.groupBy(result, column.title); |
|
|
|
|
|
|
|
|
|
const r = Object.entries(groupedResult).map(([key, value]) => ({ |
|
|
|
|
key, |
|
|
|
@ -2475,9 +2480,15 @@ class BaseModelSqlv2 {
|
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
return r; |
|
|
|
|
} catch (e) { |
|
|
|
|
console.log(e); |
|
|
|
|
throw e; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public async groupedListCount(args: { groupColumnId: string ; ignoreFilterSort?:boolean} & XcFilter) { |
|
|
|
|
public async groupedListCount( |
|
|
|
|
args: { groupColumnId: string; ignoreFilterSort?: boolean } & XcFilter |
|
|
|
|
) { |
|
|
|
|
const column = await this.model |
|
|
|
|
.getColumns() |
|
|
|
|
.then((cols) => cols?.find((col) => col.id === args.groupColumnId)); |
|
|
|
@ -2536,7 +2547,6 @@ class BaseModelSqlv2 {
|
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await this.selectObject({ |
|
|
|
|
qb, |
|
|
|
|
columns: [new Column({ ...column, title: 'key' })], |
|
|
|
|