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