Skip to content

Commit

Permalink
feat(api): enhanced search options for projects
Browse files Browse the repository at this point in the history
  • Loading branch information
xmlking committed Apr 6, 2019
1 parent 92add74 commit f34a3bf
Show file tree
Hide file tree
Showing 35 changed files with 6,397 additions and 4,838 deletions.
2 changes: 2 additions & 0 deletions .deploy/api/Dockerfile
Expand Up @@ -22,7 +22,9 @@ COPY --from=dev-dependencies /app /app
COPY apps/api apps/api
COPY libs/models libs/models
COPY libs/utils libs/utils
COPY tools/hooks/api.webpack.js tools/hooks/api.webpack.js
COPY angular.json nx.json tsconfig.json ./
RUN npm i typescript@3.1.6
ENV NODE_ENV production
RUN $(npm bin)/ng build api --prod

Expand Down
2 changes: 1 addition & 1 deletion .deploy/api/README.md
Expand Up @@ -6,7 +6,7 @@ Build and Deploy NgxApi

```bash
# build
VERSION=1.5.0-SNAPSHOT
VERSION=2.0.0-SNAPSHOT
docker build \
--no-cache \
--build-arg VERSION=$VERSION \
Expand Down
2 changes: 1 addition & 1 deletion .deploy/api/helm/values-dev.yaml
Expand Up @@ -3,7 +3,7 @@ test:

image:
repository: xmlking/ngxapi
tag: 1.5.0-SNAPSHOT
tag: 2.0.0-SNAPSHOT
pullPolicy: IfNotPresent

securityContext:
Expand Down
2 changes: 1 addition & 1 deletion .deploy/api/helm/values-prod.yaml
Expand Up @@ -11,7 +11,7 @@ resources:

image:
repository: xmlking/ngxapi
tag: 1.5.0-SNAPSHOT
tag: 2.0.0-SNAPSHOT
pullPolicy: IfNotPresent

securityContext:
Expand Down
2 changes: 1 addition & 1 deletion .deploy/webapp/README.md
Expand Up @@ -8,7 +8,7 @@ Build and Deploy NgxApp webapp.

```bash
# build
VERSION=1.5.0-SNAPSHOT
VERSION=2.0.0-SNAPSHOT
docker build \
--no-cache \
--build-arg VERSION=$VERSION \
Expand Down
2 changes: 1 addition & 1 deletion .deploy/webapp/helm/values-dev.yaml
Expand Up @@ -3,7 +3,7 @@ test:

image:
repository: xmlking/ngxapp
tag: 1.5.0-SNAPSHOT
tag: 2.0.0-SNAPSHOT
pullPolicy: IfNotPresent

securityContext:
Expand Down
2 changes: 1 addition & 1 deletion .deploy/webapp/helm/values-prod.yaml
Expand Up @@ -11,7 +11,7 @@ resources:

image:
repository: xmlking/ngxapp
tag: 1.5.0-SNAPSHOT
tag: 2.0.0-SNAPSHOT
pullPolicy: IfNotPresent

securityContext:
Expand Down
2 changes: 1 addition & 1 deletion .editorconfig
@@ -1,4 +1,4 @@
# Editor configuration, see http://editorconfig.org
# Editor configuration, see https://editorconfig.org
root = true

[*]
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -4,7 +4,8 @@
/dist
/tmp
/out-tsc
report.*.json
# Only exists if Bazel was run
/bazel-out

# dependencies
/node_modules
Expand Down
82 changes: 41 additions & 41 deletions PLAYBOOK-NEST.md
Expand Up @@ -65,63 +65,62 @@ npm i -D @types/helmet

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

nest g module app/core -d
nest g guard auth app/core -d

# scaffold shared module
nest g module app/shared --dry-run
nest g gateway eventbus app/shared --dry-run
nest g module app/shared -d
nest g gateway eventbus app/shared -d

# scaffold user module
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
nest g module app/user -d
nest g class user.entity app/user --no-spec -d
nest g controller user app -d
nest g service user app -d
nest g controller profile app/user -d
nest g service profile app/user -d
nest g class profile/profile.entity app/user --no-spec -d
nest g controller email app/user -d

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

# 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
nest g module app/auth -d
nest g class auth.exception app/auth --no-spec -d

# scaffold chat module
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
nest g module app/chat -d
nest g controller chat app/chat --flat -d
nest g service chat app/chat --flat -d
nest g gateway chat app/chat --flat -d

# scaffold external module
nest g module app/external --dry-run
nest g controller weather app/external --dry-run
nest g service weather app/external --dry-run
nest g module app/external -d
nest g controller weather app/external -d
nest g service weather app/external -d

# scaffold project module
nest g module app/project --dry-run
nest g controller kubernetes app/project --dry-run
nest g service kubernetes app/project --dry-run
nest g class cluster/cluster.entity app/project --no-spec --dry-run
nest g controller cluster app/project --dry-run
nest g service cluster app/project --dry-run
nest g class project.entity app/project --no-spec --dry-run
nest g controller project app --dry-run
nest g service project app --dry-run
nest g module app/project -d
nest g controller kubernetes app/project -d
nest g service kubernetes app/project -d
nest g class cluster/cluster.entity app/project --no-spec -d
nest g controller cluster app/project -d
nest g service cluster app/project -d
nest g class project.entity app/project --no-spec -d
nest g controller project app -d
nest g service project app -d

# 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
nest g module app/notifications -d
nest g controller notification app/notifications -d
nest g service notification app/notifications -d
nest g service notification/push app/notifications --flat --no-spec -d
nest g class notification/notification.entity app/notifications --no-spec -d
nest g controller subscription app/notifications -d
nest g service subscription app/notifications -d
nest g class subscription/subscription.entity app/notifications --no-spec -d

You could also use `ng g` if you `npm i -D @nestjs/schematics`
ng g @nestjs/schematics:module game --path app --source-root apps/api/src -d
Expand All @@ -139,3 +138,4 @@ ng g @nestjs/schematics:class match/match.entity --path app/game --source-root a
- https://github.com/beeman/nest-angular-nx
- https://github.com/cgatian/customer-portal
- http://blog.exceptionfound.com/index.php/2018/06/07/nestjs-basic-auth-and-sessions/
- https://github.com/TorinAsakura/etl-api
9 changes: 6 additions & 3 deletions PLAYBOOK.md
Expand Up @@ -8,8 +8,8 @@ Do-it-yourself step-by-step instructions to create this project structure from s
| Software | Version | Optional |
| -------------------- | -------- | -------- |
| Node | v11.11.0 | |
| NPM | v6.9.0 | |
| Node | v11.13.0 | |
| NPM | v6.7.0 | |
| Angular CLI | v8.0.0 | |
| @nrwl/schematics | v7.7.2 | |
| @nestjs/cli | v6.0.0 | |
Expand Down Expand Up @@ -262,6 +262,7 @@ ng g lib utils --framework=none --publishable=true --tags=utils --unit-test-runn
# system wide `models` module
ng g lib models --framework=none --tags=utils --unit-test-runner=jest -d
ng g interface User --project=models --type=model -d
ng g interface JwtToken --project=models --type=model -d
ng g interface Profile --project=models --type=model -d
ng g interface Image --project=models --type=model -d
ng g enum ImageType --project=models -d
Expand Down Expand Up @@ -554,7 +555,7 @@ ng update --all
ng xi18n --output-path apps/webapp/src/local

ng build api
# start with hugh memory
# start with hugh memory
node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build api --prod
```

Expand All @@ -581,11 +582,13 @@ docker-compose up web
```

### Uint Test

```bash
ng test <module>
```

### E2E Test

```bash
ng e2e webapp-e2e
# headless tests (CI)
Expand Down
4 changes: 2 additions & 2 deletions angular.json
Expand Up @@ -4,7 +4,7 @@
"newProjectRoot": "",
"projects": {
"webapp": {
"root": "apps/webapp",
"root": "apps/webapp/",
"sourceRoot": "apps/webapp/src",
"projectType": "application",
"prefix": "ngx",
Expand Down Expand Up @@ -252,7 +252,7 @@
"with": "apps/api/src/environments/environment.prod.ts"
}
],
webpackConfig: 'tools/hooks/custom.webpack.js',
"webpackConfig": "tools/hooks/api.webpack.js",
"externalDependencies": "all"
}
}
Expand Down
15 changes: 7 additions & 8 deletions apps/api/src/app/project/cluster/cluster.entity.ts
Expand Up @@ -2,23 +2,22 @@ import { Column, Entity, Index, OneToMany, RelationId } from 'typeorm';
import { ApiModelProperty } from '@nestjs/swagger';
import { Exclude } from 'class-transformer';
import { IsAscii, IsNotEmpty, IsUrl } from 'class-validator';
import { AuditBase } from '../../core/entities/audit-base.entity';
import { AuditBase } from '../../core/entities/audit-base';
import { Project } from '../project.entity';
import { Cluster as ICluster } from '@ngx-starter-kit/models';

@Entity('cluster')
export class Cluster extends AuditBase implements ICluster {

@ApiModelProperty({ type: String, minLength: 3, maxLength: 15 })
@IsNotEmpty()
@IsAscii()
@Index({ unique: true })
@Column({length: 15 })
@Column({ length: 15 })
name: string;

@ApiModelProperty({ type: String, minLength: 3, maxLength: 6 })
@IsNotEmpty()
@Column({length: 6 })
@Column({ length: 6 })
ver: string;

@ApiModelProperty({ type: String, minLength: 10, maxLength: 256 })
Expand All @@ -37,11 +36,11 @@ export class Cluster extends AuditBase implements ICluster {
@OneToMany(_ => Project, project => project.cluster)
projects?: Project[];

@ApiModelProperty({ type: Number, readOnly: true })
@ApiModelProperty({ type: String, readOnly: true })
@RelationId((cluster: Cluster) => cluster.createdBy)
readonly createdById?: number;
readonly createdById?: string;

@ApiModelProperty({ type: Number, readOnly: true })
@ApiModelProperty({ type: String, readOnly: true })
@RelationId((cluster: Cluster) => cluster.updatedBy)
readonly updatedById?: number;
readonly updatedById?: string;
}
2 changes: 1 addition & 1 deletion apps/api/src/app/project/cluster/dto/create-cluster.dto.ts
Expand Up @@ -17,7 +17,7 @@ export class CreateClusterDto {

@ApiModelProperty({ type: String, minLength: 10, maxLength: 256 })
@IsNotEmpty()
@IsUrl()
@IsUrl({ require_tld: false })
@MinLength(10)
@MaxLength(256)
baseUrl: string;
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/app/project/cluster/dto/update-cluster.dto.ts
Expand Up @@ -10,7 +10,7 @@ export class UpdateClusterDto {

@ApiModelPropertyOptional({ type: String, minLength: 10, maxLength: 256 })
@IsOptional()
@IsUrl()
@IsUrl({ require_tld: false })
@MinLength(10)
@MaxLength(256)
baseUrl?: string;
Expand Down
16 changes: 15 additions & 1 deletion apps/api/src/app/project/dto/create-project.dto.ts
@@ -1,8 +1,20 @@
import { ArrayUnique, IsAscii, IsEmail, IsNotEmpty, IsOptional, IsString, Length, Matches, ValidateNested } from 'class-validator';
import {
ArrayUnique,
IsAscii,
IsEmail,
IsNotEmpty,
IsOptional,
IsString,
Length,
Matches,
Validate,
ValidateNested,
} from 'class-validator';
import { ApiModelProperty, ApiModelPropertyOptional } from '@nestjs/swagger';
import { Labels } from './labels.dto';
import { Type } from 'class-transformer';
import { ResourceQuota } from './resource-quota';
import { IsNamespaceUnique } from '../validators';

export class CreateProjectDto {
@ApiModelProperty({ type: String })
Expand All @@ -17,13 +29,15 @@ export class CreateProjectDto {

@ApiModelProperty({ type: String })
@IsString()
@IsNotEmpty()
readonly clusterName: string;

@ApiModelProperty({ type: String, minLength: 5, maxLength: 100 })
@IsAscii()
@IsNotEmpty()
@Length(5, 100)
@Matches(/^[a-z\d-]+$/)
@IsNamespaceUnique()
readonly namespace: string;

@ApiModelProperty({ type: String, minLength: 5, maxLength: 100 })
Expand Down
18 changes: 13 additions & 5 deletions apps/api/src/app/project/dto/find-projects.dto.ts
@@ -1,10 +1,19 @@
import { OrderType, PaginationParams } from '../../core';
import { User } from '../../auth';
import { Project } from '../project.entity';
import { ArrayUnique, IsAscii, IsBoolean, IsOptional, IsString, Length, Matches, ValidateNested } from 'class-validator';
import {
ArrayUnique,
IsAscii,
IsBoolean,
IsOptional,
IsString,
Length,
Matches,
ValidateNested,
} from 'class-validator';
import { ApiModelPropertyOptional } from '@nestjs/swagger';
import { Labels } from './labels.dto';
import { Transform, Type } from 'class-transformer';
import { User } from '../../user';

export class FindProjectsDto extends PaginationParams<Project> {
@ApiModelPropertyOptional({ type: String })
Expand All @@ -25,7 +34,7 @@ export class FindProjectsDto extends PaginationParams<Project> {
@IsOptional()
@ArrayUnique()
@IsString({ each: true })
@Transform(value => value ? value.split(',') : [])
@Transform(value => (value ? value.split(',') : []))
readonly groups?: string[];

@ApiModelPropertyOptional({ type: String })
Expand All @@ -49,12 +58,11 @@ export class FindProjectsDto extends PaginationParams<Project> {
readonly labels?: Labels;

@ApiModelPropertyOptional({ type: Boolean, default: true })
@Transform((val: string) => ( val === 'true' ))
@Transform((val: string) => val === 'true')
@IsOptional()
@IsBoolean()
readonly isActive = true;


@ApiModelPropertyOptional({ type: String, enum: ['ASC', 'DESC'] })
@IsOptional()
@Transform((val: string) => ({ createdAt: val === OrderType.ASC ? OrderType.ASC : OrderType.DESC }))
Expand Down
1 change: 1 addition & 0 deletions apps/api/src/app/project/index.ts
@@ -1 +1,2 @@
export * from './project.module';
export { KubernetesHealthIndicator } from './kubernetes/kubernetes.health';

0 comments on commit f34a3bf

Please sign in to comment.