feat: allow admins to add match participants
This commit is contained in:
1 parent
8aff1be225
commit
24983aeb09
11 files changed
+1019
-19
No files matched your search
@@ -0,0 +1,61 @@
|
||||
import {
|
||||
BadRequestException,
|
||||
Controller,
|
||||
Get,
|
||||
Param,
|
||||
Query,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { Type } from 'class-transformer';
|
||||
import {
|
||||
IsInt,
|
||||
IsOptional,
|
||||
IsString,
|
||||
Max,
|
||||
MaxLength,
|
||||
Min,
|
||||
} from 'class-validator';
|
||||
import mongoose from 'mongoose';
|
||||
import { CurrentUser } from '../auth/current-user.decorator';
|
||||
import { Roles } from '../auth/roles.decorator';
|
||||
import { RolesGuard } from '../auth/roles.guard';
|
||||
import { ParseObjectIdPipe } from '../common/parse-object-id.pipe';
|
||||
import type { UserDocument } from '../global/database/schema';
|
||||
import { UserSearchService } from './user-search.service';
|
||||
|
||||
class SearchCommunityUsersQueryDto {
|
||||
@IsString()
|
||||
@MaxLength(80)
|
||||
query!: string;
|
||||
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsInt()
|
||||
@Min(1)
|
||||
@Max(20)
|
||||
limit?: number;
|
||||
}
|
||||
|
||||
@Controller('communities/:communityId/users')
|
||||
@Roles('admin', 'owner')
|
||||
@UseGuards(RolesGuard)
|
||||
export class CommunityUserController {
|
||||
constructor(private readonly userSearchService: UserSearchService) {}
|
||||
|
||||
@Get('search')
|
||||
public async searchUsers(
|
||||
@CurrentUser() currentUser: UserDocument,
|
||||
@Param('communityId', ParseObjectIdPipe)
|
||||
communityId: mongoose.Types.ObjectId,
|
||||
@Query() query: SearchCommunityUsersQueryDto,
|
||||
) {
|
||||
if (!currentUser.communityId.equals(communityId)) {
|
||||
throw new BadRequestException('Different community.');
|
||||
}
|
||||
return this.userSearchService.search({
|
||||
communityId,
|
||||
query: query.query,
|
||||
limit: query.limit,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user