Skip to content

Commit 5844d3f

Browse files
feat(audit): add join with groups table
1 parent b7699bb commit 5844d3f

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

backend/src/routers/tg/audit-log.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ export default createTRPCRouter({
1717
}),
1818
)
1919
.mutation(async ({ input }) => {
20-
await DB.insert(SCHEMA.TG.auditLog)
21-
.values(input)
22-
.onConflictDoNothing();
20+
await DB.insert(SCHEMA.TG.auditLog).values(input).onConflictDoNothing();
2321
}),
2422

2523
getById: publicProcedure
@@ -29,8 +27,14 @@ export default createTRPCRouter({
2927
}),
3028
)
3129
.query(async ({ input }) => {
32-
return await DB.select()
30+
const res = await DB.select()
3331
.from(SCHEMA.TG.auditLog)
34-
.where((t) => eq(t.targetId, input.targetId));
32+
.where((t) => eq(t.targetId, input.targetId))
33+
.leftJoin(
34+
SCHEMA.TG.groups,
35+
eq(SCHEMA.TG.auditLog.groupId, SCHEMA.TG.groups.telegramId),
36+
);
37+
38+
return res.map((e) => ({ ...e.audit_log, groupTitle: e.groups?.title }));
3539
}),
3640
});

0 commit comments

Comments
 (0)