Skip to content

Commit 4710cbb

Browse files
committed
feat(api): now using built-in ParseUUIDPipe
nextjs libs updated, now using ParseUUIDPipe
1 parent 01ecc18 commit 4710cbb

File tree

14 files changed

+1275
-832
lines changed

14 files changed

+1275
-832
lines changed

apps/api/package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414
},
1515
"dependencies": {
1616
"@godaddy/terminus": "^4.1.2",
17-
"@nestjs/common": "^6.3.0",
18-
"@nestjs/core": "^6.3.0",
17+
"@nestjs/common": "^6.3.2",
18+
"@nestjs/core": "^6.3.2",
1919
"@nestjs/cqrs": "^6.0.0",
2020
"@nestjs/passport": "^6.1.0",
21-
"@nestjs/platform-express": "^6.3.0",
22-
"@nestjs/platform-socket.io": "^6.3.0",
21+
"@nestjs/platform-express": "^6.3.2",
22+
"@nestjs/platform-socket.io": "^6.3.2",
2323
"@nestjs/swagger": "^3.0.0",
24-
"@nestjs/terminus": "^6.3.0",
24+
"@nestjs/terminus": "^6.3.4",
2525
"@nestjs/typeorm": "^6.1.2",
26-
"@nestjs/websockets": "^6.3.0",
27-
"@nestjsx/crud": "^4.0.0",
26+
"@nestjs/websockets": "^6.3.2",
27+
"@nestjsx/crud": "^4.1.0",
2828
"@xmlking/jwks-rsa": "^1.4.3",
2929
"cache-manager": "^2.9.1",
3030
"class-transformer": "^0.2.3",
@@ -58,7 +58,7 @@
5858
},
5959
"optionalDependencies": {
6060
"@nestjs/schematics": "^6.2.0",
61-
"@nestjs/testing": "^6.3.0",
61+
"@nestjs/testing": "^6.3.2",
6262
"nodemon": "^1.19.1",
6363
"supertest": "^4.0.0"
6464
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Module } from '@nestjs/common';
1+
import { Module, HttpModule } from '@nestjs/common';
22
import { RouterModule } from 'nest-router';
33
import { CoreModule } from './core';
44
import { AuthModule } from './auth';
@@ -28,6 +28,7 @@ import { AppHealthService } from './app-health.service';
2828
},
2929
{ path: '/external', module: ExternalModule },
3030
]),
31+
HttpModule,
3132
CoreModule,
3233
CacheModule,
3334
AuthModule,

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
import { HttpModule, Module } from '@nestjs/common';
1+
import { forwardRef, HttpModule, Module, CacheModule } from '@nestjs/common';
22
import { SharedModule } from '../shared';
33
import { WeatherController } from './weather/weather.controller';
44
import { WeatherService } from './weather/weather.service';
55

66
@Module({
7-
imports: [SharedModule, HttpModule.register({ timeout: 5000 })],
7+
imports: [
8+
SharedModule,
9+
HttpModule.register({ timeout: 5000 }),
10+
CacheModule.register({
11+
ttl: 60, // seconds
12+
max: 10, // maximum number of items in cache
13+
}),
14+
],
815
providers: [WeatherService],
916
controllers: [WeatherController],
1017
})

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Body, Controller, Delete, Get, HttpStatus, Param, Post, Put, Query } from '@nestjs/common';
1+
import { Body, Controller, Delete, Get, HttpStatus, Param, ParseUUIDPipe, Post, Put, Query } from '@nestjs/common';
22
import { CrudController } from '../../core';
33
import { ApiExcludeEndpoint, ApiOAuth2Auth, ApiOperation, ApiResponse, ApiUseTags } from '@nestjs/swagger';
44
import { Notification } from './notification.entity';
@@ -11,7 +11,6 @@ import { NotificationList } from './dto/notification-list.model';
1111
import { FindNotificationsDto } from './dto/find-notifications.dto';
1212
import { FindOwnNotificationsDto } from './dto/find-own-notifications.dto';
1313
import { User } from '@ngx-starter-kit/models';
14-
import { UUIDValidationPipe } from '../../shared';
1514

1615
@ApiOAuth2Auth(['read'])
1716
@ApiUseTags('Notifications')
@@ -34,7 +33,7 @@ export class NotificationController extends CrudController<Notification> {
3433
return this.notificationService.findAll(filter);
3534
}
3635

37-
@ApiOperation({ title: "find user's and global Notifications" })
36+
@ApiOperation({ title: "find user's and global Notifications" }) // tslint:disable-line
3837
@ApiResponse({ status: HttpStatus.OK, description: 'Find matching Notifications', type: NotificationList })
3938
@ApiResponse({ status: HttpStatus.NOT_FOUND, description: 'No matching records found' })
4039
@Get('own')
@@ -49,7 +48,7 @@ export class NotificationController extends CrudController<Notification> {
4948
@ApiUseTags('Admin')
5049
@Roles(RolesEnum.ADMIN)
5150
@Get(':id')
52-
async findById(@Param('id', UUIDValidationPipe) id: string): Promise<Notification> {
51+
async findById(@Param('id', new ParseUUIDPipe({ version: '4' })) id: string): Promise<Notification> {
5352
return super.findById(id);
5453
}
5554

apps/api/src/app/project/project.controller.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
import { Body, Controller, Get, HttpCode, HttpStatus, Logger, Param, Post, Put, Query } from '@nestjs/common';
1+
import {
2+
Body,
3+
Controller,
4+
Get,
5+
HttpCode,
6+
HttpStatus,
7+
Logger,
8+
Param,
9+
ParseUUIDPipe,
10+
Post,
11+
Put,
12+
Query,
13+
} from '@nestjs/common';
214
import { ApiOAuth2Auth, ApiOperation, ApiResponse, ApiUseTags } from '@nestjs/swagger';
315
import { ProjectService } from './project.service';
416
import { KubernetesService } from './kubernetes/kubernetes.service';
@@ -11,7 +23,7 @@ import { UpdateProjectDto } from './dto/update-project.dto';
1123
import { FindOwnProjectsDto } from './dto/find-own-projects.dto';
1224
import { ProjectList } from './dto/project-list.model';
1325
import { FindProjectsDto } from './dto/find-projects.dto';
14-
import { ORMQuery, UUIDValidationPipe } from '../shared';
26+
import { ORMQuery } from '../shared';
1527
import { User } from '@ngx-starter-kit/models';
1628

1729
@ApiOAuth2Auth(['read'])
@@ -97,7 +109,10 @@ export class ProjectController extends CrudController<Project> {
97109
description: 'Invalid input, The response body may contain clues as to what went wrong',
98110
})
99111
@Put(':id')
100-
async update(@Param('id', UUIDValidationPipe) id: string, @Body() entity: UpdateProjectDto): Promise<any> {
112+
async update(
113+
@Param('id', new ParseUUIDPipe({ version: '4' })) id: string,
114+
@Body() entity: UpdateProjectDto,
115+
): Promise<any> {
101116
// TODO check if owner
102117
return super.update(id, entity);
103118
}

apps/api/src/app/shared/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export * from './shared.module';
22
export { CQRSGateway } from './cqrs.gateway';
3-
export { UUIDValidationPipe } from './pipes/uuid-validation.pipe';
43
export { ORMQuery } from './decorators/orm-query';
54
export { GenericCommand } from './commands/generic.command';
65
export { GenericEvent } from './events/generic.event';

apps/api/src/app/shared/pipes/.gitkeep

Whitespace-only changes.

apps/api/src/app/shared/pipes/uuid-validation.pipe.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { Module } from '@nestjs/common';
1+
import { Module, ParseUUIDPipe } from '@nestjs/common';
22
import { CqrsModule } from '@nestjs/cqrs';
33
import { CQRSGateway } from './cqrs.gateway';
4-
import { UUIDValidationPipe } from './pipes/uuid-validation.pipe';
54
import { AuthModule } from '../auth';
65

76
@Module({
87
imports: [CqrsModule, AuthModule],
9-
providers: [CQRSGateway, UUIDValidationPipe],
10-
exports: [CQRSGateway, UUIDValidationPipe],
8+
providers: [CQRSGateway],
9+
exports: [CQRSGateway],
1110
})
1211
export class SharedModule {}

apps/api/src/app/user/profile/profile.controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
HttpStatus,
99
NotFoundException,
1010
Param,
11+
ParseUUIDPipe,
1112
Post,
1213
Put,
1314
UploadedFile,
@@ -23,7 +24,6 @@ import { ProfileService } from './profile.service';
2324
import { ProfileList } from './dto/profile-list.model';
2425
import { User } from '../user.entity';
2526
// UserModule -> SharedModule -> AuthModule -> UserModule, so
26-
import { UUIDValidationPipe } from '../../shared/pipes/uuid-validation.pipe';
2727

2828
const ALLOWED_MIME_TYPES = ['image/gif', 'image/png', 'image/jpeg', 'image/bmp', 'image/webp'];
2929

@@ -68,7 +68,7 @@ export class ProfileController extends CrudController<Profile> {
6868
@ApiUseTags('Admin')
6969
@Roles(RolesEnum.ADMIN)
7070
@Get(':id')
71-
async findById(@Param('id', UUIDValidationPipe) id: string): Promise<Profile> {
71+
async findById(@Param('id', new ParseUUIDPipe({ version: '4' })) id: string): Promise<Profile> {
7272
console.log('in findById', id);
7373
return this.profileService.findOne(id);
7474
}

0 commit comments

Comments
 (0)