Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add createUnionGroup #649

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions apps/api/src/app/groups/dto/create-union-group.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {
ArrayNotEmpty,
IsArray,
IsNumber,
IsString,
Length,
Max,
Min,
MinLength,
NotContains
} from "class-validator"
import { ApiProperty } from "@nestjs/swagger"

export class CreateUnionGroupDto {
@IsString()
@Length(1, 50)
@NotContains("admin-groups")
@ApiProperty()
readonly name: string

@IsString()
@MinLength(10)
@ApiProperty()
readonly description: string

@IsNumber()
@Min(16, { message: "The tree depth must be between 16 and 32." })
@Max(32, { message: "The tree depth must be between 16 and 32." })
@ApiProperty()
readonly treeDepth: number

@IsNumber()
@Min(0)
@ApiProperty()
readonly fingerprintDuration: number
@IsArray()
@ArrayNotEmpty()
@ApiProperty()
readonly groupIds: string[]
}
35 changes: 35 additions & 0 deletions apps/api/src/app/groups/groups.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { UpdateGroupsDto } from "./dto/update-groups.dto"
import { GroupsService } from "./groups.service"
import { mapGroupToResponseDTO } from "./groups.utils"
import { RemoveGroupsDto } from "./dto/remove-groups.dto"
import { CreateUnionGroupDto } from "./dto/create-union-group.dto"

@ApiTags("groups")
@Controller("groups")
Expand Down Expand Up @@ -108,6 +109,40 @@ export class GroupsController {
return groupsToResponseDTO
}

@Post("union")
@ApiBody({ type: CreateUnionGroupDto })
@ApiHeader({ name: "x-api-key", required: true })
@ApiCreatedResponse({ type: Group })
@ApiOperation({
description: "Create a union group using an API Key or a valid session."
})
async createUnionGroup(
@Body() dto: CreateUnionGroupDto,
@Headers() headers: Headers,
@Req() req: Request
) {
let group: any
const apiKey = headers["x-api-key"] as string

if (apiKey) {
group = await this.groupsService.createUnionGroupWithApiKey(
dto,
apiKey
)
} else if (req.session.adminId) {
group = await this.groupsService.createUnionGroupManually(
dto,
req.session.adminId
)
} else {
throw new NotImplementedException()
}

const fingerprint = await this.groupsService.getFingerprint(group.id)

return mapGroupToResponseDTO(group, fingerprint)
}

@Delete()
@ApiBody({ type: RemoveGroupsDto })
@ApiHeader({ name: "x-api-key", required: true })
Expand Down
Loading
Loading