Files
wwjcloud/LoginController.ts

43 lines
1.1 KiB
TypeScript
Raw Normal View History

import { Controller, Get, Put, Body, Param } from "@nestjs/common";
import { ApiTags, ApiOperation, ApiResponse } from "@nestjs/swagger";
import { LoginService } from "../../services/admin/LoginService";
@ApiTags("登录管理")
@Controller("adminapi")
export class LoginController {
constructor(
private readonly loginService: LoginService,
) {}
@Get("login/:app_type")
@ApiOperation({ summary: "用户登录" })
@ApiResponse({ status: 200, description: "登录成功" })
async login(@Param("app_type") appType: string, @Body() data: any) {
const { username, password } = data;
const result = await this.loginService.login(username, password, appType);
if (!result) {
return {
code: 1,
data: null,
message: "USER_ERROR"
};
}
return {
code: 0,
data: result,
message: "success"
};
}
@Put("auth/logout")
@ApiOperation({ summary: "退出登录" })
@ApiResponse({ status: 200, description: "退出成功" })
async logout() {
await this.loginService.logout();
return {
code: 0,
data: null,
message: "LOGOUT"
};
}
}