Skip to content

Commit

Permalink
Update deps & code to work properly
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelkleczek committed Feb 2, 2019
1 parent 123a7d3 commit 7854d51
Show file tree
Hide file tree
Showing 19 changed files with 5,432 additions and 75 deletions.
34 changes: 18 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,34 @@
},
"homepage": "https://github.com/lujakob/nestjs-realworld-example-app#readme",
"dependencies": {
"@nestjs/common": "^4.6.3",
"@nestjs/core": "^4.6.3",
"@nestjs/microservices": "^4.6.1",
"@nestjs/swagger": "^1.1.4",
"@nestjs/testing": "^4.6.1",
"@nestjs/typeorm": "^2.0.0",
"@nestjs/websockets": "^4.5.8",
"@nestjs/common": "^5.6.2",
"@nestjs/core": "^5.6.2",
"@nestjs/microservices": "^5.6.2",
"@nestjs/swagger": "^2.5.1",
"@nestjs/testing": "^5.6.2",
"@nestjs/typeorm": "^5.2.2",
"@nestjs/websockets": "^5.6.2",
"class-transformer": "^0.2.0",
"class-validator": "^0.9.1",
"crypto": "^1.0.1",
"crypto-js": "^3.1.9-1",
"jsonwebtoken": "^8.1.1",
"mysql": "^2.15.0",
"passport": "^0.4.0",
"passport-jwt": "^3.0.1",
"passport-jwt": "^4.0.0",
"reflect-metadata": "^0.1.12",
"rxjs": "^5.5.6",
"rxjs": "^6.4.0",
"slug": "^0.9.1",
"typeorm": "^0.1.12",
"typescript": "^2.7.2"
"typeorm": "^0.2.12",
"typescript": "^3.3.1"
},
"devDependencies": {
"@types/jest": "^22.1.3",
"@types/node": "^9.4.6",
"jest": "^22.4.2",
"@types/jest": "^23.3.13",
"@types/node": "^10.12.21",
"jest": "^24.0.0",
"nodemon": "^1.15.0",
"supertest": "^3.0.0",
"ts-jest": "^22.0.4",
"ts-node": "^4.1.0"
"ts-jest": "^23.10.5",
"ts-node": "^8.0.2"
}
}
4 changes: 2 additions & 2 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { TagModule } from './tag/tag.module';
controllers: [
AppController
],
components: []
providers: []
})
export class ApplicationModule {
constructor(private readonly connection: Connection) {}
}
}
6 changes: 3 additions & 3 deletions src/article/article.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MiddlewaresConsumer, Module, NestModule, RequestMethod } from '@nestjs/common';
import { MiddlewareConsumer, Module, NestModule, RequestMethod } from '@nestjs/common';
import { ArticleController } from './article.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ArticleEntity } from './article.entity';
Expand All @@ -11,13 +11,13 @@ import { UserModule } from '../user/user.module';

@Module({
imports: [TypeOrmModule.forFeature([ArticleEntity, Comment, UserEntity, FollowsEntity]), UserModule],
components: [ArticleService],
providers: [ArticleService],
controllers: [
ArticleController
]
})
export class ArticleModule implements NestModule {
public configure(consumer: MiddlewaresConsumer) {
public configure(consumer: MiddlewareConsumer) {
consumer
.apply(AuthMiddleware)
.forRoutes(
Expand Down
22 changes: 11 additions & 11 deletions src/article/article.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, Inject } from '@nestjs/common';
import { Component, Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository, getRepository } from 'typeorm';
import { Repository, getRepository, DeleteResult } from 'typeorm';
import { ArticleEntity } from './article.entity';
import { Comment } from './comment.entity';
import { UserEntity } from '../user/user.entity';
Expand All @@ -10,7 +10,7 @@ import { CreateArticleDto } from './dto';
import {ArticleRO, ArticlesRO, CommentsRO} from './article.interface';
const slug = require('slug');

@Component()
@Injectable()
export class ArticleService {
constructor(
@InjectRepository(ArticleEntity)
Expand Down Expand Up @@ -82,7 +82,7 @@ export class ArticleService {
if ('offset' in query) {
qb.offset(query.offset);
}

const articles = await qb.getMany();

return {articles, articlesCount};
Expand All @@ -109,12 +109,12 @@ export class ArticleService {
async deleteComment(slug: string, id: string): Promise<ArticleRO> {
let article = await this.articleRepository.findOne({slug});

const comment = await this.commentRepository.findOneById(id);
const comment = await this.commentRepository.findOne(id);
const deleteIndex = article.comments.findIndex(_comment => _comment.id === comment.id);

if (deleteIndex >= 0) {
const deleteComments = article.comments.splice(deleteIndex, 1);
await this.commentRepository.deleteById(deleteComments[0].id);
await this.commentRepository.delete(deleteComments[0].id);
article = await this.articleRepository.save(article);
return {article};
} else {
Expand All @@ -125,7 +125,7 @@ export class ArticleService {

async favorite(id: number, slug: string): Promise<ArticleRO> {
let article = await this.articleRepository.findOne({slug});
const user = await this.userRepository.findOneById(id);
const user = await this.userRepository.findOne(id);

const isNewFavorite = user.favorites.findIndex(_article => _article.id === article.id) < 0;
if (isNewFavorite) {
Expand All @@ -141,7 +141,7 @@ export class ArticleService {

async unFavorite(id: number, slug: string): Promise<ArticleRO> {
let article = await this.articleRepository.findOne({slug});
const user = await this.userRepository.findOneById(id);
const user = await this.userRepository.findOne(id);

const deleteIndex = user.favorites.findIndex(_article => _article.id === article.id);

Expand Down Expand Up @@ -173,7 +173,7 @@ export class ArticleService {

const newArticle = await this.articleRepository.save(article);

const author = await this.userRepository.findOneById(userId);
const author = await this.userRepository.findOne(userId);

if (Array.isArray(author.articles)) {
author.articles.push(article);
Expand All @@ -194,11 +194,11 @@ export class ArticleService {
return {article};
}

async delete(slug: string): Promise<void> {
async delete(slug: string): Promise<DeleteResult> {
return await this.articleRepository.delete({ slug: slug});
}

slugify(title: string) {
return slug(title, {lower: true}) + '-' + (Math.random() * Math.pow(36, 6) | 0).toString(36)
}
}
}
4 changes: 2 additions & 2 deletions src/profile/follows.entity.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Entity, PrimaryGeneratedColumn, Column } from "typeorm";
import {IsEmail, Validate} from "class-validator";
import * as crypto from 'crypto';
import { CustomEmail } from '../user/CustomEmail';
// import { CustomEmail } from '../user/CustomEmail';

@Entity('follows')
export class FollowsEntity {
Expand All @@ -15,4 +15,4 @@ export class FollowsEntity {
@Column()
followingId: number;

}
}
6 changes: 3 additions & 3 deletions src/profile/profile.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {MiddlewaresConsumer, Module, NestModule, RequestMethod} from '@nestjs/common';
import {MiddlewareConsumer, Module, NestModule, RequestMethod} from '@nestjs/common';
import { ProfileController } from './profile.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ProfileService } from './profile.service';
Expand All @@ -9,14 +9,14 @@ import {AuthMiddleware} from "../user/auth.middleware";

@Module({
imports: [TypeOrmModule.forFeature([UserEntity, FollowsEntity]), UserModule],
components: [ProfileService],
providers: [ProfileService],
controllers: [
ProfileController
],
exports: []
})
export class ProfileModule implements NestModule {
public configure(consumer: MiddlewaresConsumer) {
public configure(consumer: MiddlewareConsumer) {
consumer
.apply(AuthMiddleware)
.forRoutes({path: 'profiles/:username/follow', method: RequestMethod.ALL});
Expand Down
8 changes: 4 additions & 4 deletions src/profile/profile.service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {Component, HttpStatus, Inject} from '@nestjs/common';
import {Component, HttpStatus, Injectable} from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { UserEntity } from '../user/user.entity';
import { DeepPartial } from 'typeorm/common/DeepPartial';
import { ProfileRO, ProfileData } from './profile.interface';
import {FollowsEntity} from "./follows.entity";
import {HttpException} from "@nestjs/core";
import {HttpException} from "@nestjs/common/exceptions/http.exception";

@Component()
@Injectable()
export class ProfileService {
constructor(
@InjectRepository(UserEntity)
Expand Down Expand Up @@ -101,4 +101,4 @@ export class ProfileService {
return {profile};
}

}
}
6 changes: 3 additions & 3 deletions src/shared/pipes/validation.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {PipeTransform, Pipe, ArgumentMetadata, BadRequestException, HttpStatus} from '@nestjs/common';
import {PipeTransform, Pipe, ArgumentMetadata, BadRequestException, HttpStatus, Injectable} from '@nestjs/common';
import { validate } from 'class-validator';
import { plainToClass } from 'class-transformer';
import {HttpException} from "@nestjs/common/exceptions/http.exception";

@Pipe()
@Injectable()
export class ValidationPipe implements PipeTransform<any> {
async transform(value, metadata: ArgumentMetadata) {

Expand Down Expand Up @@ -38,4 +38,4 @@ export class ValidationPipe implements PipeTransform<any> {
const types = [String, Boolean, Number, Array, Object];
return !types.find((type) => metatype === type);
}
}
}
4 changes: 2 additions & 2 deletions src/tag/tag.entity.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Entity, PrimaryGeneratedColumn, Column, BeforeInsert} from "typeorm";
import {IsEmail, Validate} from "class-validator";
import * as crypto from 'crypto';
import { CustomEmail } from './CustomEmail';
// import { CustomEmail } from './CustomEmail';

@Entity('tag')
export class TagEntity {
Expand All @@ -12,4 +12,4 @@ export class TagEntity {
@Column()
tag: string;

}
}
6 changes: 3 additions & 3 deletions src/tag/tag.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {MiddlewaresConsumer, Module, NestModule, RequestMethod} from '@nestjs/common';
import {MiddlewareConsumer, Module, NestModule, RequestMethod} from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { UserModule } from '../user/user.module';
import { TagService } from './tag.service';
Expand All @@ -7,13 +7,13 @@ import { TagController } from './tag.controller';

@Module({
imports: [TypeOrmModule.forFeature([TagEntity]), UserModule],
components: [TagService],
providers: [TagService],
controllers: [
TagController
],
exports: []
})
export class TagModule implements NestModule {
public configure(consumer: MiddlewaresConsumer) {
public configure(consumer: MiddlewareConsumer) {
}
}
6 changes: 3 additions & 3 deletions src/tag/tag.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Component, HttpStatus, Inject} from '@nestjs/common';
import {Component, HttpStatus, Inject, Injectable} from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { TagEntity } from './tag.entity';

@Component()
@Injectable()
export class TagService {
constructor(
@InjectRepository(TagEntity)
Expand All @@ -14,4 +14,4 @@ export class TagService {
return await this.tagRepository.find();
}

}
}
8 changes: 4 additions & 4 deletions src/user/auth.middleware.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { HttpException } from '@nestjs/core';
import { Middleware, NestMiddleware, HttpStatus } from '@nestjs/common';
import { HttpException } from '@nestjs/common/exceptions/http.exception';
import { Middleware, NestMiddleware, HttpStatus, Injectable } from '@nestjs/common';
import { ExtractJwt, Strategy } from 'passport-jwt';
import { Request, Response, NextFunction } from 'express';
import * as jwt from 'jsonwebtoken';
import { SECRET } from '../config';
import { UserService } from './user.service';

@Middleware()
@Injectable()
export class AuthMiddleware implements NestMiddleware {
constructor(private readonly userService: UserService) {}

Expand All @@ -31,4 +31,4 @@ export class AuthMiddleware implements NestMiddleware {
}
};
}
}
}
4 changes: 2 additions & 2 deletions src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { UserService } from './user.service';
import { UserEntity } from './user.entity';
import { UserRO } from './user.interface';
import { CreateUserDto, UpdateUserDto, LoginUserDto } from './dto';
import { HttpException } from '@nestjs/core';
import { HttpException } from '@nestjs/common/exceptions/http.exception';
import { User } from './user.decorator';
import { ValidationPipe } from '../shared/pipes/validation.pipe';

Expand Down Expand Up @@ -54,4 +54,4 @@ export class UserController {
const user = {email, token, username, bio, image};
return {user}
}
}
}
6 changes: 3 additions & 3 deletions src/user/user.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createRouteParamDecorator } from '@nestjs/common';
import { createParamDecorator } from '@nestjs/common';
import { SECRET } from '../config';
import * as jwt from 'jsonwebtoken';

export const User = createRouteParamDecorator((data, req) => {
export const User = createParamDecorator((data, req) => {

// if route is protected, there is a user set in auth.middleware
if (!!req.user) {
Expand All @@ -16,4 +16,4 @@ export const User = createRouteParamDecorator((data, req) => {
return !!data ? decoded[data] : decoded.user;
}

});
});
2 changes: 1 addition & 1 deletion src/user/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ export class UserEntity {

@OneToMany(type => ArticleEntity, article => article.author)
articles: ArticleEntity[];
}
}
6 changes: 3 additions & 3 deletions src/user/user.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {MiddlewaresConsumer, Module, NestModule, RequestMethod} from '@nestjs/common';
import {MiddlewareConsumer, Module, NestModule, RequestMethod} from '@nestjs/common';
import { UserController } from './user.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { UserEntity } from './user.entity';
Expand All @@ -7,14 +7,14 @@ import { AuthMiddleware } from './auth.middleware';

@Module({
imports: [TypeOrmModule.forFeature([UserEntity])],
components: [UserService],
providers: [UserService],
controllers: [
UserController
],
exports: [UserService]
})
export class UserModule implements NestModule {
public configure(consumer: MiddlewaresConsumer) {
public configure(consumer: MiddlewareConsumer) {
consumer
.apply(AuthMiddleware)
.forRoutes({path: 'user', method: RequestMethod.GET}, {path: 'user', method: RequestMethod.PUT});
Expand Down
Loading

0 comments on commit 7854d51

Please sign in to comment.