Skip to content

Toni grbic/backend profile leaderboard #530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 33 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
af7df9e
profile endpoints
ToniGrbic Apr 16, 2025
b60bf4e
hooks
ToniGrbic Apr 17, 2025
4c2aabc
route name change
ToniGrbic Apr 17, 2025
8ae4092
delete account popup
ToniGrbic Apr 17, 2025
058cf35
update password endpoint finished
ToniGrbic Apr 17, 2025
76789f7
modified userData response
ToniGrbic Apr 17, 2025
903daad
fixed query key
ToniGrbic Apr 17, 2025
a7a84e7
calling endpoints for updating user
ToniGrbic Apr 17, 2025
18fe69e
type refactoring
ToniGrbic Apr 17, 2025
c692a5d
cleaned up context, removed localStorage
ToniGrbic Apr 17, 2025
20a91d8
refactored types for Registration and Profile Settings
ToniGrbic Apr 17, 2025
0277014
validateRepeatedPassword function
ToniGrbic Apr 17, 2025
8dd4450
check for existing user with same email or phoneNumber
ToniGrbic Apr 17, 2025
bcba0a0
edit states moved to Context
ToniGrbic Apr 17, 2025
3555d72
Merge branch 'main' of github.com:dump-hr/ddays-app into ToniGrbic/ba…
ToniGrbic Apr 17, 2025
f341f4d
build error fixes
ToniGrbic Apr 17, 2025
3426007
Merge branch 'main' of github.com:dump-hr/ddays-app into ToniGrbic/ba…
ToniGrbic Apr 18, 2025
dea5eef
linter fixes
ToniGrbic Apr 18, 2025
363d134
implemented soft delete for user
ToniGrbic Apr 18, 2025
f493f98
adjustments
ToniGrbic Apr 18, 2025
f5fa999
linter fix
ToniGrbic Apr 18, 2025
9b61c6d
Merge branch 'main' of github.com:dump-hr/ddays-app into ToniGrbic/ba…
ToniGrbic Apr 18, 2025
becc46a
check is not deleted for existing user
ToniGrbic Apr 19, 2025
8b40fab
removed duplicate toast and navigate
ToniGrbic Apr 19, 2025
c3855f3
toast message adjustment
ToniGrbic Apr 19, 2025
9e8c106
added "-" to name regex
lovretomic Apr 19, 2025
ae21fbd
dropdown options shared
ToniGrbic Apr 20, 2025
6b27091
absolute import
ToniGrbic Apr 20, 2025
ad5ac8b
removed unnecessary escape character for build fix
ToniGrbic Apr 20, 2025
eb6860b
Merge branch 'main' of github.com:dump-hr/ddays-app into ToniGrbic/ba…
ToniGrbic Apr 20, 2025
6bf122b
leaderboard wip
ToniGrbic Apr 23, 2025
ba7d26a
lint fixes
ToniGrbic Apr 23, 2025
fea0c81
build fix
ToniGrbic Apr 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Warnings:

- A unique constraint covering the columns `[email,isDeleted]` on the table `User` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[phoneNumber,isDeleted]` on the table `User` will be added. If there are existing duplicate values, this will fail.

*/
-- DropIndex
DROP INDEX "User_email_key";

-- DropIndex
DROP INDEX "User_phoneNumber_key";

-- AlterTable
ALTER TABLE "User" ALTER COLUMN "isDeleted" SET DEFAULT false;

-- CreateIndex
CREATE UNIQUE INDEX "User_email_isDeleted_key" ON "User"("email", "isDeleted");

-- CreateIndex
CREATE UNIQUE INDEX "User_phoneNumber_isDeleted_key" ON "User"("phoneNumber", "isDeleted");
9 changes: 6 additions & 3 deletions apps/api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,16 @@ model User {
id Int @id @default(autoincrement())
firstName String
lastName String
email String @unique
phoneNumber String @unique
email String
phoneNumber String
birthYear Int
occupation String?
educationDegree String?
password String?
points Int?
newsletterEnabled Boolean?
companiesNewsEnabled Boolean?
isDeleted Boolean?
isDeleted Boolean? @default(false)
isConfirmed Boolean? @default(false)
profilePhotoUrl String?
avatar Avatar[]
Expand All @@ -237,6 +237,9 @@ model User {
userToAchievement UserToAchievement[]
userToEvent UserToEvent[]
userToInterest UserToInterest[]

@@unique([email, isDeleted])
@@unique([phoneNumber, isDeleted])
}

model UserNotification {
Expand Down
4 changes: 4 additions & 0 deletions apps/api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import { EventModule } from './event/event.module';
import { FrequentlyAskedQuestionModule } from './frequently-asked-question/frequently-asked-question.module';
import { InterestModule } from './interest/interest.module';
import { JobModule } from './job/job.module';
import { LeaderboardModule } from './leaderboard/leaderboard.module';
import { NotificationModule } from './notification/notification.module';
import { PrismaService } from './prisma.service';
import { ShopModule } from './shop/shop.module';
import { SpeakerModule } from './speaker/speaker.module';
import { SurveyQuestionModule } from './survey-question/survey-question.module';
import { UserModule } from './user/user.module';

@Module({
imports: [
Expand Down Expand Up @@ -56,6 +58,8 @@ import { SurveyQuestionModule } from './survey-question/survey-question.module';

BoothModule,
ShopModule,
UserModule,
LeaderboardModule,
],
controllers: [AppController],
providers: [AppService, PrismaService],
Expand Down
32 changes: 25 additions & 7 deletions apps/api/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { JwtResponseDto } from '@ddays-app/types';
import { UserDto } from '@ddays-app/types/src/dto/user';
import { UserDto, UserPublicDto } from '@ddays-app/types/src/dto/user';
import { BadRequestException, Injectable } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { compare, hash } from 'bcrypt';
Expand Down Expand Up @@ -49,16 +49,18 @@ export class AuthService {
email: string,
password: string,
): Promise<JwtResponseDto> {
const loginUser = await this.prisma.user.findUnique({
const loginUser = await this.prisma.user.findFirst({
where: {
email,
isDeleted: false,
},
select: {
id: true,
email: true,
firstName: true,
lastName: true,
password: true,
isDeleted: true,
},
});

Expand All @@ -83,25 +85,27 @@ export class AuthService {
}

async userRegister(register: UserDto): Promise<JwtResponseDto> {
const existingPhoneNumber = await this.prisma.user.findUnique({
const existingActivePhoneUser = await this.prisma.user.findFirst({
where: {
phoneNumber: register.phoneNumber,
isDeleted: false,
},
});

if (existingPhoneNumber) {
if (existingActivePhoneUser) {
throw new BadRequestException(
'Korisnik sa ovim brojem telefona već postoji!',
);
}

const existingUser = await this.prisma.user.findUnique({
const existingActiveEmailUser = await this.prisma.user.findFirst({
where: {
email: register.email,
isDeleted: false,
},
});

if (existingUser) {
if (existingActiveEmailUser) {
throw new BadRequestException('Korisnik sa ovim emailom već postoji!');
}

Expand All @@ -125,9 +129,23 @@ export class AuthService {
return { accessToken };
}

async getUserById(id: number) {
async getUserById(id: number): Promise<UserPublicDto> {
return this.prisma.user.findUnique({
where: { id },
select: {
id: true,
email: true,
firstName: true,
lastName: true,
phoneNumber: true,
birthYear: true,
educationDegree: true,
occupation: true,
newsletterEnabled: true,
companiesNewsEnabled: true,
isConfirmed: true,
isDeleted: true,
},
});
}
}
49 changes: 49 additions & 0 deletions apps/api/src/leaderboard/leaderboard.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {
LeaderboardEntryDto,
LeaderboardQueryDto,
LeaderboardResponseDto,
UserRankResponseDto,
} from '@ddays-app/types/src/dto/leaderboard';
import {
Controller,
Get,
Param,
ParseIntPipe,
Query,
Req,
UseGuards,
} from '@nestjs/common';

import { UserGuard } from '../auth/user.guard';
import { LeaderboardService } from './leaderboard.service';

@Controller('leaderboard')
export class LeaderboardController {
constructor(private readonly leaderboardService: LeaderboardService) {}

@Get()
async getLeaderboard(
@Query() query: LeaderboardQueryDto,
): Promise<LeaderboardResponseDto> {
return this.leaderboardService.getLeaderboard(query);
}

@Get('top')
async getTopUsers(): Promise<LeaderboardEntryDto[]> {
return this.leaderboardService.getTopUsers(3);
}

@Get('user/:id')
@UseGuards(UserGuard)
async getUserRank(
@Param('id', ParseIntPipe) userId: number,
): Promise<UserRankResponseDto> {
return this.leaderboardService.getUserRank(userId);
}

@Get('me')
@UseGuards(UserGuard)
async getCurrentUserRank(@Req() { user }): Promise<UserRankResponseDto> {
return this.leaderboardService.getUserRank(user.id);
}
}
11 changes: 11 additions & 0 deletions apps/api/src/leaderboard/leaderboard.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common';
import { PrismaService } from 'src/prisma.service';

import { LeaderboardController } from './leaderboard.controller';
import { LeaderboardService } from './leaderboard.service';

@Module({
controllers: [LeaderboardController],
providers: [LeaderboardService, PrismaService],
})
export class LeaderboardModule {}
Loading
Loading