Skip to content

Commit

Permalink
Add controller for retrieving user
Browse files Browse the repository at this point in the history
  • Loading branch information
devleejb committed Jan 18, 2024
1 parent 58237a4 commit 862d7ed
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
3 changes: 3 additions & 0 deletions backend/src/users/types/find-user-response.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { UserDomain } from "./user-domain.type";

export class FindUserResponse extends UserDomain {}
6 changes: 6 additions & 0 deletions backend/src/users/types/user-domain.type.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { ApiProperty } from "@nestjs/swagger";

export class UserDomain {
@ApiProperty({ type: String, description: "ID of user" })
id: string;
@ApiProperty({ type: String, description: "Nickname of user" })
nickname: string;
@ApiProperty({ type: Date, description: "Created date of user" })
createdAt: Date;
@ApiProperty({ type: Date, description: "Updated date of user" })
updatedAt: Date;
}
22 changes: 20 additions & 2 deletions backend/src/users/users.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
import { Controller } from "@nestjs/common";
import { Controller, Get, Req } from "@nestjs/common";
import { ApiBearerAuth, ApiOkResponse, ApiOperation, ApiTags } from "@nestjs/swagger";
import { UsersService } from "./users.service";
import { AuthroizedRequest } from "src/utils/types/req.type";
import { FindUserResponse } from "./types/find-user-response.type";

@ApiTags("Users")
@ApiBearerAuth()
@Controller("users")
export class UsersController {}
export class UsersController {
constructor(private usersService: UsersService) {}

@Get("")
@ApiOperation({
summary: "Retrieve the Users Information (Myself)",
description: "Return the user information",
})
@ApiOkResponse({ type: FindUserResponse })
async findOne(@Req() req: AuthroizedRequest): Promise<FindUserResponse> {
return this.usersService.findOne(req.user.id);
}
}
4 changes: 2 additions & 2 deletions backend/src/users/users.service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Injectable } from "@nestjs/common";
import { User } from "@prisma/client";
import { PrismaService } from "src/db/prisma.service";
import { UserDomain } from "./types/user-domain.type";
import { FindUserResponse } from "./types/find-user-response.type";

@Injectable()
export class UsersService {
constructor(private prismaService: PrismaService) {}

async findOne(userId: string): Promise<UserDomain> {
async findOne(userId: string): Promise<FindUserResponse> {
return await this.prismaService.user.findUnique({
select: {
id: true,
Expand Down

0 comments on commit 862d7ed

Please sign in to comment.