json logging + fix lint
This commit is contained in:
parent
24f3fb9b8e
commit
13ec6e388d
18 changed files with 551 additions and 465 deletions
|
@ -1,16 +1,16 @@
|
|||
import {Controller, Get, Req, UseGuards} from "@nestjs/common";
|
||||
import {JwtAuthGuard} from "../../common/modules/auth/guards/jwt-auth.guard";
|
||||
import {UserEntity} from "../../common/modules/auth/models/entities/user.entity";
|
||||
import {ApiBearerAuth} from "@nestjs/swagger";
|
||||
import { Controller, Get, Req, UseGuards } from '@nestjs/common';
|
||||
import { JwtAuthGuard } from '../../common/modules/auth/guards/jwt-auth.guard';
|
||||
import { UserEntity } from '../../common/modules/auth/models/entities/user.entity';
|
||||
import { ApiBearerAuth } from '@nestjs/swagger';
|
||||
|
||||
@Controller("users")
|
||||
export class UsersController{
|
||||
constructor(){}
|
||||
@Controller('users')
|
||||
export class UsersController {
|
||||
constructor() {}
|
||||
|
||||
@Get("me")
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
getMyself(@Req() req: any): UserEntity{
|
||||
return req.user;
|
||||
}
|
||||
@Get('me')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
getMyself(@Req() req: any): UserEntity {
|
||||
return req.user;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import {Module} from "@nestjs/common";
|
||||
import {UsersService} from "./users.service";
|
||||
import {UsersController} from "./users.controller";
|
||||
import { Module } from '@nestjs/common';
|
||||
import { UsersService } from './users.service';
|
||||
import { UsersController } from './users.controller';
|
||||
|
||||
@Module({
|
||||
providers: [UsersService],
|
||||
exports: [UsersService],
|
||||
controllers: [UsersController],
|
||||
providers: [UsersService],
|
||||
exports: [UsersService],
|
||||
controllers: [UsersController],
|
||||
})
|
||||
export class UsersModule{}
|
||||
export class UsersModule {}
|
||||
|
|
|
@ -1,56 +1,52 @@
|
|||
import {Injectable, NotFoundException} from "@nestjs/common";
|
||||
import {UserEntity} from "../../common/modules/auth/models/entities/user.entity";
|
||||
import {PrismaService} from "../../common/modules/helper/prisma.service";
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { UserEntity } from '../../common/modules/auth/models/entities/user.entity';
|
||||
import { PrismaService } from '../../common/modules/helper/prisma.service';
|
||||
|
||||
@Injectable()
|
||||
export class UsersService{
|
||||
constructor(
|
||||
private readonly prismaService: PrismaService,
|
||||
){}
|
||||
export class UsersService {
|
||||
constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
async getUserById(id: string){
|
||||
const user = await this.prismaService.users.findUnique({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
include: {
|
||||
email_verifications: true,
|
||||
},
|
||||
});
|
||||
if(!user)
|
||||
throw new NotFoundException("User not found");
|
||||
return new UserEntity({
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
email: user.email,
|
||||
verified: !user.email_verifications,
|
||||
password: user.password,
|
||||
tokenId: user.token_id,
|
||||
createdAt: user.created_at,
|
||||
updatedAt: user.updated_at,
|
||||
});
|
||||
}
|
||||
async getUserById(id: string) {
|
||||
const user = await this.prismaService.users.findUnique({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
include: {
|
||||
email_verifications: true,
|
||||
},
|
||||
});
|
||||
if (!user) throw new NotFoundException('User not found');
|
||||
return new UserEntity({
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
email: user.email,
|
||||
verified: !user.email_verifications,
|
||||
password: user.password,
|
||||
tokenId: user.token_id,
|
||||
createdAt: user.created_at,
|
||||
updatedAt: user.updated_at,
|
||||
});
|
||||
}
|
||||
|
||||
async getUserByEmail(email: string): Promise<UserEntity>{
|
||||
const user = await this.prismaService.users.findUnique({
|
||||
where: {
|
||||
email,
|
||||
},
|
||||
include: {
|
||||
email_verifications: true,
|
||||
},
|
||||
});
|
||||
if(!user)
|
||||
throw new NotFoundException("User not found");
|
||||
return new UserEntity({
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
email: user.email,
|
||||
verified: !user.email_verifications,
|
||||
password: user.password,
|
||||
tokenId: user.token_id,
|
||||
createdAt: user.created_at,
|
||||
updatedAt: user.updated_at,
|
||||
});
|
||||
}
|
||||
async getUserByEmail(email: string): Promise<UserEntity> {
|
||||
const user = await this.prismaService.users.findUnique({
|
||||
where: {
|
||||
email,
|
||||
},
|
||||
include: {
|
||||
email_verifications: true,
|
||||
},
|
||||
});
|
||||
if (!user) throw new NotFoundException('User not found');
|
||||
return new UserEntity({
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
email: user.email,
|
||||
verified: !user.email_verifications,
|
||||
password: user.password,
|
||||
tokenId: user.token_id,
|
||||
createdAt: user.created_at,
|
||||
updatedAt: user.updated_at,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue