feat: add auth to the users controller
This commit is contained in:
@@ -38,8 +38,8 @@ export class UsersService {
|
||||
}
|
||||
/*******************************/
|
||||
|
||||
async getMe(userId: string) {
|
||||
const user = await this.userRepository.findOne({ id: userId }, { populate: ["role"] });
|
||||
async getMe(userId: string, businessId: string) {
|
||||
const user = await this.userRepository.findOne({ id: userId, business: { id: businessId } }, { populate: ["role"] });
|
||||
if (!user) throw new BadRequestException(UserMessage.USER_NOT_FOUND);
|
||||
return { user };
|
||||
}
|
||||
|
||||
@@ -1,16 +1,21 @@
|
||||
import { Controller, Get } from "@nestjs/common";
|
||||
import { Controller, Get, UseInterceptors } from "@nestjs/common";
|
||||
import { ApiOperation } from "@nestjs/swagger";
|
||||
|
||||
import { UsersService } from "./services/users.service";
|
||||
import { AuthGuards } from "../../common/decorators/auth-guard.decorator";
|
||||
import { BusinessDec } from "../../common/decorators/business.decorator";
|
||||
import { UserDec } from "../../common/decorators/user.decorator";
|
||||
import { BusinessInterceptor } from "../../core/interceptors/business.interceptor";
|
||||
|
||||
@Controller("users")
|
||||
@AuthGuards()
|
||||
@UseInterceptors(BusinessInterceptor)
|
||||
export class UsersController {
|
||||
constructor(private readonly usersService: UsersService) {}
|
||||
|
||||
@ApiOperation({ summary: "Get user profile" })
|
||||
@Get("me")
|
||||
getMe(@UserDec("id") userId: string) {
|
||||
return this.usersService.getMe(userId);
|
||||
getMe(@UserDec("id") userId: string, @BusinessDec("id") businessId: string) {
|
||||
return this.usersService.getMe(userId, businessId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,10 @@ import { Role } from "./entities/role.entity";
|
||||
import { User } from "./entities/user.entity";
|
||||
import { UsersService } from "./services/users.service";
|
||||
import { UsersController } from "./users.controller";
|
||||
import { BusinessesModule } from "../businesses/businesses.module";
|
||||
|
||||
@Module({
|
||||
imports: [MikroOrmModule.forFeature([User, Role])],
|
||||
imports: [MikroOrmModule.forFeature([User, Role]), BusinessesModule],
|
||||
controllers: [UsersController],
|
||||
providers: [UsersService],
|
||||
exports: [UsersService],
|
||||
|
||||
Reference in New Issue
Block a user