Skip to content

Commit 9487784

Browse files
feat: add endpoint to get tg group by tag
1 parent f3557b8 commit 9487784

4 files changed

Lines changed: 24 additions & 3 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "backend",
3-
"version": "0.15.17",
3+
"version": "0.15.18",
44
"description": "PoliNetwork backend server",
55
"private": true,
66
"keywords": [],

package/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@polinetwork/backend",
3-
"version": "0.15.17",
3+
"version": "0.15.18",
44
"description": "Utils to interact with the backend.",
55
"repository": {
66
"type": "git",

src/routers/tg/groups.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { DB, SCHEMA } from "@/db"
44
import { logger } from "@/logger"
55
import { WSS } from "@/server"
66
import { createTRPCRouter, publicProcedure } from "@/trpc"
7+
import { lower } from "@/utils/db"
78

89
const GROUPS = SCHEMA.TG.groups
910
export default createTRPCRouter({
@@ -84,6 +85,22 @@ export default createTRPCRouter({
8485
return res[0]
8586
}),
8687

88+
getByTag: publicProcedure
89+
.input(
90+
z.object({
91+
tag: z.string(),
92+
})
93+
)
94+
.query(async ({ input }) => {
95+
const res = await DB.select()
96+
.from(GROUPS)
97+
.limit(1)
98+
.where((t) => eq(lower(t.tag), input.tag.toLowerCase().replace("@", "")))
99+
100+
if (res.length === 0) return null
101+
return res[0]
102+
}),
103+
87104
create: publicProcedure
88105
.input(
89106
z.array(

src/utils/db.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { type SQL, sql } from "drizzle-orm"
2-
import type { PgTableWithColumns, TableConfig } from "drizzle-orm/pg-core"
2+
import type { AnyPgColumn, PgTableWithColumns, TableConfig } from "drizzle-orm/pg-core"
33

44
type ColNames<TC extends TableConfig> = Readonly<(keyof TC["columns"])[]>
55
type SetSQL<TC extends TableConfig> = Partial<Record<ColNames<TC>[number], SQL<unknown>>>
@@ -13,3 +13,7 @@ export function upsertMultipleSetSql<TC extends TableConfig>(
1313
return acc
1414
}, {})
1515
}
16+
17+
export function lower(column: AnyPgColumn): SQL {
18+
return sql`lower(${column})`
19+
}

0 commit comments

Comments
 (0)