Browse Source

feat: sort by user field

pull/7202/head
mertmit 12 months ago
parent
commit
ac284aa65e
  1. 28
      packages/nocodb/src/db/sortV2.ts

28
packages/nocodb/src/db/sortV2.ts

@ -6,7 +6,7 @@ import { NcError } from '~/helpers/catchError';
import formulaQueryBuilderv2 from '~/db/formulav2/formulaQueryBuilderv2'; import formulaQueryBuilderv2 from '~/db/formulav2/formulaQueryBuilderv2';
import genRollupSelectv2 from '~/db/genRollupSelectv2'; import genRollupSelectv2 from '~/db/genRollupSelectv2';
import { sanitize } from '~/helpers/sqlSanitize'; import { sanitize } from '~/helpers/sqlSanitize';
import { Sort } from '~/models'; import { Base, BaseUser, Sort } from '~/models';
import generateLookupSelectQuery from '~/db/generateLookupSelectQuery'; import generateLookupSelectQuery from '~/db/generateLookupSelectQuery';
export default async function sortV2( export default async function sortV2(
@ -138,6 +138,32 @@ export default async function sortV2(
} }
break; break;
} }
case UITypes.User: {
const base = await Base.get(model.base_id);
const baseUsers = await BaseUser.getUsersList({
base_id: base.id,
...((base as any)?.fk_workspace_id
? { workspace_id: (base as any).fk_workspace_id }
: {}),
});
// create nested replace statement for each user
const finalStatement = baseUsers.reduce((acc, user) => {
const qb = knex.raw(`REPLACE(${acc}, ?, ?)`, [
user.id,
user.display_name || user.email,
]);
return qb.toQuery();
}, knex.raw(`??`, [column.column_name]).toQuery());
qb.orderBy(
sanitize(knex.raw(finalStatement)),
sort.direction || 'asc',
nulls,
);
break;
}
default: default:
qb.orderBy( qb.orderBy(
sanitize(column.column_name), sanitize(column.column_name),

Loading…
Cancel
Save