({
projectId,
cursor,
take,
search,
type,
}: {
projectId: string;
cursor?: number;
take: number;
search?: string;
type?: string;
})
| 108 | } |
| 109 | |
| 110 | export async function getGroupList({ |
| 111 | projectId, |
| 112 | cursor, |
| 113 | take, |
| 114 | search, |
| 115 | type, |
| 116 | }: { |
| 117 | projectId: string; |
| 118 | cursor?: number; |
| 119 | take: number; |
| 120 | search?: string; |
| 121 | type?: string; |
| 122 | }): Promise<IServiceGroup[]> { |
| 123 | const conditions = [ |
| 124 | `project_id = ${sqlstring.escape(projectId)}`, |
| 125 | 'deleted = 0', |
| 126 | ...(type ? [`type = ${sqlstring.escape(type)}`] : []), |
| 127 | ...(search |
| 128 | ? [ |
| 129 | `(name ILIKE ${sqlstring.escape(`%${search}%`)} OR id ILIKE ${sqlstring.escape(`%${search}%`)})`, |
| 130 | ] |
| 131 | : []), |
| 132 | ]; |
| 133 | |
| 134 | const rows = await chQuery<IClickhouseGroup>(` |
| 135 | SELECT project_id, id, type, name, properties, created_at, version |
| 136 | FROM ${TABLE_NAMES.groups} FINAL |
| 137 | WHERE ${conditions.join(' AND ')} |
| 138 | ORDER BY created_at DESC |
| 139 | LIMIT ${take} |
| 140 | OFFSET ${Math.max(0, (cursor ?? 0) * take)} |
| 141 | `); |
| 142 | return rows.map(transformGroup); |
| 143 | } |
| 144 | |
| 145 | export async function getGroupListCount({ |
| 146 | projectId, |
no test coverage detected