Skip to content

Commit 1599ab7

Browse files
committed
feat(notifications): refactored notifications module
refactored notifications UI and API modules
1 parent 7b47023 commit 1599ab7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+875
-787
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ speed-measure-plugin.json
2727
!.vscode/tasks.json
2828
!.vscode/launch.json
2929
!.vscode/extensions.json
30+
.history/*
3031

3132
# misc
3233
/.sass-cache

PLAYBOOK-NEST.md

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -66,54 +66,47 @@ npm i -D @types/helmet
6666

6767
```bash
6868
# scaffold core module
69-
nest g module core --dry-run
70-
nest g guard auth core --dry-run
71-
nest g exception auth --dry-run
69+
nest g module app/core --dry-run
70+
nest g guard auth app/core --dry-run
7271

73-
# scaffold shared module
74-
nest g module shared --dry-run
75-
nest g gateway eventbus shared --dry-run # /src/shared/eventbus/eventbus.gateway.ts to shared/eventbus.gateway.ts
7672

77-
# scaffold project module
78-
nest g module project --dry-run
79-
nest g controller project --dry-run
80-
nest g service project project --dry-run
81-
nest g class project --dry-run
73+
# scaffold shared module
74+
nest g module app/shared --dry-run
75+
nest g gateway eventbus app/shared --dry-run
8276

8377
# scaffold user module
84-
nest g module user --dry-run
85-
nest g controller profile user --dry-run
86-
nest g service profile user --dry-run
87-
nest g class profile user --dry-run
88-
nest g controller email user --dry-run
78+
nest g module app/user --dry-run
79+
nest g controller profile app/user --dry-run
80+
nest g service profile app/user --dry-run
81+
nest g class profile/profile.entity app/user --no-spec --dry-run
82+
nest g controller email app/user --dry-run
8983

9084
# scaffold email module
91-
nest g module email --dry-run
92-
nest g service email email --dry-run
85+
nest g module app/email --dry-run
86+
nest g service email app/email --flat --dry-run
9387

9488
# scaffold auth module
95-
nest g module auth --dry-run
96-
nest g service auth auth --dry-run
97-
nest g controller auth --dry-run
98-
nest g class user auth --dry-run # move ../ and rename as user.entity.ts
99-
100-
# scaffold chat module
101-
nest g module chat --dry-run
102-
nest g service chat chat --dry-run
103-
nest g controller chat --dry-run
104-
nest g gateway chat --dry-run
89+
nest g module app/auth --dry-run
90+
nest g controller auth app/auth --flat --dry-run
91+
nest g service auth app/auth --flat --dry-run
92+
nest g class user.entity app/auth --no-spec --dry-run
93+
nest g class auth.exception app/auth --no-spec --dry-run
10594

10695
# scaffold chat module
107-
nest g module notifications --dry-run
108-
nest g controller notifications --dry-run
109-
nest g service notifications notifications --dry-run
110-
nest g class notification notifications --dry-run
111-
112-
# scaffold push module
113-
nest g module push --dry-run
114-
nest g controller push --dry-run
115-
nest g service push --dry-run
116-
nest g class subscription push --no-spec --dry-run # rename as subscription.entity.ts
96+
nest g module app/chat --dry-run
97+
nest g controller chat app/chat --flat --dry-run
98+
nest g service chat app/chat --flat --dry-run
99+
nest g gateway chat app/chat --flat --dry-run
100+
101+
# scaffold notifications module
102+
nest g module app/notifications --dry-run
103+
nest g controller notification app/notifications --dry-run
104+
nest g service notification app/notifications --dry-run
105+
nest g service notification/push app/notifications --flat --no-spec --dry-run
106+
nest g class notification/notification.entity app/notifications --no-spec --dry-run
107+
nest g controller subscription app/notifications --dry-run
108+
nest g service subscription app/notifications --dry-run
109+
nest g class subscription/subscription.entity app/notifications --no-spec --dry-run
117110
```
118111

119112
### Ref

apps/api/README.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,12 @@ npm run api:build
8484
# check of nest installed
8585
nest info
8686

87-
# scaffold project module
88-
nest generate module project --dry-run
89-
nest generate controller project --dry-run
90-
nest generate service project project --dry-run
91-
nest generate class project --dry-run
92-
93-
# scaffold core module
94-
nest g module core --dry-run
95-
nest g guard auth core --dry-run
96-
nest g exception auth --dry-run
87+
# scaffold auth module
88+
nest g module app/auth --dry-run
89+
nest g controller auth app/auth --flat --dry-run
90+
nest g service auth app/auth --flat --dry-run
91+
nest g class user.entity app/auth --no-spec --dry-run
92+
nest g class auth.exception app/auth --no-spec --dry-run
9793
```
9894

9995
### Test

apps/api/src/app/app.module.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { UserModule } from './user';
77
// import { ChatModule } from './chat';
88
import { AppController } from './app.controller';
99
import { NotificationsModule } from './notifications';
10-
import { PushModule } from './push';
1110
import { ExternalModule } from './external';
1211

1312
@Module({
@@ -18,9 +17,8 @@ import { ExternalModule } from './external';
1817
children: [
1918
{ path: '/auth', module: AuthModule },
2019
{ path: '/user', module: UserModule },
21-
{ path: '/push', module: PushModule },
2220
// { path: '/account', module: AccountModule },
23-
{ path: '/notifications', module: NotificationsModule },
21+
{ path: '/', module: NotificationsModule },
2422
],
2523
},
2624
{ path: '/external', module: ExternalModule },
@@ -32,7 +30,6 @@ import { ExternalModule } from './external';
3230
// ChatModule,
3331
ExternalModule,
3432
NotificationsModule,
35-
PushModule,
3633
],
3734
controllers: [AppController],
3835
})

apps/api/src/app/core/core.module.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import { LoggingInterceptor, TransformInterceptor } from './interceptors';
77
import { RequestContextMiddleware } from './context';
88
import { ConfigService } from '../config';
99
import { ConnectionOptions } from 'typeorm';
10-
import { Notification } from '../notifications/notification.entity';
11-
import { User } from '../auth/user.entity';
1210
import { environment as env } from '@env-api/environment';
13-
import { Subscription } from '../push/subscription.entity';
11+
import { User } from '../auth/user.entity';
12+
import { Notification } from '../notifications/notification/notification.entity';
13+
import { Subscription } from '../notifications/subscription/subscription.entity';
1414

1515
@Module({
1616
imports: [
@@ -21,7 +21,7 @@ import { Subscription } from '../push/subscription.entity';
2121
useFactory: async (config: ConfigService) =>
2222
({
2323
...env.database,
24-
entities: [Notification, User, Subscription],
24+
entities: [User, Notification, Subscription],
2525
} as ConnectionOptions),
2626
inject: [ConfigService],
2727
}),

apps/api/src/app/notifications/dto/create-notification.dto.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
// Actions
2-
export class AddNotification {
3-
static readonly type = '[Notifications] Add';
4-
constructor(public readonly payload: any) {}
5-
}
62

73
export class DeleteNotification {
84
static readonly type = '[Notifications] Delete';
95
constructor(public readonly payload: any) {}
106
}
7+
8+
export class MarkAsRead {
9+
static readonly type = '[Notifications] MarkAsRead';
10+
constructor(public readonly payload: any) {}
11+
}
12+
13+
export class MarkAllAsRead {
14+
static readonly type = '[Notifications] MarkAllAsRead';
15+
}

apps/api/src/app/notifications/notification.entity.ts

Lines changed: 0 additions & 67 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { ApiModelProperty, ApiModelPropertyOptional } from '@nestjs/swagger';
2+
import { IsAscii, IsBoolean, IsEnum, IsNotEmpty, IsOptional, IsString, MaxLength, MinLength } from 'class-validator';
3+
import { NotificationColor, NotificationIcon, TargetType } from '../notification.entity';
4+
5+
export class CreateNotificationDto {
6+
@ApiModelProperty({ type: String, minLength: 10, maxLength: 100 })
7+
@IsNotEmpty()
8+
@IsString()
9+
readonly title: string;
10+
11+
@ApiModelProperty({ type: String, minLength: 10, maxLength: 100 })
12+
@IsNotEmpty()
13+
@IsString()
14+
readonly body: string;
15+
16+
@ApiModelProperty({ type: String, minLength: 3, maxLength: 50 })
17+
@IsNotEmpty()
18+
@IsAscii()
19+
@MinLength(3)
20+
@MaxLength(50)
21+
readonly target: string;
22+
23+
@ApiModelProperty({ type: String, enum: TargetType })
24+
@IsNotEmpty()
25+
@IsEnum(TargetType)
26+
readonly targetType: TargetType;
27+
28+
@ApiModelPropertyOptional({ type: String, enum: NotificationIcon, default: NotificationIcon.notifications })
29+
@IsOptional()
30+
@IsEnum(NotificationIcon)
31+
readonly icon?: NotificationIcon;
32+
33+
@ApiModelPropertyOptional({ type: String, enum: NotificationColor, default: NotificationColor.PRIMARY })
34+
@IsOptional()
35+
@IsEnum(NotificationColor)
36+
readonly color?: NotificationColor;
37+
38+
@ApiModelPropertyOptional({ type: Boolean, default: false })
39+
@IsOptional()
40+
@IsBoolean()
41+
readonly native?: boolean;
42+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { ApiModelProperty, ApiModelPropertyOptional } from '@nestjs/swagger';
2+
import { IsNotEmpty, IsOptional, IsString } from 'class-validator';
3+
4+
export class SendNotificationDto {
5+
@ApiModelProperty({ type: String })
6+
@IsNotEmpty()
7+
@IsString()
8+
id: string;
9+
10+
@ApiModelPropertyOptional({ type: String })
11+
@IsOptional()
12+
@IsString()
13+
target?: string;
14+
}

0 commit comments

Comments
 (0)