mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 01:46:07 +00:00
add graphql handling and adjust entity
This commit is contained in:
parent
5adc84bc84
commit
eb3ce6e9cf
@ -8,4 +8,5 @@ export const ADMIN_RIGHTS = [
|
||||
RIGHTS.COMMUNITY_BY_UUID,
|
||||
RIGHTS.COMMUNITY_BY_IDENTIFIER,
|
||||
RIGHTS.HOME_COMMUNITY,
|
||||
RIGHTS.PROJECT_BRANDING_MUTATE,
|
||||
]
|
||||
|
||||
@ -9,4 +9,5 @@ export const INALIENABLE_RIGHTS = [
|
||||
RIGHTS.QUERY_TRANSACTION_LINK,
|
||||
RIGHTS.QUERY_OPT_IN,
|
||||
RIGHTS.CHECK_USERNAME,
|
||||
RIGHTS.PROJECT_BRANDING_BANNER,
|
||||
]
|
||||
|
||||
@ -8,6 +8,7 @@ export enum RIGHTS {
|
||||
QUERY_TRANSACTION_LINK = 'QUERY_TRANSACTION_LINK',
|
||||
QUERY_OPT_IN = 'QUERY_OPT_IN',
|
||||
CHECK_USERNAME = 'CHECK_USERNAME',
|
||||
PROJECT_BRANDING_BANNER = 'PROJECT_BRANDING_BANNER',
|
||||
// User
|
||||
VERIFY_LOGIN = 'VERIFY_LOGIN',
|
||||
BALANCE = 'BALANCE',
|
||||
@ -39,6 +40,7 @@ export enum RIGHTS {
|
||||
USER = 'USER',
|
||||
GMS_USER_PLAYGROUND = 'GMS_USER_PLAYGROUND',
|
||||
HUMHUB_AUTO_LOGIN = 'HUMHUB_AUTO_LOGIN',
|
||||
PROJECT_BRANDING_VIEW = 'PROJECT_BRANDING_VIEW',
|
||||
// Moderator
|
||||
SEARCH_USERS = 'SEARCH_USERS',
|
||||
ADMIN_CREATE_CONTRIBUTION = 'ADMIN_CREATE_CONTRIBUTION',
|
||||
@ -64,4 +66,5 @@ export enum RIGHTS {
|
||||
COMMUNITY_BY_IDENTIFIER = 'COMMUNITY_BY_IDENTIFIER',
|
||||
HOME_COMMUNITY = 'HOME_COMMUNITY',
|
||||
COMMUNITY_UPDATE = 'COMMUNITY_UPDATE',
|
||||
PROJECT_BRANDING_MUTATE = 'PROJECT_BRANDING_MUTATE',
|
||||
}
|
||||
|
||||
@ -31,4 +31,5 @@ export const USER_RIGHTS = [
|
||||
RIGHTS.USER,
|
||||
RIGHTS.GMS_USER_PLAYGROUND,
|
||||
RIGHTS.HUMHUB_AUTO_LOGIN,
|
||||
RIGHTS.PROJECT_BRANDING_VIEW,
|
||||
]
|
||||
|
||||
38
backend/src/graphql/input/ProjectBrandingInput.ts
Normal file
38
backend/src/graphql/input/ProjectBrandingInput.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import { IsString, IsOptional, MaxLength, IsNumber, IsBoolean, IsUrl } from 'class-validator'
|
||||
import { InputType, Field, Int } from 'type-graphql'
|
||||
|
||||
@InputType()
|
||||
export class ProjectBrandingInput {
|
||||
@Field(() => Int, { nullable: true })
|
||||
@IsOptional()
|
||||
id: number | null | undefined
|
||||
|
||||
@Field(() => String)
|
||||
@IsString()
|
||||
name: string
|
||||
|
||||
@Field(() => String)
|
||||
@IsString()
|
||||
@MaxLength(32)
|
||||
alias: string
|
||||
|
||||
@Field(() => String, { nullable: true })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
description: string | null | undefined
|
||||
|
||||
@Field(() => Int, { nullable: true })
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
spaceId: number | null | undefined
|
||||
|
||||
@Field(() => Boolean)
|
||||
@IsBoolean()
|
||||
newUserToSpace: boolean
|
||||
|
||||
@Field(() => String, { nullable: true })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@IsUrl()
|
||||
logoUrl: string | null | undefined
|
||||
}
|
||||
30
backend/src/graphql/model/ProjectBranding.ts
Normal file
30
backend/src/graphql/model/ProjectBranding.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { ProjectBranding as dbProjectBranding } from '@entity/ProjectBranding'
|
||||
import { ObjectType, Field, Int } from 'type-graphql'
|
||||
|
||||
@ObjectType()
|
||||
export class ProjectBranding {
|
||||
constructor(projectBranding: dbProjectBranding) {
|
||||
Object.assign(this, projectBranding)
|
||||
}
|
||||
|
||||
@Field(() => Int)
|
||||
id: number
|
||||
|
||||
@Field(() => String)
|
||||
name: string
|
||||
|
||||
@Field(() => String)
|
||||
alias: string
|
||||
|
||||
@Field(() => String, { nullable: true })
|
||||
description: string | null
|
||||
|
||||
@Field(() => Int, { nullable: true })
|
||||
spaceId: number | null
|
||||
|
||||
@Field(() => Boolean)
|
||||
newUserToSpace: boolean
|
||||
|
||||
@Field(() => String, { nullable: true })
|
||||
logoUrl: string | null
|
||||
}
|
||||
72
backend/src/graphql/resolver/ProjectBrandingResolver.ts
Normal file
72
backend/src/graphql/resolver/ProjectBrandingResolver.ts
Normal file
@ -0,0 +1,72 @@
|
||||
import { ProjectBranding as DbProjectBranding } from '@entity/ProjectBranding'
|
||||
import { Resolver, Query, Mutation, Arg, Int, Authorized } from 'type-graphql'
|
||||
|
||||
import { ProjectBrandingInput } from '@input/ProjectBrandingInput'
|
||||
import { ProjectBranding } from '@model/ProjectBranding'
|
||||
|
||||
import { RIGHTS } from '@/auth/RIGHTS'
|
||||
import { LogError } from '@/server/LogError'
|
||||
import { backendLogger as logger } from '@/server/logger'
|
||||
|
||||
@Resolver()
|
||||
export class ProjectBrandingResolver {
|
||||
@Query(() => [ProjectBranding])
|
||||
@Authorized([RIGHTS.PROJECT_BRANDING_VIEW])
|
||||
async getProjectBrandings(): Promise<ProjectBranding[]> {
|
||||
return (await DbProjectBranding.find()).map(
|
||||
(entity: DbProjectBranding) => new ProjectBranding(entity),
|
||||
)
|
||||
}
|
||||
|
||||
@Query(() => ProjectBranding, { nullable: true })
|
||||
@Authorized([RIGHTS.PROJECT_BRANDING_VIEW])
|
||||
async getProjectBranding(@Arg('id', () => Int) id: number): Promise<ProjectBranding | null> {
|
||||
const projectBrandingEntity = await DbProjectBranding.findOneBy({ id })
|
||||
if (!projectBrandingEntity) {
|
||||
throw new LogError(`Project Branding with id: ${id} not found`)
|
||||
}
|
||||
return new ProjectBranding(projectBrandingEntity)
|
||||
}
|
||||
|
||||
@Query(() => String, { nullable: true })
|
||||
@Authorized([RIGHTS.PROJECT_BRANDING_BANNER])
|
||||
async getProjectBrandingBanner(
|
||||
@Arg('alias', () => String) alias: string,
|
||||
): Promise<string | null> {
|
||||
const projectBrandingEntity = await DbProjectBranding.findOne({
|
||||
where: { alias },
|
||||
select: { logoUrl: true },
|
||||
})
|
||||
if (!projectBrandingEntity) {
|
||||
throw new LogError(`Project Branding with alias: ${alias} not found`)
|
||||
}
|
||||
return projectBrandingEntity.logoUrl
|
||||
}
|
||||
|
||||
@Mutation(() => ProjectBranding, { nullable: true })
|
||||
@Authorized([RIGHTS.PROJECT_BRANDING_MUTATE])
|
||||
async upsertProjectBranding(
|
||||
@Arg('data') data: ProjectBrandingInput,
|
||||
): Promise<ProjectBranding | null> {
|
||||
const projectBranding = data.id
|
||||
? await DbProjectBranding.findOneOrFail({ where: { id: data.id } })
|
||||
: new DbProjectBranding()
|
||||
|
||||
Object.assign(projectBranding, data)
|
||||
await projectBranding.save()
|
||||
|
||||
return new ProjectBranding(projectBranding)
|
||||
}
|
||||
|
||||
@Mutation(() => Boolean)
|
||||
@Authorized([RIGHTS.PROJECT_BRANDING_MUTATE])
|
||||
async deleteProjectBranding(@Arg('id', () => Int) id: number): Promise<boolean> {
|
||||
try {
|
||||
await DbProjectBranding.delete({ id })
|
||||
return true
|
||||
} catch (err) {
|
||||
logger.error(err)
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,8 @@
|
||||
import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm'
|
||||
import { Entity, PrimaryGeneratedColumn, Column, BaseEntity } from 'typeorm'
|
||||
|
||||
@Entity('project_brandings')
|
||||
export class ProjectBranding {
|
||||
@PrimaryGeneratedColumn()
|
||||
export class ProjectBranding extends BaseEntity {
|
||||
@PrimaryGeneratedColumn('increment', { unsigned: true })
|
||||
id: number
|
||||
|
||||
@Column({ name: 'name', type: 'varchar', length: 255 })
|
||||
@ -17,7 +17,7 @@ export class ProjectBranding {
|
||||
@Column({ name: 'space_id', type: 'int', unsigned: true, nullable: true, default: null })
|
||||
spaceId: number | null
|
||||
|
||||
@Column({ name:'new_user_to_space', type: 'tinyint', width: 1, default: 0 })
|
||||
@Column({ name: 'new_user_to_space', type: 'tinyint', width: 1, default: 0 })
|
||||
newUserToSpace: boolean
|
||||
|
||||
@Column({ name: 'logo_url', type: 'varchar', length: 255, nullable: true, default: null })
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user