Skip to content

Commit

Permalink
feat(notifications): refactored notifications module
Browse files Browse the repository at this point in the history
refactored notifications UI and API modules
  • Loading branch information
xmlking committed Dec 4, 2018
1 parent d2f1a2e commit 2d85fd3
Show file tree
Hide file tree
Showing 51 changed files with 875 additions and 787 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -27,6 +27,7 @@ speed-measure-plugin.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history/*

# misc
/.sass-cache
Expand Down
69 changes: 31 additions & 38 deletions PLAYBOOK-NEST.md
Expand Up @@ -66,54 +66,47 @@ npm i -D @types/helmet

```bash
# scaffold core module
nest g module core --dry-run
nest g guard auth core --dry-run
nest g exception auth --dry-run
nest g module app/core --dry-run
nest g guard auth app/core --dry-run

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

# scaffold project module
nest g module project --dry-run
nest g controller project --dry-run
nest g service project project --dry-run
nest g class project --dry-run
# scaffold shared module
nest g module app/shared --dry-run
nest g gateway eventbus app/shared --dry-run

# scaffold user module
nest g module user --dry-run
nest g controller profile user --dry-run
nest g service profile user --dry-run
nest g class profile user --dry-run
nest g controller email user --dry-run
nest g module app/user --dry-run
nest g controller profile app/user --dry-run
nest g service profile app/user --dry-run
nest g class profile/profile.entity app/user --no-spec --dry-run
nest g controller email app/user --dry-run

# scaffold email module
nest g module email --dry-run
nest g service email email --dry-run
nest g module app/email --dry-run
nest g service email app/email --flat --dry-run

# scaffold auth module
nest g module auth --dry-run
nest g service auth auth --dry-run
nest g controller auth --dry-run
nest g class user auth --dry-run # move ../ and rename as user.entity.ts

# scaffold chat module
nest g module chat --dry-run
nest g service chat chat --dry-run
nest g controller chat --dry-run
nest g gateway chat --dry-run
nest g module app/auth --dry-run
nest g controller auth app/auth --flat --dry-run
nest g service auth app/auth --flat --dry-run
nest g class user.entity app/auth --no-spec --dry-run
nest g class auth.exception app/auth --no-spec --dry-run

# scaffold chat module
nest g module notifications --dry-run
nest g controller notifications --dry-run
nest g service notifications notifications --dry-run
nest g class notification notifications --dry-run

# scaffold push module
nest g module push --dry-run
nest g controller push --dry-run
nest g service push --dry-run
nest g class subscription push --no-spec --dry-run # rename as subscription.entity.ts
nest g module app/chat --dry-run
nest g controller chat app/chat --flat --dry-run
nest g service chat app/chat --flat --dry-run
nest g gateway chat app/chat --flat --dry-run

# scaffold notifications module
nest g module app/notifications --dry-run
nest g controller notification app/notifications --dry-run
nest g service notification app/notifications --dry-run
nest g service notification/push app/notifications --flat --no-spec --dry-run
nest g class notification/notification.entity app/notifications --no-spec --dry-run
nest g controller subscription app/notifications --dry-run
nest g service subscription app/notifications --dry-run
nest g class subscription/subscription.entity app/notifications --no-spec --dry-run
```

### Ref
Expand Down
16 changes: 6 additions & 10 deletions apps/api/README.md
Expand Up @@ -84,16 +84,12 @@ npm run api:build
# check of nest installed
nest info

# scaffold project module
nest generate module project --dry-run
nest generate controller project --dry-run
nest generate service project project --dry-run
nest generate class project --dry-run

# scaffold core module
nest g module core --dry-run
nest g guard auth core --dry-run
nest g exception auth --dry-run
# scaffold auth module
nest g module app/auth --dry-run
nest g controller auth app/auth --flat --dry-run
nest g service auth app/auth --flat --dry-run
nest g class user.entity app/auth --no-spec --dry-run
nest g class auth.exception app/auth --no-spec --dry-run
```

### Test
Expand Down
5 changes: 1 addition & 4 deletions apps/api/src/app/app.module.ts
Expand Up @@ -7,7 +7,6 @@ import { UserModule } from './user';
// import { ChatModule } from './chat';
import { AppController } from './app.controller';
import { NotificationsModule } from './notifications';
import { PushModule } from './push';
import { ExternalModule } from './external';

@Module({
Expand All @@ -18,9 +17,8 @@ import { ExternalModule } from './external';
children: [
{ path: '/auth', module: AuthModule },
{ path: '/user', module: UserModule },
{ path: '/push', module: PushModule },
// { path: '/account', module: AccountModule },
{ path: '/notifications', module: NotificationsModule },
{ path: '/', module: NotificationsModule },
],
},
{ path: '/external', module: ExternalModule },
Expand All @@ -32,7 +30,6 @@ import { ExternalModule } from './external';
// ChatModule,
ExternalModule,
NotificationsModule,
PushModule,
],
controllers: [AppController],
})
Expand Down
8 changes: 4 additions & 4 deletions apps/api/src/app/core/core.module.ts
Expand Up @@ -7,10 +7,10 @@ import { LoggingInterceptor, TransformInterceptor } from './interceptors';
import { RequestContextMiddleware } from './context';
import { ConfigService } from '../config';
import { ConnectionOptions } from 'typeorm';
import { Notification } from '../notifications/notification.entity';
import { User } from '../auth/user.entity';
import { environment as env } from '@env-api/environment';
import { Subscription } from '../push/subscription.entity';
import { User } from '../auth/user.entity';
import { Notification } from '../notifications/notification/notification.entity';
import { Subscription } from '../notifications/subscription/subscription.entity';

@Module({
imports: [
Expand All @@ -21,7 +21,7 @@ import { Subscription } from '../push/subscription.entity';
useFactory: async (config: ConfigService) =>
({
...env.database,
entities: [Notification, User, Subscription],
entities: [User, Notification, Subscription],
} as ConnectionOptions),
inject: [ConfigService],
}),
Expand Down
39 changes: 0 additions & 39 deletions apps/api/src/app/notifications/dto/create-notification.dto.ts

This file was deleted.

@@ -1,10 +1,15 @@
// Actions
export class AddNotification {
static readonly type = '[Notifications] Add';
constructor(public readonly payload: any) {}
}

export class DeleteNotification {
static readonly type = '[Notifications] Delete';
constructor(public readonly payload: any) {}
}

export class MarkAsRead {
static readonly type = '[Notifications] MarkAsRead';
constructor(public readonly payload: any) {}
}

export class MarkAllAsRead {
static readonly type = '[Notifications] MarkAllAsRead';
}
67 changes: 0 additions & 67 deletions apps/api/src/app/notifications/notification.entity.ts

This file was deleted.

@@ -0,0 +1,42 @@
import { ApiModelProperty, ApiModelPropertyOptional } from '@nestjs/swagger';
import { IsAscii, IsBoolean, IsEnum, IsNotEmpty, IsOptional, IsString, MaxLength, MinLength } from 'class-validator';
import { NotificationColor, NotificationIcon, TargetType } from '../notification.entity';

export class CreateNotificationDto {
@ApiModelProperty({ type: String, minLength: 10, maxLength: 100 })
@IsNotEmpty()
@IsString()
readonly title: string;

@ApiModelProperty({ type: String, minLength: 10, maxLength: 100 })
@IsNotEmpty()
@IsString()
readonly body: string;

@ApiModelProperty({ type: String, minLength: 3, maxLength: 50 })
@IsNotEmpty()
@IsAscii()
@MinLength(3)
@MaxLength(50)
readonly target: string;

@ApiModelProperty({ type: String, enum: TargetType })
@IsNotEmpty()
@IsEnum(TargetType)
readonly targetType: TargetType;

@ApiModelPropertyOptional({ type: String, enum: NotificationIcon, default: NotificationIcon.notifications })
@IsOptional()
@IsEnum(NotificationIcon)
readonly icon?: NotificationIcon;

@ApiModelPropertyOptional({ type: String, enum: NotificationColor, default: NotificationColor.PRIMARY })
@IsOptional()
@IsEnum(NotificationColor)
readonly color?: NotificationColor;

@ApiModelPropertyOptional({ type: Boolean, default: false })
@IsOptional()
@IsBoolean()
readonly native?: boolean;
}
@@ -0,0 +1,14 @@
import { ApiModelProperty, ApiModelPropertyOptional } from '@nestjs/swagger';
import { IsNotEmpty, IsOptional, IsString } from 'class-validator';

export class SendNotificationDto {
@ApiModelProperty({ type: String })
@IsNotEmpty()
@IsString()
id: string;

@ApiModelPropertyOptional({ type: String })
@IsOptional()
@IsString()
target?: string;
}
@@ -0,0 +1,22 @@
import { Test, TestingModule } from '@nestjs/testing';
import { NotificationController } from './notification.controller';
import { NotificationService } from './notification.service';

describe('Notification Controller', () => {
let module: TestingModule;
beforeAll(async () => {
module = await Test.createTestingModule({
controllers: [NotificationController],
providers: [
{
provide: NotificationService,
useValue: {}, // TODO: Mock
},
],
}).compile();
});
it('should be defined', () => {
const controller: NotificationController = module.get<NotificationController>(NotificationController);
expect(controller).toBeDefined();
});
});

0 comments on commit 2d85fd3

Please sign in to comment.