| 143 | } |
| 144 | |
| 145 | export async function getGroupListCount({ |
| 146 | projectId, |
| 147 | type, |
| 148 | search, |
| 149 | }: { |
| 150 | projectId: string; |
| 151 | type?: string; |
| 152 | search?: string; |
| 153 | }): Promise<number> { |
| 154 | const conditions = [ |
| 155 | `project_id = ${sqlstring.escape(projectId)}`, |
| 156 | 'deleted = 0', |
| 157 | ...(type ? [`type = ${sqlstring.escape(type)}`] : []), |
| 158 | ...(search |
| 159 | ? [ |
| 160 | `(name ILIKE ${sqlstring.escape(`%${search}%`)} OR id ILIKE ${sqlstring.escape(`%${search}%`)})`, |
| 161 | ] |
| 162 | : []), |
| 163 | ]; |
| 164 | |
| 165 | const rows = await chQuery<{ count: number }>(` |
| 166 | SELECT count() as count |
| 167 | FROM ${TABLE_NAMES.groups} FINAL |
| 168 | WHERE ${conditions.join(' AND ')} |
| 169 | `); |
| 170 | return rows[0]?.count ?? 0; |
| 171 | } |
| 172 | |
| 173 | export async function getGroupTypes(projectId: string): Promise<string[]> { |
| 174 | const rows = await chQuery<{ type: string }>(` |