init commit
This commit is contained in:
commit
2346fe4879
45 changed files with 2573 additions and 0 deletions
16
src/modules/users/users.controller.ts
Normal file
16
src/modules/users/users.controller.ts
Normal file
|
@ -0,0 +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";
|
||||
|
||||
@Controller("users")
|
||||
export class UsersController{
|
||||
constructor(){}
|
||||
|
||||
@Get("me")
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
getMyself(@Req() req: any): UserEntity{
|
||||
return req.user;
|
||||
}
|
||||
}
|
10
src/modules/users/users.module.ts
Normal file
10
src/modules/users/users.module.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
import {Module} from "@nestjs/common";
|
||||
import {UsersService} from "./users.service";
|
||||
import {UsersController} from "./users.controller";
|
||||
|
||||
@Module({
|
||||
providers: [UsersService],
|
||||
exports: [UsersService],
|
||||
controllers: [UsersController],
|
||||
})
|
||||
export class UsersModule{}
|
56
src/modules/users/users.service.ts
Normal file
56
src/modules/users/users.service.ts
Normal file
|
@ -0,0 +1,56 @@
|
|||
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,
|
||||
){}
|
||||
|
||||
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,
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue