112 lines
3.3 KiB
TypeScript
112 lines
3.3 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Put,
|
|
Delete,
|
|
Body,
|
|
Param,
|
|
Query,
|
|
Post,
|
|
UseGuards,
|
|
} from '@nestjs/common'
|
|
import { UserRole, CardTypeCategory } from '@mp-pilates/shared'
|
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard'
|
|
import { RolesGuard } from '../auth/roles.guard'
|
|
import { Roles } from '../auth/roles.decorator'
|
|
import { CurrentUser } from '../common/decorators/current-user.decorator'
|
|
import { UserService } from './user.service'
|
|
import { UpdateProfileDto } from './dto/update-profile.dto'
|
|
import { UpdateUserMembershipDto } from './dto/update-user-membership.dto'
|
|
import { ReportSubscriptionMessageRequestDto } from './dto/report-subscription-message.dto'
|
|
|
|
const VALID_CARD_TYPES = new Set<string>(Object.values(CardTypeCategory))
|
|
|
|
@UseGuards(JwtAuthGuard)
|
|
@Controller()
|
|
export class UserController {
|
|
constructor(private readonly userService: UserService) {}
|
|
|
|
@Get('user/profile')
|
|
getProfile(@CurrentUser('sub') userId: string) {
|
|
return this.userService.getProfile(userId)
|
|
}
|
|
|
|
@Put('user/profile')
|
|
updateProfile(
|
|
@CurrentUser('sub') userId: string,
|
|
@Body() dto: UpdateProfileDto,
|
|
) {
|
|
return this.userService.updateProfile(userId, dto)
|
|
}
|
|
|
|
@Get('user/stats')
|
|
getStats(@CurrentUser('sub') userId: string) {
|
|
return this.userService.getStats(userId)
|
|
}
|
|
|
|
@Get('user/subscription-messages/templates')
|
|
getSubscriptionMessageTemplates() {
|
|
return this.userService.getSubscriptionMessageTemplates()
|
|
}
|
|
|
|
@Post('user/subscription-messages/report')
|
|
reportSubscriptionMessageRequests(
|
|
@CurrentUser('sub') userId: string,
|
|
@Body() dto: ReportSubscriptionMessageRequestDto,
|
|
) {
|
|
return this.userService.reportSubscriptionMessageRequests(userId, dto.requests)
|
|
}
|
|
|
|
@Post('user/subscription-messages/admin-booking-count')
|
|
increaseAdminBookingSubscriptionCount(@CurrentUser('sub') userId: string) {
|
|
return this.userService.grantAdminBookingSubscriptionCount(userId)
|
|
}
|
|
|
|
// ─── Admin: Member Management ─────────────────────────────────────────────
|
|
|
|
@Get('admin/members')
|
|
@UseGuards(RolesGuard)
|
|
@Roles(UserRole.ADMIN)
|
|
getMembers(
|
|
@Query('page') page?: string,
|
|
@Query('limit') limit?: string,
|
|
@Query('search') search?: string,
|
|
@Query('cardType') cardType?: string,
|
|
) {
|
|
const validCardType =
|
|
cardType && cardType !== 'undefined' && (VALID_CARD_TYPES.has(cardType) || cardType === 'NONE')
|
|
? cardType
|
|
: undefined
|
|
return this.userService.getMembers(
|
|
page ? Number(page) : 1,
|
|
limit ? Number(limit) : 20,
|
|
search && search !== 'undefined' ? search : undefined,
|
|
validCardType,
|
|
)
|
|
}
|
|
|
|
@Get('admin/members/:userId/membership')
|
|
@UseGuards(RolesGuard)
|
|
@Roles(UserRole.ADMIN)
|
|
getUserMembership(@Param('userId') userId: string) {
|
|
return this.userService.getUserMembership(userId)
|
|
}
|
|
|
|
@Put('admin/members/:userId/membership')
|
|
@UseGuards(RolesGuard)
|
|
@Roles(UserRole.ADMIN)
|
|
updateUserMembership(
|
|
@Param('userId') userId: string,
|
|
@Body() dto: UpdateUserMembershipDto,
|
|
) {
|
|
return this.userService.updateUserMembership(userId, dto)
|
|
}
|
|
|
|
@Delete('admin/members/:userId/membership')
|
|
@UseGuards(RolesGuard)
|
|
@Roles(UserRole.ADMIN)
|
|
deleteUserMembership(@Param('userId') userId: string) {
|
|
return this.userService.deleteUserMembership(userId)
|
|
}
|
|
}
|