Skip to content

Commit

Permalink
fix: amend typescript errors
Browse files Browse the repository at this point in the history
  • Loading branch information
leosuncin committed Sep 5, 2022
1 parent bde93f8 commit 1b3db6e
Show file tree
Hide file tree
Showing 41 changed files with 84 additions and 47 deletions.
4 changes: 3 additions & 1 deletion src/auth/controllers/auth.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Test } from '@nestjs/testing';
import { createMock } from 'ts-auto-mock';

import { AuthController } from '@/auth/controllers/auth.controller';
import { LoginUser } from '@/auth/dto/login-user.dto';
import type { LoginUser } from '@/auth/dto/login-user.dto';
import type { RegisterUser } from '@/auth/dto/register-user.dto';
import type { UpdateUser } from '@/auth/dto/update-user.dto';
import { User } from '@/auth/entities/user.entity';
Expand Down Expand Up @@ -47,6 +47,8 @@ describe('AuthController', () => {
),
});
}

return;
})
.compile();

Expand Down
2 changes: 2 additions & 0 deletions src/auth/dto/login-user.dto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ describe('Login user validations', () => {
),
});
}

return;
})
.compile();

Expand Down
2 changes: 2 additions & 0 deletions src/auth/dto/register-user.dto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ describe('Register user validations', () => {
if (token === getRepositoryToken(User)) {
return createMock<Repository<User>>();
}

return;
})
.compile();

Expand Down
2 changes: 2 additions & 0 deletions src/auth/dto/update-user.dto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ describe('Update user validations', () => {
if (token === getRepositoryToken(User)) {
return createMock<Repository<User>>();
}

return;
})
.compile();

Expand Down
4 changes: 2 additions & 2 deletions src/auth/interceptors/current-user.interceptor.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CallHandler } from '@nestjs/common';
import type { CallHandler } from '@nestjs/common';
import { ExecutionContextHost } from '@nestjs/core/helpers/execution-context-host';
import { createMocks } from 'node-mocks-http';
import { lastValueFrom, of } from 'rxjs';
Expand Down Expand Up @@ -42,8 +42,8 @@ describe('UserInterceptor', () => {
it("should not inject the user's id when there is no request's body", async () => {
const { req, res } = createMocks({
user,
body: undefined,
});
delete req.body;
const context = new ExecutionContextHost([req, res]);
const next: CallHandler = {
handle: () => of({}),
Expand Down
4 changes: 3 additions & 1 deletion src/auth/interceptors/token.interceptor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createMocks } from 'node-mocks-http';
import { lastValueFrom, of } from 'rxjs';
import { createMock } from 'ts-auto-mock';

import { User } from '@/auth/entities/user.entity';
import type { User } from '@/auth/entities/user.entity';
import { TokenInterceptor } from '@/auth/interceptors/token.interceptor';

describe('TokenInterceptor', () => {
Expand All @@ -21,6 +21,8 @@ describe('TokenInterceptor', () => {
if (token === JwtService) {
return createMock<JwtService>();
}

return;
})
.compile();

Expand Down
2 changes: 1 addition & 1 deletion src/auth/pipes/strip-id.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ArgumentMetadata } from '@nestjs/common';
import type { ArgumentMetadata } from '@nestjs/common';

import { StripIdPipe } from '@/auth/pipes/strip-id.pipe';
import { credentials } from '@/common/test-helpers';
Expand Down
2 changes: 1 addition & 1 deletion src/auth/pipes/swap-password.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ArgumentMetadata } from '@nestjs/common';
import type { ArgumentMetadata } from '@nestjs/common';

import { SwapPasswordPipe } from '@/auth/pipes/swap-password.pipe';
import { credentials } from '@/common/test-helpers';
Expand Down
6 changes: 4 additions & 2 deletions src/auth/pipes/swap-password.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ArgumentMetadata, Injectable, PipeTransform } from '@nestjs/common';
import invariant from 'tiny-invariant';

import type { UpdateUser } from '@/auth/dto/update-user.dto';

Expand All @@ -13,10 +14,11 @@ export class SwapPasswordPipe implements PipeTransform {
if (metadata.type !== 'body') return value;

if (this.#want2ChangePassword(value)) {
invariant(value.newPassword);
value.password = value.newPassword;
delete value.newPassword;
} else {
delete value.password;
delete value['password'];
}

return value;
Expand All @@ -25,6 +27,6 @@ export class SwapPasswordPipe implements PipeTransform {
#want2ChangePassword(
value: Record<string, unknown>,
): value is Writeable<UpdateUser> {
return typeof value.newPassword === 'string';
return typeof value['newPassword'] === 'string';
}
}
2 changes: 2 additions & 0 deletions src/auth/services/authentication.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ describe('AuthenticationService', () => {
merge: jest.fn().mockImplementation(Object.assign),
});
}

return;
})
.compile();

Expand Down
6 changes: 3 additions & 3 deletions src/auth/services/authentication.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import type { Repository } from 'typeorm';

import { LoginUser } from '@/auth/dto/login-user.dto';
import { RegisterUser } from '@/auth/dto/register-user.dto';
import { UpdateUser } from '@/auth/dto/update-user.dto';
import type { LoginUser } from '@/auth/dto/login-user.dto';
import type { RegisterUser } from '@/auth/dto/register-user.dto';
import type { UpdateUser } from '@/auth/dto/update-user.dto';
import { User } from '@/auth/entities/user.entity';
import type { JwtPayload } from '@/auth/interfaces/jwt-payload.interface';

Expand Down
6 changes: 3 additions & 3 deletions src/auth/strategies/jwt.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Injectable } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
import { ExtractJwt, JwtFromRequestFunction, Strategy } from 'passport-jwt';

import { User } from '@/auth/entities/user.entity';
import { JwtPayload } from '@/auth/interfaces/jwt-payload.interface';
import type { User } from '@/auth/entities/user.entity';
import type { JwtPayload } from '@/auth/interfaces/jwt-payload.interface';
import { AuthenticationService } from '@/auth/services/authentication.service';

declare module 'express' {
Expand All @@ -16,7 +16,7 @@ declare module 'express' {
export const JWT = 'jwt' as const;

const extractJwtFromCookie: JwtFromRequestFunction = (request) => {
return request.signedCookies.token;
return request.signedCookies['token']!;
};

@Injectable()
Expand Down
2 changes: 2 additions & 0 deletions src/auth/validators/is-already-register.validator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ describe('IsAlreadyRegister', () => {
if (token === getRepositoryToken(User)) {
return createMock<Repository<User>>();
}

return;
})
.compile();

Expand Down
2 changes: 1 addition & 1 deletion src/auth/validators/is-already-register.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class IsAlreadyRegisterConstraint
}
}

export function IsAlreadyRegister(options?: ValidationOptions) {
export function IsAlreadyRegister(options: ValidationOptions = {}) {
return function (object: object, propertyName: 'username' | 'email') {
registerDecorator({
target: object.constructor,
Expand Down
2 changes: 1 addition & 1 deletion src/auth/validators/is-not-the-same.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('IsNotTheSame', () => {
const errors = validateSync(dto);

expect(errors).toHaveLength(1);
expect(errors[0].constraints).toMatchObject({
expect(errors[0]!.constraints).toMatchObject({
isNotTheSame: 'password must be different than username',
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/auth/validators/is-not-the-same.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class IsNotTheSameConstraint implements ValidatorConstraintInterface {

export function IsNotTheSame<Type>(
property: keyof Type,
validationOptions?: ValidationOptions,
validationOptions: ValidationOptions = {},
) {
return (object: object, propertyName: string) => {
registerDecorator({
Expand Down
2 changes: 1 addition & 1 deletion src/auth/validators/is-not-vulnerable.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class IsNotVulnerableConstraint implements ValidatorConstraintInterface {
}
}

export function IsNotVulnerable(options?: ValidationOptions) {
export function IsNotVulnerable(options: ValidationOptions = {}) {
return function (object: object, propertyName: string) {
registerDecorator({
target: object.constructor,
Expand Down
2 changes: 2 additions & 0 deletions src/auth/validators/validate-credential.validator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ describe('ValidateCredential', () => {
if (token === getRepositoryToken(User)) {
return createMock<Repository<User>>();
}

return;
})
.compile();

Expand Down
2 changes: 1 addition & 1 deletion src/auth/validators/validate-credential.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class ValidateCredentialConstraint
}
}

export function ValidateCredential(options?: ValidationOptions) {
export function ValidateCredential(options: ValidationOptions = {}) {
return function (object: object, propertyName: 'username' | 'password') {
registerDecorator({
target: object.constructor,
Expand Down
6 changes: 4 additions & 2 deletions src/blog/controllers/article.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { createMock } from 'ts-auto-mock';

import { User } from '@/auth/entities/user.entity';
import { ArticleController } from '@/blog/controllers/article.controller';
import { CreateArticle } from '@/blog/dto/create-article.dto';
import { UpdateArticle } from '@/blog/dto/update-article.dto';
import type { CreateArticle } from '@/blog/dto/create-article.dto';
import type { UpdateArticle } from '@/blog/dto/update-article.dto';
import { Article } from '@/blog/entities/article.entity';
import { ArticleService } from '@/blog/services/article.service';

Expand All @@ -20,6 +20,8 @@ describe('ArticleController', () => {
if (token === ArticleService) {
return createMock<ArticleService>();
}

return;
})
.compile();

Expand Down
4 changes: 3 additions & 1 deletion src/blog/controllers/comment.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createMock } from 'ts-auto-mock';

import { User } from '@/auth/entities/user.entity';
import { CommentController } from '@/blog/controllers/comment.controller';
import { CreateComment } from '@/blog/dto/create-comment';
import type { CreateComment } from '@/blog/dto/create-comment';
import { Article } from '@/blog/entities/article.entity';
import { Comment } from '@/blog/entities/comment.entity';
import { ArticleService } from '@/blog/services/article.service';
Expand All @@ -25,6 +25,8 @@ describe('CommentController', () => {
if (token === ArticleService) {
return createMock<ArticleService>();
}

return;
})
.compile();

Expand Down
2 changes: 1 addition & 1 deletion src/blog/controllers/comment.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { JWTAuthGuard } from '@/auth/guards/jwt-auth.guard';
import { IsComment } from '@/blog/decorators/is-entity.decorator';
import { CreateComment } from '@/blog/dto/create-comment';
import type { Article } from '@/blog/entities/article.entity';
import { Comment } from '@/blog/entities/comment.entity';
import type { Comment } from '@/blog/entities/comment.entity';
import { IsAuthorGuard } from '@/blog/guards/is-author.guard';
import { SetArticleInterceptor } from '@/blog/interceptors/set-article.interceptor';
import { SetAuthorInterceptor } from '@/blog/interceptors/set-author.interceptor';
Expand Down
2 changes: 2 additions & 0 deletions src/blog/dto/create-comment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ describe('CreateComment DTO', () => {
),
});
}

return;
})
.compile();

Expand Down
2 changes: 1 addition & 1 deletion src/blog/fixtures/article.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { plainToInstance } from 'class-transformer';
import { fluse } from 'fluse';

import { CreateArticle } from '@/blog/dto/create-article.dto';
import { UpdateArticle } from '@/blog/dto/update-article.dto';
import type { UpdateArticle } from '@/blog/dto/update-article.dto';
import { fakerPlugin } from '@/common/fluse-plugin-faker';
import { txtgenPlugin } from '@/common/fluse-plugin-txtgen';

Expand Down
2 changes: 2 additions & 0 deletions src/blog/guards/is-author.guard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ describe('IsAuthorGuard', () => {
),
});
}

return;
}),
}),
},
Expand Down
4 changes: 3 additions & 1 deletion src/blog/guards/is-author.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export class IsAuthorGuard implements CanActivate {
) {}

async canActivate(context: ExecutionContext): Promise<boolean> {
const request = context.switchToHttp().getRequest<Request>();
const request = context
.switchToHttp()
.getRequest<Request<{ id: string }>>();
const kindOf = this.reflector.get<Entities>(
ENTITY_METADATA_KEY,
context.getHandler(),
Expand Down
2 changes: 1 addition & 1 deletion src/blog/interceptors/set-article.interceptor.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CallHandler } from '@nestjs/common';
import type { CallHandler } from '@nestjs/common';
import { ExecutionContextHost } from '@nestjs/core/helpers/execution-context-host';
import { createMocks } from 'node-mocks-http';
import { lastValueFrom, of } from 'rxjs';
Expand Down
2 changes: 1 addition & 1 deletion src/blog/interceptors/set-author.interceptor.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CallHandler } from '@nestjs/common';
import type { CallHandler } from '@nestjs/common';
import { ExecutionContextHost } from '@nestjs/core/helpers/execution-context-host';
import { createMocks } from 'node-mocks-http';
import { lastValueFrom, of } from 'rxjs';
Expand Down
2 changes: 1 addition & 1 deletion src/blog/interceptors/set-author.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
NestInterceptor,
} from '@nestjs/common';
import type { Request } from 'express';
import { Observable } from 'rxjs';
import type { Observable } from 'rxjs';
import invariant from 'tiny-invariant';

@Injectable()
Expand Down
2 changes: 2 additions & 0 deletions src/blog/pipes/article.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ describe('ArticlePipe', () => {
),
});
}

return;
})
.compile();

Expand Down
4 changes: 2 additions & 2 deletions src/blog/seeders/article.seeder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class ArticleSeeder implements Seeder {
However, cats have begun to rent blueberries over the past few months, specifically for sharks associated with their puppies.
Some assert that however, ducks have begun to rent octopus over the past few months, specifically for sharks associated with their snakes.
Though we assume the latter, however, birds have begun to rent kumquats over the past few months, specifically for chickens associated with their watermelons.`,
author: users.find((user) => user.username === 'john-doe'),
author: users.find((user) => user.username === 'john-doe')!,
});
await articleFactory.save({
id: '31a10506-c334-4841-97a6-144a55bf4ebb',
Expand All @@ -32,7 +32,7 @@ Though we assume the latter, however, birds have begun to rent kumquats over the
Of course, however, plums have begun to rent raspberries over the past few months, specifically for giraffes associated with their lions.
This is not to discredit the idea that however, alligators have begun to rent sharks over the past few months, specifically for sheeps associated with their monkeys.
However, pomegranates have begun to rent sheeps over the past few months, specifically for apricots associated with their grapes.`,
author: users.find((user) => user.username === 'jane-doe'),
author: users.find((user) => user.username === 'jane-doe')!,
});

for (const author of users) {
Expand Down
16 changes: 8 additions & 8 deletions src/blog/seeders/comment.seeder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ export class CommentSeeder implements Seeder {
await Promise.allSettled([
commentFactory.save({
id: '9395e782-367b-4487-a048-242e37169109',
article: article1,
author: jane,
article: article1!,
author: jane!,
}),
commentFactory.saveMany(14, {
article: article1,
author: jane,
article: article1!,
author: jane!,
}),
commentFactory.save({
id: '2cce7079-b434-42fb-85e3-8d1aadd7bb8a',
article: article2,
author: john,
article: article2!,
author: john!,
}),
commentFactory.saveMany(14, {
article: article2,
author: john,
article: article2!,
author: john!,
}),
]);
}
Expand Down
Loading

0 comments on commit 1b3db6e

Please sign in to comment.