-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(BE) Add API for Retrieving a User (#68)
* Add base code for users controller * Add service for user * Add controller for retrieving user
- Loading branch information
Showing
6 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from "@nestjs/testing"; | ||
import { UsersController } from "./users.controller"; | ||
|
||
describe("UsersController", () => { | ||
let controller: UsersController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [UsersController], | ||
}).compile(); | ||
|
||
controller = module.get<UsersController>(UsersController); | ||
}); | ||
|
||
it("should be defined", () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
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 { | ||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import { Module } from "@nestjs/common"; | ||
import { UsersService } from "./users.service"; | ||
import { PrismaService } from "src/db/prisma.service"; | ||
import { UsersController } from "./users.controller"; | ||
|
||
@Module({ | ||
providers: [UsersService, PrismaService], | ||
exports: [UsersService], | ||
controllers: [UsersController], | ||
}) | ||
export class UsersModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters