Skip to content
This repository has been archived by the owner on Feb 3, 2025. It is now read-only.

Commit

Permalink
chore(): update to 0.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominic-Preap committed Mar 27, 2021
1 parent 402851a commit eb6f0ca
Show file tree
Hide file tree
Showing 70 changed files with 1,778 additions and 1,943 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"bracketSpacing": true,
"printWidth": 120,
"printWidth": 100,
"semi": true,
"singleQuote": true,
"tabWidth": 2,
Expand Down
7 changes: 3 additions & 4 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"EditorConfig.EditorConfig",
"Tyriar.sort-lines",
"aaron-bond.better-comments",
"alefragnani.Bookmarks",
"christian-kohler.path-intellisense",
"ionutvmi.path-autocomplete",
"abierbaum.vscode-file-peek",
"dbaeumer.vscode-eslint",
"eamodio.gitlens",
"esbenp.prettier-vscode",
Expand All @@ -15,7 +15,6 @@
"rbbit.typescript-hero",
"streetsidesoftware.code-spell-checker",
"vscode-icons-team.vscode-icons",
"xabikos.JavaScriptSnippets",
"yzhang.markdown-all-in-one"
"xabikos.JavaScriptSnippets"
]
}
74 changes: 9 additions & 65 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"editor.formatOnSave": true,
"editor.tabSize": 2,
"editor.formatOnSave": false,
"typescriptHero.imports.organizeOnSave": true,
"typescriptHero.imports.grouping": [
"Plains",
"Modules",
"/^@api|@common|@dynamodb|@entities|@lib|@models|@queries|@repositories|@schemas/",
"Workspace"
],
"files.exclude": {
"**/.git": true,
"**/.svn": true,
Expand All @@ -13,72 +20,9 @@
"dist": true,
"node_modules": true
},
"git.autofetch": true,
"typescriptHero.imports.multiLineTrailingComma": false,
"typescriptHero.imports.multiLineWrapThreshold": 120,
"typescriptHero.imports.removeTrailingIndex": true,
"typescript.tsdk": "node_modules/typescript/lib",
"typescriptHero.imports.grouping": [
"Plains",
"Modules",
"/^@api|@common|@dynamodb|@entities|@lib|@models|@queries|@repositories|@schemas/",
"Workspace"
],
"search.exclude": {
"**/node_modules": true,
"**/bower_components": true,
"**/dist": true
},
"cSpell.words": [
"Certbot",
"Injectable",
"Metacounter",
"NOFIELDS",
"Nginx",
"Twilio",
"Typegoose",
"UNPROCESSABLE",
"Unban",
"Unbans",
"Unmutes",
"Unregisters",
"Urlencoding",
"Validators",
"WHEREEVAL",
"WHEREEVALSHA",
"Webhook",
"Whitelisted",
"aofmd",
"apns",
"backend",
"bolditalics",
"callsite",
"cognito",
"dayoff",
"dynamodb",
"elasticbeanstalk",
"gmail",
"homenet",
"keycloak",
"ldap",
"middlewares",
"mimetype",
"nestjs",
"originalname",
"pathmazing",
"pdfmake",
"promisify",
"randomatic",
"sendbird",
"systemctl",
"timestamps",
"typeorm",
"udid",
"undoable",
"unmock",
"upsert",
"webhooks",
"websockets",
"wowza"
]
}
}
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# CHANGELOG

## 0.12.0

_*Mar 27, 2021*_

- add `BaseRepository` in `@lib/typeorm` for custom raw query
- add interfaces directory in `@models`
- update `jest` configuration
- update `@lib/mongoose` on deprecation warning
- update `printWidth` option to 100 in `.prettierrc`
- update linter to all files
- update testing spec example in `AuthModule`
- update `@lib/sequelize` using `@nestjs/sequelize`
- update prefix `Model` to model class in `@models`
- update sequelize controller
- update SQL example files in `@queries`
- update plopfile on `sequelize` and `typeorm`
- remove `ToArrayCreateLang`, `ToArrayUpdateLang` in `@lib/sequelize`
- remove `sequelize.interfaces.ts` in `@lib/sequelize`
- remove unnecessary functions in `user.model.ts`
- remove `Cat`, `CatLocale` and `Language` model in `@models`
- remove `rate-limiting.guard.ts` in favor of `nestjs/throttler`
- remove `@types/callsite` in `package.json`

## 0.11.0

_*Feb 05, 2021*_
Expand Down
13 changes: 13 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { pathsToModuleNameMapper } = require('ts-jest/utils');
const { compilerOptions } = require('./tsconfig');

module.exports = {
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/' }),
moduleFileExtensions: ['ts', 'tsx', 'js', 'json'],
collectCoverageFrom: ['src/**/*.{js,jsx,tsx,ts}', '!**/node_modules/**', '!**/vendor/**'],
coverageReporters: ['json', 'lcov'],
testRegex: '/src/.*\\.(test|spec).(ts|tsx|js)$',
transform: {
'^.+\\.tsx?$': 'ts-jest'
},
};
14 changes: 0 additions & 14 deletions jest.json

This file was deleted.

36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "backend-core-project",
"description": "backend-core-project description",
"version": "0.11.0",
"version": "0.12.0",
"private": true,
"engines": {
"node": ">= 12.13.0"
Expand All @@ -14,9 +14,9 @@
"format": "prettier \"**/*.ts\" --write && git status",
"lint": "eslint \"src/**/*.ts\" --fix --ignore-pattern \"**/*.spec.ts\"",
"i18next": "node src/lib/i18next/i18next.converter.js",
"test": "jest --config=jest.json",
"test:watch": "jest --watch --config=jest.json",
"test:coverage": "jest --config=jest.json --coverage --coverageDirectory=coverage",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage --coverageDirectory=coverage",
"e2e": "jest --config=e2e/jest-e2e.json --forceExit --detectOpenHandles",
"e2e:watch": "jest --watch --config=e2e/jest-e2e.json",
"compodoc": "compodoc -p tsconfig.json -s",
Expand All @@ -40,17 +40,18 @@
"@aws/dynamodb-data-mapper": "0.7.3",
"@aws/dynamodb-data-mapper-annotations": "0.7.3",
"@google-cloud/storage": "5.7.0",
"@nestjs/common": "7.6.4",
"@nestjs/config": "0.6.1",
"@nestjs/core": "7.6.4",
"@nestjs/common": "7.6.13",
"@nestjs/config": "0.6.3",
"@nestjs/core": "7.6.13",
"@nestjs/jwt": "7.2.0",
"@nestjs/passport": "7.1.5",
"@nestjs/platform-express": "7.6.4",
"@nestjs/platform-socket.io": "7.6.4",
"@nestjs/schedule": "0.4.1",
"@nestjs/swagger": "4.7.8",
"@nestjs/platform-express": "7.6.13",
"@nestjs/platform-socket.io": "7.6.13",
"@nestjs/schedule": "0.4.2",
"@nestjs/sequelize": "^0.2.0",
"@nestjs/swagger": "4.7.15",
"@nestjs/typeorm": "7.1.5",
"@nestjs/websockets": "7.6.4",
"@nestjs/websockets": "7.6.13",
"@typegoose/typegoose": "7.4.5",
"archiver": "5.1.0",
"auth0": "2.31.0",
Expand Down Expand Up @@ -96,8 +97,8 @@
"reflect-metadata": "0.1.13",
"rxjs": "6.6.3",
"sanitize-html": "2.3.0",
"sequelize": "5.22.2",
"sequelize-typescript": "1.1.0",
"sequelize": "6.5.0",
"sequelize-typescript": "2.1.0",
"sharp": "0.27.0",
"shelljs": "0.8.4",
"soap": "0.35.0",
Expand All @@ -112,12 +113,11 @@
"@commitlint/cli": "11.0.0",
"@commitlint/config-angular": "11.0.0",
"@commitlint/config-conventional": "11.0.0",
"@nestjs/cli": "7.5.4",
"@nestjs/testing": "7.6.4",
"@nestjs/cli": "7.5.6",
"@nestjs/testing": "7.6.13",
"@types/archiver": "5.1.0",
"@types/auth0": "2.20.12",
"@types/bcryptjs": "2.4.2",
"@types/callsite": "1.0.30",
"@types/compression": "1.7.0",
"@types/express": "4.17.9",
"@types/html-entities": "1.2.16",
Expand All @@ -144,7 +144,7 @@
"eslint": "7.16.0",
"eslint-config-prettier": "7.1.0",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-prettier": "3.3.0",
"eslint-plugin-prettier": "3.3.1",
"graphql": "15.4.0",
"husky": "4.3.6",
"jest": "26.6.3",
Expand Down
4 changes: 2 additions & 2 deletions plopfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,10 @@ module.exports = function (
sequelize: [
'callsites',
'mysql2',
'@nestjs/sequelize',
'sequelize',
'sequelize-typescript',
'string-template',
'@types/callsite',
'@types/node',
'@types/string-template'
],
Expand All @@ -360,7 +360,7 @@ module.exports = function (
'@types/socket.io-redis'
],
tile38: ['ioredis', '@types/ioredis'],
typeorm: ['@nestjs/typeorm', 'mysql2', 'typeorm'],
typeorm: ['@nestjs/typeorm', 'mysql2', 'typeorm', 'callsites'],
twilio: ['twilio'],
wowza: [],
// -------------------------------------------------
Expand Down
37 changes: 27 additions & 10 deletions src/api/auth/auth.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,46 @@
import { Test } from '@nestjs/testing';

import { ConfigModule } from '../../lib/config';
import { ConfigModule } from '@lib/config';
import { JwtModule } from '@lib/jwt';

import { AuthController } from './auth.controller';
import { AuthService } from './auth.service';

describe('CatsController', () => {
describe('AuthController', () => {
let authController: AuthController;
let authService: AuthService;

beforeEach(async () => {
const module = await Test.createTestingModule({
imports: [ConfigModule],
imports: [ConfigModule, JwtModule],
controllers: [AuthController],
providers: [AuthService]
providers: [
{
provide: AuthService,
useValue: {
login: jest.fn(() => ({ accessToken: 'ACCESS_TOKEN' })),
authorize: jest.fn(() => ({ token: 'TOKEN' }))
}
}
]
}).compile();

authService = module.get<AuthService>(AuthService);
authController = module.get<AuthController>(AuthController);
});

describe('login', () => {
it('should return true', async () => {
const result = true;
jest.spyOn(authService, 'login').mockImplementation(() => result);
expect(await authController.login({ username: 'A', password: 'A' })).toBe(result);
it('should return access token', async () => {
const body = { username: 'john', password: 'doe' };
const result = { accessToken: 'ACCESS_TOKEN' };
expect(await authController.login(body)).toMatchObject(result);
});
});

describe('authorize', () => {
it('should return token', async () => {
const body = { clientId: 'x' };
const header = { udid: 'x' };
const result = { token: 'TOKEN' };
expect(await authController.authorize(body, header as any)).toMatchObject(result);
});
});
});
22 changes: 18 additions & 4 deletions src/api/auth/auth.guard.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { CanActivate, ExecutionContext, ForbiddenException, Injectable, UnauthorizedException } from '@nestjs/common';
import {
CanActivate,
ExecutionContext,
ForbiddenException,
Injectable,
UnauthorizedException
} from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import { JwtService } from '@nestjs/jwt';
import { Request } from 'express';
Expand Down Expand Up @@ -30,7 +36,8 @@ export class AuthGuard implements CanActivate {
}

async checkUserScheme(scheme: string, token: string, roles: string[]) {
if (scheme.toLowerCase() !== 'bearer') throw new UnauthorizedException('Invalid Authorization Scheme');
if (scheme.toLowerCase() !== 'bearer')
throw new UnauthorizedException('Invalid Authorization Scheme');
if (!token) throw new UnauthorizedException('Authorization token is missing.');

let decoded: JWTPayload;
Expand All @@ -43,9 +50,16 @@ export class AuthGuard implements CanActivate {

// TODO: use your own user table
// const user = await User.findById(jwtDecoded.id);
const user = { id: 1, username: 'my-username', password: 'my-password', isArchived: false, role: 'admin' };
const user = {
id: 1,
username: 'my-username',
password: 'my-password',
isArchived: false,
role: 'admin'
};
if (!user || user.isArchived) throw new ForbiddenException('Unknown User');
if (roles.length > 0 && !roles.find(x => x === user.role)) throw new ForbiddenException('Invalid User Role');
if (roles.length > 0 && !roles.find(x => x === user.role))
throw new ForbiddenException('Invalid User Role');

return user;
}
Expand Down
Loading

0 comments on commit eb6f0ca

Please sign in to comment.