Skip to content

Commit 52bfce5

Browse files
feat: not role is now null instead of 'user'
1 parent e0a0857 commit 52bfce5

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

backend/src/routers/tg/permissions.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,27 @@ const CAN_ASSIGN: TUserRole[] = [USER_ROLE.PRESIDENT, USER_ROLE.OWNER, USER_ROLE
1212
const CAN_ADD_BOT: TUserRole[] = [USER_ROLE.HR, USER_ROLE.OWNER, USER_ROLE.CREATOR, USER_ROLE.DIRETTIVO]
1313

1414
export default createTRPCRouter({
15-
getRoles: publicProcedure.input(z.object({ userId: z.number() })).query(async ({ input }) => {
16-
const [res] = await DB.select({
17-
roles: s.permissions.roles,
18-
})
19-
.from(s.permissions)
20-
.where(eq(s.permissions.userId, input.userId))
21-
.limit(1)
22-
23-
return {
24-
userId: input.userId,
25-
roles: res ? res.roles : ["user"],
26-
}
27-
}),
15+
getRoles: publicProcedure
16+
.input(z.object({ userId: z.number() }))
17+
.output(
18+
z.object({
19+
userId: z.number(),
20+
roles: z.union([z.array(z.string<TUserRole>()), z.null()]),
21+
})
22+
)
23+
.query(async ({ input }) => {
24+
const [res] = await DB.select({
25+
roles: s.permissions.roles,
26+
})
27+
.from(s.permissions)
28+
.where(eq(s.permissions.userId, input.userId))
29+
.limit(1)
30+
31+
return {
32+
userId: input.userId,
33+
roles: res ? res.roles : null,
34+
}
35+
}),
2836

2937
getDirettivo: publicProcedure
3038
.output(

0 commit comments

Comments
 (0)