|
|
|
@ -16,6 +16,7 @@ import NocoCache from '~/cache/NocoCache';
|
|
|
|
|
import { CacheGetType, CacheScope } from '~/utils/globals'; |
|
|
|
|
import { convertDateFormatForConcat } from '~/helpers/formulaFnHelper'; |
|
|
|
|
import FormulaColumn from '~/models/FormulaColumn'; |
|
|
|
|
import { Base, BaseUser } from '~/models'; |
|
|
|
|
|
|
|
|
|
// todo: switch function based on database
|
|
|
|
|
|
|
|
|
@ -637,6 +638,32 @@ async function _formulaQueryBuilder(
|
|
|
|
|
Promise.resolve({ builder: col.column_name }); |
|
|
|
|
} |
|
|
|
|
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(`??`, [col.column_name]).toQuery()); |
|
|
|
|
|
|
|
|
|
aliasToColumn[col.id] = async (): Promise<any> => { |
|
|
|
|
return { |
|
|
|
|
builder: knex.raw(finalStatement).wrap('(', ')'), |
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
aliasToColumn[col.id] = () => |
|
|
|
|
Promise.resolve({ builder: col.column_name }); |
|
|
|
|