feat(api): Add permissions to every route and permission config

This commit is contained in:
Jesse Wierzbinski 2024-06-07 18:57:29 -10:00
parent 19823d8eca
commit 4902f078a8
No known key found for this signature in database
79 changed files with 729 additions and 251 deletions

View file

@ -8,6 +8,7 @@ import {
Instances,
Notifications,
Relationships,
type Roles,
Tokens,
Users,
} from "~/drizzle/schema";
@ -31,6 +32,7 @@ export type UserWithRelations = UserType & {
followerCount: number;
followingCount: number;
statusCount: number;
roles: InferSelectModel<typeof Roles>[];
};
export const userRelations: {
@ -44,6 +46,11 @@ export const userRelations: {
};
};
};
roles: {
with: {
role: true;
};
};
} = {
instance: true,
emojis: {
@ -55,6 +62,11 @@ export const userRelations: {
},
},
},
roles: {
with: {
role: true,
},
},
};
export const userExtras = {
@ -242,6 +254,11 @@ export const transformOutputToUserWithRelations = (
emoji?: EmojiWithInstance;
}[];
instance: InferSelectModel<typeof Instances> | null;
roles: {
userId: string;
roleId: string;
role?: InferSelectModel<typeof Roles>;
}[];
endpoints: unknown;
},
): UserWithRelations => {
@ -266,6 +283,9 @@ export const transformOutputToUserWithRelations = (
(emoji as unknown as Record<string, object>)
.emoji as EmojiWithInstance,
),
roles: user.roles
.map((role) => role.role)
.filter(Boolean) as InferSelectModel<typeof Roles>[],
};
};