You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.4 KiB
40 lines
1.4 KiB
import { Controller, Get, Post, Body, Request, Put, UseGuards } from "@nestjs/common"; |
|
import { AdminService } from "./admin.service"; |
|
import { CreateAdminDto } from "./dto/create-Admin.dto"; |
|
import { LoginAdminDto } from "./dto/login-Admin.dto"; |
|
import { UpdateUserDto } from "./dto/update-user.dto"; |
|
import { RoleGuard } from "src/guard/role.guard"; |
|
|
|
@Controller("admin") |
|
export class AdminController { |
|
constructor(private readonly adminService: AdminService) {} |
|
// register as a admin |
|
@Post("register") |
|
async register(@Body() createAdminDto: CreateAdminDto): Promise<{ message }> { |
|
return this.adminService.register(createAdminDto); |
|
} |
|
//login as admin |
|
@Post("login") |
|
async login(@Body() loginAdminDto: LoginAdminDto): Promise<{ accessToken; refreshToken }> { |
|
return this.adminService.login(loginAdminDto); |
|
} |
|
//logout user |
|
@UseGuards(RoleGuard) |
|
@Get("logout") |
|
async logout(@Request() req) { |
|
const userId = req.user.id; |
|
return this.adminService.logout(userId); |
|
} |
|
//get a new access token |
|
@Post("new-token") |
|
async newAccessToken(@Body("token") token: string) { |
|
return this.adminService.newAccessToken(token); |
|
} |
|
//edit admin profile |
|
@UseGuards(RoleGuard) |
|
@Put() |
|
async editAdminProfile(@Request() req, @Body() updateAdminDto: UpdateUserDto): Promise<{ message }> { |
|
const userId = req.user.id; |
|
return this.adminService.editAdminProfile(userId, updateAdminDto); |
|
} |
|
}
|
|
|