Skip to content

Commit

Permalink
feat(api): now using built-in ParseUUIDPipe
Browse files Browse the repository at this point in the history
nextjs libs updated, now using ParseUUIDPipe
  • Loading branch information
xmlking committed Jun 29, 2019
1 parent 01ecc18 commit 4710cbb
Show file tree
Hide file tree
Showing 14 changed files with 1,275 additions and 832 deletions.
16 changes: 8 additions & 8 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
},
"dependencies": {
"@godaddy/terminus": "^4.1.2",
"@nestjs/common": "^6.3.0",
"@nestjs/core": "^6.3.0",
"@nestjs/common": "^6.3.2",
"@nestjs/core": "^6.3.2",
"@nestjs/cqrs": "^6.0.0",
"@nestjs/passport": "^6.1.0",
"@nestjs/platform-express": "^6.3.0",
"@nestjs/platform-socket.io": "^6.3.0",
"@nestjs/platform-express": "^6.3.2",
"@nestjs/platform-socket.io": "^6.3.2",
"@nestjs/swagger": "^3.0.0",
"@nestjs/terminus": "^6.3.0",
"@nestjs/terminus": "^6.3.4",
"@nestjs/typeorm": "^6.1.2",
"@nestjs/websockets": "^6.3.0",
"@nestjsx/crud": "^4.0.0",
"@nestjs/websockets": "^6.3.2",
"@nestjsx/crud": "^4.1.0",
"@xmlking/jwks-rsa": "^1.4.3",
"cache-manager": "^2.9.1",
"class-transformer": "^0.2.3",
Expand Down Expand Up @@ -58,7 +58,7 @@
},
"optionalDependencies": {
"@nestjs/schematics": "^6.2.0",
"@nestjs/testing": "^6.3.0",
"@nestjs/testing": "^6.3.2",
"nodemon": "^1.19.1",
"supertest": "^4.0.0"
}
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Module } from '@nestjs/common';
import { Module, HttpModule } from '@nestjs/common';
import { RouterModule } from 'nest-router';
import { CoreModule } from './core';
import { AuthModule } from './auth';
Expand Down Expand Up @@ -28,6 +28,7 @@ import { AppHealthService } from './app-health.service';
},
{ path: '/external', module: ExternalModule },
]),
HttpModule,
CoreModule,
CacheModule,
AuthModule,
Expand Down
11 changes: 9 additions & 2 deletions apps/api/src/app/external/external.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { HttpModule, Module } from '@nestjs/common';
import { forwardRef, HttpModule, Module, CacheModule } from '@nestjs/common';
import { SharedModule } from '../shared';
import { WeatherController } from './weather/weather.controller';
import { WeatherService } from './weather/weather.service';

@Module({
imports: [SharedModule, HttpModule.register({ timeout: 5000 })],
imports: [
SharedModule,
HttpModule.register({ timeout: 5000 }),
CacheModule.register({
ttl: 60, // seconds
max: 10, // maximum number of items in cache
}),
],
providers: [WeatherService],
controllers: [WeatherController],
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Body, Controller, Delete, Get, HttpStatus, Param, Post, Put, Query } from '@nestjs/common';
import { Body, Controller, Delete, Get, HttpStatus, Param, ParseUUIDPipe, Post, Put, Query } from '@nestjs/common';
import { CrudController } from '../../core';
import { ApiExcludeEndpoint, ApiOAuth2Auth, ApiOperation, ApiResponse, ApiUseTags } from '@nestjs/swagger';
import { Notification } from './notification.entity';
Expand All @@ -11,7 +11,6 @@ import { NotificationList } from './dto/notification-list.model';
import { FindNotificationsDto } from './dto/find-notifications.dto';
import { FindOwnNotificationsDto } from './dto/find-own-notifications.dto';
import { User } from '@ngx-starter-kit/models';
import { UUIDValidationPipe } from '../../shared';

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

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

Expand Down
21 changes: 18 additions & 3 deletions apps/api/src/app/project/project.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
import { Body, Controller, Get, HttpCode, HttpStatus, Logger, Param, Post, Put, Query } from '@nestjs/common';
import {
Body,
Controller,
Get,
HttpCode,
HttpStatus,
Logger,
Param,
ParseUUIDPipe,
Post,
Put,
Query,
} from '@nestjs/common';
import { ApiOAuth2Auth, ApiOperation, ApiResponse, ApiUseTags } from '@nestjs/swagger';
import { ProjectService } from './project.service';
import { KubernetesService } from './kubernetes/kubernetes.service';
Expand All @@ -11,7 +23,7 @@ import { UpdateProjectDto } from './dto/update-project.dto';
import { FindOwnProjectsDto } from './dto/find-own-projects.dto';
import { ProjectList } from './dto/project-list.model';
import { FindProjectsDto } from './dto/find-projects.dto';
import { ORMQuery, UUIDValidationPipe } from '../shared';
import { ORMQuery } from '../shared';
import { User } from '@ngx-starter-kit/models';

@ApiOAuth2Auth(['read'])
Expand Down Expand Up @@ -97,7 +109,10 @@ export class ProjectController extends CrudController<Project> {
description: 'Invalid input, The response body may contain clues as to what went wrong',
})
@Put(':id')
async update(@Param('id', UUIDValidationPipe) id: string, @Body() entity: UpdateProjectDto): Promise<any> {
async update(
@Param('id', new ParseUUIDPipe({ version: '4' })) id: string,
@Body() entity: UpdateProjectDto,
): Promise<any> {
// TODO check if owner
return super.update(id, entity);
}
Expand Down
1 change: 0 additions & 1 deletion apps/api/src/app/shared/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export * from './shared.module';
export { CQRSGateway } from './cqrs.gateway';
export { UUIDValidationPipe } from './pipes/uuid-validation.pipe';
export { ORMQuery } from './decorators/orm-query';
export { GenericCommand } from './commands/generic.command';
export { GenericEvent } from './events/generic.event';
Empty file.
30 changes: 0 additions & 30 deletions apps/api/src/app/shared/pipes/uuid-validation.pipe.ts

This file was deleted.

7 changes: 3 additions & 4 deletions apps/api/src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Module } from '@nestjs/common';
import { Module, ParseUUIDPipe } from '@nestjs/common';
import { CqrsModule } from '@nestjs/cqrs';
import { CQRSGateway } from './cqrs.gateway';
import { UUIDValidationPipe } from './pipes/uuid-validation.pipe';
import { AuthModule } from '../auth';

@Module({
imports: [CqrsModule, AuthModule],
providers: [CQRSGateway, UUIDValidationPipe],
exports: [CQRSGateway, UUIDValidationPipe],
providers: [CQRSGateway],
exports: [CQRSGateway],
})
export class SharedModule {}
4 changes: 2 additions & 2 deletions apps/api/src/app/user/profile/profile.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
HttpStatus,
NotFoundException,
Param,
ParseUUIDPipe,
Post,
Put,
UploadedFile,
Expand All @@ -23,7 +24,6 @@ import { ProfileService } from './profile.service';
import { ProfileList } from './dto/profile-list.model';
import { User } from '../user.entity';
// UserModule -> SharedModule -> AuthModule -> UserModule, so
import { UUIDValidationPipe } from '../../shared/pipes/uuid-validation.pipe';

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

Expand Down Expand Up @@ -68,7 +68,7 @@ export class ProfileController extends CrudController<Profile> {
@ApiUseTags('Admin')
@Roles(RolesEnum.ADMIN)
@Get(':id')
async findById(@Param('id', UUIDValidationPipe) id: string): Promise<Profile> {
async findById(@Param('id', new ParseUUIDPipe({ version: '4' })) id: string): Promise<Profile> {
console.log('in findById', id);
return this.profileService.findOne(id);
}
Expand Down
11 changes: 9 additions & 2 deletions apps/api/test-rest-api-vs-code.http
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@ Authorization: Bearer {{authToken}}

{"title":"test123","body":"test12345","target":"sumo-topic","targetType":"topic","icon":"notifications","color":"warn","native":true}

### Test get notifications
# @name getNotification
### Test list notifications
# @name listNotifications
GET {{api-url}}/api/notifications
Accept: application/json
Authorization: Bearer {{authToken}}

@firstNotificationId = {{listNotifications.response.body.items[0].id}}

### Test findById notification
# @name findByIdNotification
GET {{api-url}}/api/notifications/{{firstNotificationId}}
Accept: application/json
Authorization: Bearer {{authToken}}

### Test send notification
# @name sendNotification
Expand Down
13 changes: 12 additions & 1 deletion apps/api/test-rest-api.http
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,22 @@ Authorization: Bearer {{access_token}}

{"title":"test123","body":"test12345","target":"sumo-topic","targetType":"topic","icon":"notifications","color":"warn","native":true}

### Test get notifications
### Test list notifications
GET {{api-url}}/api/notifications
Accept: application/json
Authorization: Bearer {{access_token}}

> {%
client.global.set("firstNotificationId", response.body.items[0].id);
client.log("firstNotificationId: " + response.body.items[0].id );
client.assert(response.status === 200, "Response status is not 200");
%}

### Test findById notification
# @name findByIdNotification
GET {{api-url}}/api/notifications/{{firstNotificationId}}
Accept: application/json
Authorization: Bearer {{access_token}}

### Test send notification
POST {{api-url}}/api/notifications/send
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
"@ngx-lite/in-viewport": "^0.1.3",
"@ngx-lite/input-star-rating": "^0.3.5",
"@ngx-lite/input-tag": "^0.4.8",
"@ngxs-labs/immer-adapter": "^3.0.3",
"@ngxs-labs/immer-adapter": "^3.0.5",
"@ngxs/devtools-plugin": "^3.4.3",
"@ngxs/form-plugin": "^3.4.3",
"@ngxs/router-plugin": "^3.4.3",
Expand Down Expand Up @@ -221,6 +221,7 @@
"webpack-bundle-analyzer": "^3.3.0"
},
"resolutions": {
"d3-selection": "1.3.0"
"d3-selection": "1.3.0",
"webpack-sources": "1.0.1"
}
}
Loading

0 comments on commit 4710cbb

Please sign in to comment.