init commit

This commit is contained in:
unurled 2025-02-07 12:47:58 +01:00
commit 2346fe4879
Signed by: unurled
GPG key ID: EFC5F5E709B47DDD
45 changed files with 2573 additions and 0 deletions

View 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;
}
}

View 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{}

View 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,
});
}
}