File tree Expand file tree Collapse file tree 6 files changed +55
-52
lines changed
shared/validation/user/dto Expand file tree Collapse file tree 6 files changed +55
-52
lines changed Original file line number Diff line number Diff line change 1
1
import { Inject , Injectable , Logger } from '@nestjs/common' ;
2
2
import { SearchQueryDTO } from '@shared/validation/common/dto/SearchQuery.dto' ;
3
3
import { SongViewDto } from '@shared/validation/song/dto/SongView.dto' ;
4
- import { UserViewDto } from '@shared/validation/user/dto/UserView .dto' ;
4
+ import { UserPreviewDto } from '@shared/validation/user/dto/UserPreview .dto' ;
5
5
6
6
import { SongService } from '@server/song/song.service' ;
7
7
import { UserService } from '@server/user/user.service' ;
@@ -61,7 +61,7 @@ export class SearchService {
61
61
return {
62
62
users : users . map (
63
63
( { username, profileImage } ) =>
64
- new UserViewDto ( {
64
+ new UserPreviewDto ( {
65
65
username,
66
66
profileImage,
67
67
} ) ,
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import { CreateUser } from '@shared/validation/user/dto/CreateUser.dto';
6
6
import { GetUser } from '@shared/validation/user/dto/GetUser.dto' ;
7
7
import { UpdateUsernameDto } from '@shared/validation/user/dto/UpdateUsername.dto' ;
8
8
import { UpdateUserProfileDto } from '@shared/validation/user/dto/UpdateUserProfile.dto' ;
9
- import { UserViewDto } from '@shared/validation/user/dto/UserView .dto' ;
9
+ import { UserProfileViewDto } from '@shared/validation/user/dto/UserProfileView .dto' ;
10
10
import { validate } from 'class-validator' ;
11
11
import { Model } from 'mongoose' ;
12
12
@@ -156,12 +156,14 @@ export class UserService {
156
156
user = await this . findByUsername ( username ) ;
157
157
}
158
158
159
- if ( user ) return new UserViewDto ( user ) ;
159
+ if ( ! user ) {
160
+ throw new HttpException (
161
+ 'You must provide an email, ID or username' ,
162
+ HttpStatus . BAD_REQUEST ,
163
+ ) ;
164
+ }
160
165
161
- throw new HttpException (
162
- 'You must provide an email, ID or username' ,
163
- HttpStatus . BAD_REQUEST ,
164
- ) ;
166
+ return UserProfileViewDto . fromUserDocument ( user ) ;
165
167
}
166
168
167
169
public async getHydratedUser ( user : UserDocument ) {
Original file line number Diff line number Diff line change 1
- export class UserViewDto {
1
+ export class UserPreviewDto {
2
2
username : string ;
3
3
profileImage : string ;
4
4
5
- constructor ( partial : UserViewDto ) {
5
+ constructor ( partial : UserPreviewDto ) {
6
6
Object . assign ( this , partial ) ;
7
7
}
8
8
}
Original file line number Diff line number Diff line change
1
+ import { UserDocument } from '@server/user/entity/user.entity' ;
2
+
3
+ export class UserProfileViewDto {
4
+ username : string ;
5
+ publicName : string ;
6
+ profileImage : string ;
7
+ description : string ;
8
+ lastSeen : Date ;
9
+ loginCount : number ;
10
+ loginStreak : number ;
11
+ playCount : number ;
12
+ // socialLinks: Record<keyof typeof UserLinks, string | undefined>;
13
+
14
+ public static fromUserDocument ( user : UserDocument ) : UserProfileViewDto {
15
+ return new UserProfileViewDto ( {
16
+ username : user . username ,
17
+ publicName : user . publicName ,
18
+ profileImage : user . profileImage ,
19
+ description : user . description ,
20
+ lastSeen : user . lastSeen ,
21
+ loginCount : user . loginCount ,
22
+ loginStreak : user . loginStreak ,
23
+ playCount : user . playCount ,
24
+ // socialLinks: user.socialLinks,
25
+ } ) ;
26
+ }
27
+
28
+ constructor ( partial : UserProfileViewDto ) {
29
+ Object . assign ( this , partial ) ;
30
+ }
31
+ }
32
+
33
+ // TODO: refactor all DTOs as ...Request.dto and ...Response.dto
Original file line number Diff line number Diff line change @@ -17,41 +17,10 @@ export type LoggedUserData = {
17
17
prefersDarkTheme : boolean ;
18
18
creationDate : string ;
19
19
lastEdited : string ;
20
- lastLogin : string ;
20
+ lastSeen : string ;
21
21
createdAt : string ;
22
22
updatedAt : string ;
23
23
id : string ;
24
24
} ;
25
25
26
- export enum SocialLinksTypes {
27
- BANDCAMP = 'bandcamp' ,
28
- DISCORD = 'discord' ,
29
- FACEBOOK = 'facebook' ,
30
- GITHUB = 'github' ,
31
- INSTAGRAM = 'instagram' ,
32
- REDDIT = 'reddit' ,
33
- SNAPCHAT = 'snapchat' ,
34
- SOUNDCLOUD = 'soundcloud' ,
35
- SPOTIFY = 'spotify' ,
36
- STEAM = 'steam' ,
37
- TELEGRAM = 'telegram' ,
38
- TIKTOK = 'tiktok' ,
39
- THREADS = 'threads' ,
40
- TWITCH = 'twitch' ,
41
- X = 'x' ,
42
- YOUTUBE = 'youtube' ,
43
- }
44
-
45
- export type SocialLinks = {
46
- [ K in SocialLinksTypes ] ?: string ;
47
- } ;
48
-
49
- export type UserProfileData = {
50
- lastLogin : Date ;
51
- loginStreak : number ;
52
- playCount : number ;
53
- publicName : string ;
54
- description : string ;
55
- profileImage : string ;
56
- socialLinks : SocialLinks ;
57
- } ;
26
+ // TODO: make this a DTO (part of the validation module)
Original file line number Diff line number Diff line change
1
+ import { UserProfileViewDto } from '@shared/validation/user/dto/UserProfileView.dto' ;
1
2
import Image from 'next/image' ;
2
3
3
- import { SocialLinksTypes , UserProfileData } from '../../auth/types/User' ;
4
-
5
4
type UserProfileProps = {
6
- userData : UserProfileData ;
5
+ userData : UserProfileViewDto ;
7
6
} ;
8
7
9
8
const UserProfile = ( { userData } : UserProfileProps ) => {
10
9
const {
11
- lastLogin ,
10
+ lastSeen ,
12
11
loginStreak,
13
12
playCount,
14
13
publicName,
15
14
description,
16
15
profileImage,
17
- socialLinks,
16
+ // socialLinks,
18
17
} = userData ;
19
18
20
19
return (
@@ -28,12 +27,12 @@ const UserProfile = ({ userData }: UserProfileProps) => {
28
27
/>
29
28
< h1 className = 'text-2xl font-bold' > { publicName } </ h1 >
30
29
< p className = 'text-gray-500' > { description } </ p >
31
- < p className = 'text-gray-500' > Last Login: { lastLogin . toLocaleString ( ) } </ p >
30
+ < p className = 'text-gray-500' > Last Login: { lastSeen . toLocaleString ( ) } </ p >
32
31
< p className = 'text-gray-500' > Login Streak: { loginStreak } </ p >
33
32
< p className = 'text-gray-500' > Play Count: { playCount } </ p >
34
- < ul className = 'mt-4' >
33
+ { /* <ul className='mt-4'>
35
34
{Object.keys(socialLinks).map((key, index) => {
36
- const link = socialLinks [ key as SocialLinksTypes ] ;
35
+ const link = socialLinks[key as keyof UserLinks ];
37
36
if (!link) return null;
38
37
39
38
return (
@@ -44,7 +43,7 @@ const UserProfile = ({ userData }: UserProfileProps) => {
44
43
</li>
45
44
);
46
45
}) }
47
- </ ul >
46
+ </ul> */ }
48
47
</ section >
49
48
) ;
50
49
} ;
You can’t perform that action at this time.
0 commit comments