Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@nestjs/passport": "^11.0.5",
"@nestjs/platform-express": "^11.0.1",
"@nestjs/schedule": "^6.0.0",
"@nestjs/swagger": "^11.0.7",
"@nestjs/swagger": "^11.2.5",
"@nestjs/throttler": "^6.4.0",
"@nestjs/typeorm": "^11.0.0",
"@types/passport-google-oauth20": "^2.0.16",
Expand Down
1 change: 0 additions & 1 deletion backend/src/auth/providers/sign-in.provider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable prettier/prettier */
import {
forwardRef,
Inject,
Expand Down
1 change: 0 additions & 1 deletion backend/src/redis/redis.constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/* eslint-disable prettier/prettier */
export const REDIS_CLIENT = 'REDIS_CLIENT';
1 change: 0 additions & 1 deletion backend/src/redis/redis.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable prettier/prettier */
import { Global, Module, OnModuleDestroy, Inject } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { redisProvider } from './redis.provider';
Expand Down
1 change: 0 additions & 1 deletion backend/src/redis/redis.provider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable prettier/prettier */
import { Provider } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import Redis from 'ioredis';
Expand Down
74 changes: 74 additions & 0 deletions backend/src/users/dtos/createUserDto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,78 @@ export class CreateUserDto {
@IsOptional()
@IsEnum(AgeGroup)
ageGroup: AgeGroup;

/**
* Country of the user
*/
@ApiProperty({
example: 'United States',
required: false,
})
@IsOptional()
@IsString()
@MaxLength(100)
country?: string;

/**
* User interests
*/
@ApiProperty({
example: ['Coding', 'Design'],
required: false,
type: [String],
})
@IsOptional()
@IsArray()
@IsString({ each: true })
interests?: string[];

/**
* User occupation
*/
@ApiProperty({
example: 'Software Engineer',
required: false,
})
@IsOptional()
@IsString()
@MaxLength(150)
occupation?: string;

/**
* User goals
*/
@ApiProperty({
example: ['Learn NestJS', 'Build an app'],
required: false,
type: [String],
})
@IsOptional()
@IsArray()
@IsString({ each: true })
goals?: string[];

/**
* Available hours for learning
*/
@ApiProperty({
example: ['09:00', '10:00'],
required: false,
type: [String],
})
@IsOptional()
@IsArray()
@IsString({ each: true })
availableHours?: string[];

/**
* User bio
*/
@ApiProperty({
example: 'I am a passionate developer...',
required: false,
})
@IsOptional()
@IsString()
bio?: string;
}
34 changes: 5 additions & 29 deletions backend/src/users/dtos/editUserDto.dto.ts
Comment thread
0xDeon marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -1,30 +1,6 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsOptional, IsString, IsEmail, MinLength } from 'class-validator';
import { PartialType, OmitType } from '@nestjs/swagger';
import { CreateUserDto } from './createUserDto';

export class EditUserDto {
@ApiProperty({
description: 'username of the user',
required: false,
})
@IsOptional()
@IsString()
username?: string;

@ApiProperty({
description: 'Email address of the user',
required: false,
})
@IsOptional()
@IsEmail()
email?: string;

@ApiProperty({
description: 'Password of the user',
required: false,
minLength: 6,
})
@IsOptional()
@IsString()
@MinLength(6)
password?: string;
}
export class EditUserDto extends PartialType(
OmitType(CreateUserDto, ['email', 'password'] as const),
) { }
17 changes: 13 additions & 4 deletions backend/src/users/providers/update-user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class UpdateUserService {
constructor(
@InjectRepository(User)
private readonly userRepository: Repository<User>,
) {}
) { }

async editUser(id: string, editUserDto: EditUserDto): Promise<User> {
const user = await this.userRepository.findOne({ where: { id } });
Expand All @@ -22,10 +22,19 @@ export class UpdateUserService {
throw new NotFoundException(`User with ID ${id} not found`);
}

// Conditionally update fields
// Conditionally update fields - email and password are omitted from EditUserDto
user.username = editUserDto.username ?? user.username;
user.email = editUserDto.email ?? user.email;
user.password = editUserDto.password ?? user.password;
user.country = editUserDto.country ?? user.country;
user.interests = editUserDto.interests ?? user.interests;
user.occupation = editUserDto.occupation ?? user.occupation;
user.goals = editUserDto.goals ?? user.goals;
user.availableHours = editUserDto.availableHours ?? user.availableHours;
user.bio = editUserDto.bio ?? user.bio;
user.challengeLevel = editUserDto.challengeLevel ?? user.challengeLevel;
user.challengeTypes = editUserDto.challengeTypes ?? user.challengeTypes;
user.referralSource = editUserDto.referralSource ?? user.referralSource;
user.ageGroup = editUserDto.ageGroup ?? user.ageGroup;
user.fullname = editUserDto.fullname ?? user.fullname;

try {
return await this.userRepository.save(user);
Expand Down
44 changes: 43 additions & 1 deletion backend/src/users/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,48 @@ export class User {
@Column('varchar', { length: 50, nullable: true })
ageGroup?: string;

/**
* Country of the user
*/
@ApiProperty({ example: 'United States', required: false })
@Column('varchar', { length: 100, nullable: true })
country?: string;

/**
* User interests
*/
@ApiProperty({ example: ['Coding', 'Design'], required: false })
@Column('simple-array', { nullable: true })
interests?: string[];

/**
* User occupation
*/
@ApiProperty({ example: 'Software Engineer', required: false })
@Column('varchar', { length: 150, nullable: true })
occupation?: string;

/**
* User goals
*/
@ApiProperty({ example: ['Learn NestJS', 'Build an app'], required: false })
@Column('simple-array', { nullable: true })
goals?: string[];

/**
* Available hours for learning
*/
@ApiProperty({ example: ['09:00', '10:00'], required: false })
@Column('simple-array', { nullable: true })
availableHours?: string[];

/**
* User bio
*/
@ApiProperty({ example: 'I am a passionate developer...', required: false })
@Column('text', { nullable: true })
bio?: string;

@Column({ nullable: true })
passwordResetToken?: string;

Expand All @@ -116,4 +158,4 @@ export class User {

@OneToOne(() => Streak, (streak) => streak.user)
streak: Streak;
}
}
Loading