From d4bfaaa52c1e1385a4f7339303651afcb95685fe Mon Sep 17 00:00:00 2001 From: Claus-Peter Huebner Date: Tue, 4 Jul 2023 14:48:51 +0200 Subject: [PATCH] rework PR-comment --- backend/src/graphql/model/User.ts | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/backend/src/graphql/model/User.ts b/backend/src/graphql/model/User.ts index 0a4993d28..551567a13 100644 --- a/backend/src/graphql/model/User.ts +++ b/backend/src/graphql/model/User.ts @@ -77,26 +77,20 @@ export class User { @Field(() => [String], { nullable: true }) roles: string[] | null -} -export function isAdmin(user: User): boolean { - if (user.roles) { - for (const role of user.roles) { - if (role === ROLE_NAMES.ROLE_NAME_ADMIN) { - return true - } + @Field(() => Boolean) + isAdmin(): boolean { + if (this.roles) { + return this.roles.includes(ROLE_NAMES.ROLE_NAME_ADMIN) } + return false } - return false -} -export function isModerator(user: User): boolean { - if (user.roles) { - for (const role of user.roles) { - if (role === ROLE_NAMES.ROLE_NAME_MODERATOR) { - return true - } + @Field(() => Boolean) + isModerator(): boolean { + if (this.roles) { + return this.roles.includes(ROLE_NAMES.ROLE_NAME_MODERATOR) } + return false } - return false }