Skip to content

Commit 48b01c2

Browse files
authored
Merge pull request #19 from pct-org/improvements
Improvements
2 parents 8dc2be7 + 777dba4 commit 48b01c2

File tree

210 files changed

+6825
-8525
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

210 files changed

+6825
-8525
lines changed

.env.example

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ MONGO_URI=127.0.0.1
1515
# The port of the MongoDB database.
1616
MONGO_PORT=27017
1717

18-
# The username of the MongoDB database, disbale if none.
18+
# The username of the MongoDB database, disable if none.
1919
MONGO_USER=
2020

21-
# The password of the MongoDB database, disbale if none.
21+
# The password of the MongoDB database, disable if none.
2222
MONGO_PASS=
2323

2424
# The url to the scraper
@@ -36,6 +36,7 @@ OPENSUBTITLES_PASSWORD=
3636

3737
# API key for Trakt
3838
TRAKT_KEY=
39+
TMDB_KEY=
3940

4041
# The time between cronjobs.
4142
CRON_TIME='0 0 3 * * *'

.eslintrc.json

+38-50
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,54 @@
11
{
22
"root": true,
3-
"parser": "@typescript-eslint/parser",
4-
"parserOptions": {
5-
"ecmaVersion": 2018,
6-
"sourceType": "module",
7-
"project": "./tsconfig.*?.json"
8-
},
9-
"ignorePatterns": [
10-
"**/*"
11-
],
12-
"plugins": [
13-
"@typescript-eslint",
14-
"@nrwl/nx"
15-
],
16-
"extends": [
17-
"eslint:recommended",
18-
"plugin:@typescript-eslint/eslint-recommended",
19-
"plugin:@typescript-eslint/recommended",
20-
"prettier",
21-
"prettier/@typescript-eslint"
22-
],
23-
"rules": {
24-
"@typescript-eslint/no-inferrable-types": "off",
25-
"@typescript-eslint/explicit-member-accessibility": "off",
26-
"@typescript-eslint/explicit-module-boundary-types": "off",
27-
"@typescript-eslint/explicit-function-return-type": "off",
28-
"@typescript-eslint/no-parameter-properties": "off",
29-
"@nrwl/nx/enforce-module-boundaries": [
30-
"error",
31-
{
32-
"enforceBuildableLibDependency": true,
33-
"allow": [],
34-
"depConstraints": [
3+
"ignorePatterns": ["**/*"],
4+
"plugins": ["@nrwl/nx"],
5+
"overrides": [
6+
{
7+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
8+
"rules": {
9+
"semi": ["warn", "never"],
10+
"@nrwl/nx/enforce-module-boundaries": [
11+
"error",
3512
{
36-
"sourceTag": "*",
37-
"onlyDependOnLibsWithTags": [
38-
"*"
13+
"enforceBuildableLibDependency": true,
14+
"allow": ["@danone-global/internal/react/testing"],
15+
"depConstraints": [
16+
{
17+
"sourceTag": "*",
18+
"onlyDependOnLibsWithTags": ["*"]
19+
}
3920
]
4021
}
4122
]
4223
}
43-
]
44-
},
45-
"overrides": [
24+
},
4625
{
47-
"files": [
48-
"**/*.spec.js",
49-
"**/*.spec.jsx",
50-
"**/*.spec.ts",
51-
"**/*.spec.tsx"
52-
],
53-
"env": {
54-
"jest": true
26+
"files": ["*.ts", "*.tsx"],
27+
"extends": ["plugin:@nrwl/nx/typescript"],
28+
"parserOptions": {
29+
"project": "./tsconfig.*?.json"
30+
},
31+
"rules": {
32+
"no-unneeded-ternary": ["error"],
33+
"no-nested-ternary": ["error"],
34+
"multiline-ternary": ["error", "always-multiline"],
35+
"operator-linebreak": ["error", "before"]
5536
}
5637
},
5738
{
58-
"files": [
59-
"*.tsx"
60-
],
39+
"files": ["*.tsx"],
6140
"rules": {
62-
"@typescript-eslint/no-unused-vars": "off"
41+
"react/jsx-max-props-per-line": [
42+
"warn",
43+
{ "maximum": 1, "when": "always" }
44+
],
45+
"react/jsx-first-prop-new-line": ["warn", "multiline"],
46+
"react/jsx-indent-props": ["warn", 2]
6347
}
48+
},
49+
{
50+
"files": ["*.js", "*.jsx"],
51+
"extends": ["plugin:@nrwl/nx/javascript"]
6452
}
6553
]
6654
}

.github/workflows/pr.yml

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: PR
22

3-
on: [ pull_request ]
3+
on: [pull_request]
44

55
jobs:
66
checks:
@@ -12,9 +12,9 @@ jobs:
1212
fetch-depth: 0
1313

1414
- name: Use Node.js
15-
uses: actions/setup-node@v1
15+
uses: actions/setup-node@v2
1616
with:
17-
node-version: 12.x
17+
node-version: 14.x
1818

1919
- uses: actions/cache@v2
2020
with:
@@ -24,8 +24,10 @@ jobs:
2424
- name: Install dependencies
2525
run: yarn
2626

27+
- name: Build
28+
run: yarn affected:build --base=origin/master
29+
2730
- name: Lint
2831
run: yarn affected:lint --base=origin/master
29-
3032
# - name: Test
3133
# run: yarn affected:test --base=master --head=HEAD

.prettierrc

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"singleQuote": true,
3-
"trailingComma": "all"
4-
}
3+
"trailingComma": "none",
4+
"semi": false
5+
}

apps/api/jest.config.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ module.exports = {
22
name: 'graphql-api',
33
preset: '../../jest.config.js',
44
globals: {
5-
'ts-jest': {
6-
tsConfig: '<rootDir>/tsconfig.spec.json',
7-
},
5+
'ts-jest': { tsconfig: '<rootDir>/tsconfig.spec.json' }
86
},
97
transform: {
10-
'^.+\\.[tj]s$': 'ts-jest',
8+
'^.+\\.[tj]s$': 'ts-jest'
119
},
1210
moduleFileExtensions: ['ts', 'js', 'html'],
1311
coverageDirectory: '../../coverage/apps/graphql-api',
14-
};
12+
testEnvironment: 'node'
13+
}

apps/api/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pct-org/graphql-api",
3-
"version": "1.0.0-alpha.1",
3+
"version": "5.0.0",
44
"description": "GraphQL API for the PCT environment",
55
"repository": {
66
"type": "git",

apps/api/project.json

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"root": "apps/api",
3+
"sourceRoot": "apps/api/src",
4+
"projectType": "application",
5+
"prefix": "api",
6+
"generators": {},
7+
"targets": {
8+
"build": {
9+
"executor": "@nrwl/node:build",
10+
"options": {
11+
"outputPath": "dist/apps/api",
12+
"main": "apps/api/src/main.ts",
13+
"tsConfig": "apps/api/tsconfig.app.json"
14+
},
15+
"configurations": {
16+
"production": {
17+
"optimization": true,
18+
"extractLicenses": false,
19+
"inspect": false
20+
}
21+
}
22+
},
23+
"serve": {
24+
"executor": "@nrwl/node:execute",
25+
"options": {
26+
"buildTarget": "api:build"
27+
}
28+
},
29+
"lint": {
30+
"executor": "@nrwl/linter:lint",
31+
"options": {
32+
"linter": "eslint",
33+
"tsConfig": [
34+
"apps/api/tsconfig.app.json",
35+
"apps/api/tsconfig.spec.json"
36+
],
37+
"exclude": ["**/node_modules/**", "!apps/api/**/*"]
38+
}
39+
},
40+
"test": {
41+
"executor": "@nrwl/jest:jest",
42+
"options": {
43+
"jestConfig": "apps/api/jest.config.js",
44+
"passWithNoTests": true
45+
}
46+
}
47+
},
48+
"tags": []
49+
}

apps/api/src/app.module.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Module } from '@nestjs/common'
22
import { GraphQLModule } from '@nestjs/graphql'
3-
import { MongooseModule } from '@nestjs/mongoose'
3+
import { ApolloDriver } from '@nestjs/apollo'
4+
import { MongooseModule, MongooseModuleOptions } from '@nestjs/mongoose'
45

56
import { ModelsModule } from './shared/models.module'
67
import { ConfigModule } from './shared/config/config.module'
@@ -54,24 +55,22 @@ import { WatchModule } from './watch/watch.module'
5455
imports: [ConfigModule],
5556
inject: [ConfigService],
5657
useFactory: (configService: ConfigService) => ({
57-
uri: configService.databaseUri,
58-
useNewUrlParser: true,
59-
useUnifiedTopology: true,
60-
useFindAndModify: false
58+
uri: configService.databaseUri
6159
})
6260
}),
6361

6462
// Enable Graphql
6563
GraphQLModule.forRootAsync({
6664
imports: [ConfigModule],
6765
inject: [ConfigService],
66+
driver: ApolloDriver,
6867
useFactory: (configService: ConfigService) => ({
6968
debug: configService.isDevelopment,
7069
tracing: configService.isDevelopment,
7170
playground: true,
7271
installSubscriptionHandlers: true,
7372
autoSchemaFile: 'schema.gql',
74-
introspection: true,
73+
introspection: true
7574
})
7675
})
7776
]

apps/api/src/bookmarks/bookmarks.service.ts

+26-22
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
import { Injectable } from '@nestjs/common'
22
import { InjectModel } from '@nestjs/mongoose'
3-
import { MovieModel, MOVIES_TYPE } from '@pct-org/types/movie'
4-
import { ShowModel, SHOWS_TYPE } from '@pct-org/types/show'
3+
import { MovieDocument, MOVIES_TYPE } from '@pct-org/types/movie'
4+
import { ShowDocument, SHOWS_TYPE } from '@pct-org/types/show'
55
import { Content } from '@pct-org/types/shared'
66

7+
import type { Model } from 'mongoose'
8+
79
import { BookmarksArgs } from './dto/bookmarks.args'
810
import { NewBookmarkInput } from './dto/new-bookmark.input'
911

1012
@Injectable()
1113
export class BookmarksService {
1214

1315
@InjectModel('Movies')
14-
private readonly movieModel: MovieModel
16+
private readonly movieModel: Model<MovieDocument>
1517

1618
@InjectModel('Shows')
17-
private readonly showModel: ShowModel
19+
private readonly showModel: Model<ShowDocument>
1820

1921
public async findAll(bookmarksArgs: BookmarksArgs): Promise<Content[]> {
2022
const movies = ['none', MOVIES_TYPE].includes(bookmarksArgs.filter)
@@ -65,24 +67,24 @@ export class BookmarksService {
6567
* @param {boolean} add - Do we need to add or remove the bookmark
6668
*/
6769
public async updateBookmark(addBookmarksArgs: NewBookmarkInput, add: boolean): Promise<Content> {
68-
return (
69-
addBookmarksArgs.type === 'movie'
70-
? this.movieModel
71-
: this.showModel
70+
const update = {
71+
bookmarked: add,
72+
bookmarkedOn: add
73+
? Number(new Date())
74+
: null
75+
}
7276

73-
).findByIdAndUpdate(
74-
addBookmarksArgs._id,
75-
{
76-
bookmarked: add,
77-
bookmarkedOn: add
78-
? Number(new Date())
79-
: null
80-
},
81-
{
82-
new: true, // Return the new updated object
83-
lean: true
84-
}
85-
)
77+
const options = {
78+
new: true, // Return the new updated object
79+
lean: true
80+
}
81+
82+
if (addBookmarksArgs.type === 'movie') {
83+
return this.movieModel.findByIdAndUpdate(addBookmarksArgs._id, update, options)
84+
85+
} else {
86+
return this.showModel.findByIdAndUpdate(addBookmarksArgs._id, update, options)
87+
}
8688
}
8789

8890
/**
@@ -101,7 +103,9 @@ export class BookmarksService {
101103
bookmarked: true,
102104
title: {
103105
// Update the query to make it better searchable
104-
$regex: bookmarksArgs.query.trim().split(' ').join('.+'),
106+
$regex: bookmarksArgs.query.trim()
107+
.split(' ')
108+
.join('.+'),
105109
$options: 'i'
106110
}
107111
}

apps/api/src/bookmarks/bookmarks.union.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ export const BookmarksUnion = createUnionType({
77
types: () => [Movie, Show],
88
resolveType(value) {
99
if (value.type === MOVIE_TYPE) {
10-
return Movie
10+
return 'Movie'
1111
}
1212

1313
if (value.type === SHOW_TYPE) {
14-
return Show
14+
return 'Show'
1515
}
1616

1717
return null

0 commit comments

Comments
 (0)