Skip to content
This repository has been archived by the owner on Jun 11, 2020. It is now read-only.

Commit

Permalink
feat($release): improvements and fixes
Browse files Browse the repository at this point in the history
Whats new:
- added pg2web for ease access to PSQL data
- launch integration to lokalise
- added verification for email code after account creating

Whats fixed:
- fix for validators
- trash cleanup

Signed-off-by: Andrew Ghostuhin <[email protected]>
  • Loading branch information
TorinAsakura committed Nov 14, 2018
1 parent 21c98b4 commit 640ef1f
Show file tree
Hide file tree
Showing 24 changed files with 56 additions and 137 deletions.
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ services:
- MINIO_SECRET_KEY=secretKey
command: server data

pgweb:
image: sosedoff/pgweb
ports:
- 8081:8081
environment:
- DATABASE_URL=postgres://root:root@db:5432/av?sslmode=disable
- AUTH_USER=user
- AUTH_PASS=password
depends_on:

mailer:
image: node
working_dir: /workspace/packages/mailer
Expand Down
4 changes: 2 additions & 2 deletions packages/account/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"scripts": {
"typecheck": "tsc --target es2015 --module es2015 --moduleResolution node",
"lint": "tslint --project tsconfig.json -c tslint.json -t codeFrame src/**/*.ts{,x}",
"locales:extract": "intl-tools intl:extract -m \"@av/intl\" ./dist",
"locales:upload": "intl-tools lokalise:upload -p 643237235b4563647d7004.50758493"
"locales:extract": "intl-tools intl:extract -m \"@er/intl\" ./dist"
},
"dependencies": {
"@nestjs/common": "^5.2.2",
Expand All @@ -16,6 +15,7 @@
"@nestjs/graphql": "^3.0.0",
"@nestjs/typeorm": "^5.2.0",
"@types/bcryptjs": "^2.4.2",

"bcryptjs": "^2.4.3",
"typeorm": "^0.2.7"
},
Expand Down
19 changes: 14 additions & 5 deletions packages/account/src/dto/CreateAccountDto.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
import { MinLength, IsEmail } from 'class-validator'
import { IsFieldEqual } from '@er/common'
import { IsEmailExists, IsLoginExists } from '../constraints'
import messages from '../messages'

export class CreateAccountDto {
@MinLength(3)
@IsLoginExists()
@MinLength(3, {
message: messages.minLength,
})
@IsLoginExists({
message: messages.loginExists,
})
readonly login: string

@IsEmail()
@IsEmailExists()
@IsEmail({}, {
message: messages.invalidEmail,
})
@IsEmailExists({
message: messages.emailExists,
})
readonly email: string

readonly password: string

@IsFieldEqual('password', {
message: 'Password not equal',
message: messages.confirmPassword,
})
readonly confirmPassword: string
}
3 changes: 2 additions & 1 deletion packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"license": "MIT",
"scripts": {
"typecheck": "tsc --target es2015 --module es2015 --moduleResolution node",
"lint": "tslint --project tsconfig.json -c tslint.json -t codeFrame src/**/*.ts{,x}"
"lint": "tslint --project tsconfig.json -c tslint.json -t codeFrame src/**/*.ts{,x}",
"locales:extract": "intl-tools intl:extract -m \"@er/intl\" ./dist"
},
"dependencies": {
"@nestjs/common": "^5.2.2",
Expand Down
5 changes: 3 additions & 2 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"main": "src/index.ts",
"license": "MIT",
"scripts": {
"typecheck": "tsc",
"lint": "tslint --project tsconfig.json -c tslint.json -t codeFrame src/**/*.ts{,x}"
"typecheck": "tsc --target es2015 --module es2015 --moduleResolution node",
"lint": "tslint --project tsconfig.json -c tslint.json -t codeFrame src/**/*.ts{,x}",
"locales:extract": "intl-tools intl:extract -m \"@er/intl\" ./dist"
},
"dependencies": {
"@nestjs/common": "^5.2.2",
Expand Down
5 changes: 2 additions & 3 deletions packages/common/src/decorators/Validate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Validator, ValidatorOptions } from 'class-validator'
import { validate, ValidatorOptions } from 'class-validator'
import { plainToClass } from 'class-transformer'

const mapErrors = (result, error) => {
Expand Down Expand Up @@ -37,9 +37,8 @@ export function Validate(metatype, options?: ValidationOptions): any {
const values = targetField ? params[targetField] : params

const object = plainToClass(metatype, { ...values, user: context.user })
const validator = new Validator()

const errors = await validator.validate(object, validatorOptions)
const errors = await validate(object, validatorOptions)

if (errors && errors.length > 0) {
return { errors: errors.reduce(mapErrors, {}) }
Expand Down
5 changes: 3 additions & 2 deletions packages/cqrs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"main": "src/index.ts",
"license": "MIT",
"scripts": {
"typecheck": "tsc",
"lint": "tslint --project tsconfig.json -c tslint.json -t codeFrame src/**/*.ts{,x}"
"typecheck": "tsc --target es2015 --module es2015 --moduleResolution node",
"lint": "tslint --project tsconfig.json -c tslint.json -t codeFrame src/**/*.ts{,x}",
"locales:extract": "intl-tools intl:extract -m \"@er/intl\" ./dist"
},
"dependencies": {
"@nestjs/cqrs": "^5.1.0"
Expand Down
5 changes: 3 additions & 2 deletions packages/intl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"main": "src/index.ts",
"license": "MIT",
"scripts": {
"typecheck": "tsc",
"lint": "tslint --project tsconfig.json -c tslint.json -t codeFrame src/**/*.ts{,x}"
"typecheck": "tsc --target es2015 --module es2015 --moduleResolution node",
"lint": "tslint --project tsconfig.json -c tslint.json -t codeFrame src/**/*.ts{,x}",
"locales:extract": "intl-tools intl:extract -m \"@er/intl\" ./dist"
},
"dependencies": {
"glob-promise": "^3.4.0",
Expand Down
5 changes: 2 additions & 3 deletions packages/mailer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
"start": "node -r ts-node/register src/index.ts",
"typecheck": "tsc --target es2015 --module es2015 --moduleResolution node",
"lint": "tslint --project tsconfig.json -c tslint.json -t codeFrame src/**/*.ts{,x}",
"locales:download": "intl-tools lokalise:download -p 643237235b4563647d7004.50758493 -t f110be4308044a0bd50b35c0bdb508c3c83a9f24 -o $PWD/locales",
"locales:extract": "intl-tools intl:extract -m \"@er/intl\" ./dist",
"locales:upload": "intl-tools lokalise:upload -p 293284795b62a7623cba23.59882259"
"locales:download": "intl-tools lokalise:download -o $PWD/locales",
"locales:extract": "intl-tools intl:extract -m \"@er/intl\" ./dist"
},
"devDependencies": {
"@types/node": "^10.9.3",
Expand Down
5 changes: 3 additions & 2 deletions packages/swt-gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
"main": "src/index.ts",
"license": "MIT",
"scripts": {
"dev": "nodemon --exec node -r ts-node/register --watch ../users/src --watch ../auth/src --watch ../verify/src --watch src src/index.ts",
"dev": "nodemon --exec node --inspect=0.0.0.0:9222 --nolazy -r ts-node/register --watch ../users/src --watch ../auth/src --watch ../verify/src --watch src src/index.ts",
"typecheck": "tsc --target es2015 --module es2015 --moduleResolution node",
"lint": "tslint --project tsconfig.json -c tslint.json -t codeFrame src/**/*.ts{,x}"
"lint": "tslint --project tsconfig.json -c tslint.json -t codeFrame src/**/*.ts{,x}",
"locales:download": "intl-tools lokalise:download -p 643237235b4563647d7004.50758493 -t f110be4308044a0bd50b35c0bdb508c3c83a9f24 -o $PWD/locales"
},
"dependencies": {
"@nestjs/common": "^5.2.2",
Expand Down
4 changes: 4 additions & 0 deletions packages/swt-gateway/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { graphqlExpress } from 'apollo-server-express'
import graphqlPlayground from 'graphql-playground-middleware-express'
import { AuthModule, AuthMiddleware } from '@er/auth'
import { VerifyModule } from '@er/verify'
import { LocaleMiddleware } from '@er/common'

@Module({
imports: [
Expand Down Expand Up @@ -56,6 +57,9 @@ export class ApplicationModule implements NestModule {
consumer
.apply(this.authMiddleware.resolve())
.forRoutes('/graphql')
.apply(LocaleMiddleware)
.with(['ru', 'en'])
.forRoutes('/graphql')
.apply(graphqlExpress(request => ({ schema, context: { user: request.user }, rootValue: request })))
.forRoutes('/graphql')
.apply(graphqlPlayground({ endpoint: '/graphql' }))
Expand Down
2 changes: 1 addition & 1 deletion packages/swt-gateway/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async function bootstrap() {

app.enableCors()

useContainer(app, { fallback: true })
useContainer(app, { fallbackOnErrors: true, fallback: true })

app.useGlobalInterceptors(new MapErrorCodes())

Expand Down
3 changes: 2 additions & 1 deletion packages/users/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"license": "MIT",
"scripts": {
"typecheck": "tsc --target es2015 --module es2015 --moduleResolution node",
"lint": "tslint --project tsconfig.json -c tslint.json -t codeFrame src/**/*.ts{,x}"
"lint": "tslint --project tsconfig.json -c tslint.json -t codeFrame src/**/*.ts{,x}",
"locales:extract": "intl-tools intl:extract -m \"@er/intl\" ./dist"
},
"dependencies": {
"@nestjs/common": "^5.2.2",
Expand Down
37 changes: 0 additions & 37 deletions packages/users/src/commands/handlers/CreateUserHandler.ts

This file was deleted.

3 changes: 0 additions & 3 deletions packages/users/src/commands/handlers/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
import { CreateUserHandler } from './CreateUserHandler'

export const CommandHandlers = [
CreateUserHandler,
]
9 changes: 0 additions & 9 deletions packages/users/src/commands/impl/CreateUserCommand.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/users/src/commands/impl/index.ts
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
export * from './CreateUserCommand'
18 changes: 0 additions & 18 deletions packages/users/src/dto/CreateUserDto.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/users/src/dto/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './CreateUserDto'

13 changes: 0 additions & 13 deletions packages/users/src/resolvers/UserMutations.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
import { Injectable } from '@nestjs/common'
import { Mutation } from '@nestjs/graphql'
import { CreateUserDto } from '../dto'
import { Validate } from '@er/common'
import { CommandBus } from '@er/cqrs'
import { CreateUserCommand } from '../commands/impl'

@Injectable()
export class UserMutations {
constructor(
private readonly commandBus: CommandBus,
) {}

@Mutation()
@Validate(CreateUserDto)
createUser(request, { input }) {
return this.commandBus.execute(
new CreateUserCommand(
input.login,
input.email,
input.password,
),
)
}
}
5 changes: 0 additions & 5 deletions packages/users/src/resolvers/UserQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,4 @@ export class UserQueries {
@InjectRepository(User)
private readonly userRepository: Repository<User>,
) {}

@Query()
all(request) {
return this.userRepository.find()
}
}
24 changes: 0 additions & 24 deletions packages/users/src/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,3 @@ type User {
login: String
email: String
}

input CreateUserInput {
login: String
email: String
password: String
}

type CreateUserErrors {
email: String
login: String
password: String
}

type CreateUserResponse {
errors: CreateUserErrors
}

type Query {
all : [User]
}

type Mutation {
createUser (input: CreateUserInput!) : CreateUserResponse
}
3 changes: 2 additions & 1 deletion packages/verify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"license": "MIT",
"scripts": {
"typecheck": "tsc --target es2015 --module es2015 --moduleResolution node",
"lint": "tslint --project tsconfig.json -c tslint.json -t codeFrame src/**/*.ts{,x}"
"lint": "tslint --project tsconfig.json -c tslint.json -t codeFrame src/**/*.ts{,x}",
"locales:extract": "intl-tools intl:extract -m \"@er/intl\" ./dist"
},
"dependencies": {
"@nestjs/common": "^5.2.2",
Expand Down
3 changes: 2 additions & 1 deletion packages/verify/src/dto/ConfirmVerificationCodeDto.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { IsVerificationCodeValid } from '../constraints'
import messages from '../messages'

export class ConfirmVerificationCodeDto {
public readonly verificationId: string

@IsVerificationCodeValid({
message: 'Invalid code',
message: messages.invalidVerificationCode,
})
public readonly verificationCode: string
}

0 comments on commit 640ef1f

Please sign in to comment.