Skip to content

Commit

Permalink
Merge pull request #19 from pct-org/improvements
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
TriPSs authored Dec 11, 2023
2 parents 8dc2be7 + 777dba4 commit 48b01c2
Show file tree
Hide file tree
Showing 210 changed files with 6,825 additions and 8,525 deletions.
5 changes: 3 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ MONGO_URI=127.0.0.1
# The port of the MongoDB database.
MONGO_PORT=27017

# The username of the MongoDB database, disbale if none.
# The username of the MongoDB database, disable if none.
MONGO_USER=

# The password of the MongoDB database, disbale if none.
# The password of the MongoDB database, disable if none.
MONGO_PASS=

# The url to the scraper
Expand All @@ -36,6 +36,7 @@ OPENSUBTITLES_PASSWORD=

# API key for Trakt
TRAKT_KEY=
TMDB_KEY=

# The time between cronjobs.
CRON_TIME='0 0 3 * * *'
Expand Down
88 changes: 38 additions & 50 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,66 +1,54 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module",
"project": "./tsconfig.*?.json"
},
"ignorePatterns": [
"**/*"
],
"plugins": [
"@typescript-eslint",
"@nrwl/nx"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
"prettier/@typescript-eslint"
],
"rules": {
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/explicit-member-accessibility": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-parameter-properties": "off",
"@nrwl/nx/enforce-module-boundaries": [
"error",
{
"enforceBuildableLibDependency": true,
"allow": [],
"depConstraints": [
"ignorePatterns": ["**/*"],
"plugins": ["@nrwl/nx"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {
"semi": ["warn", "never"],
"@nrwl/nx/enforce-module-boundaries": [
"error",
{
"sourceTag": "*",
"onlyDependOnLibsWithTags": [
"*"
"enforceBuildableLibDependency": true,
"allow": ["@danone-global/internal/react/testing"],
"depConstraints": [
{
"sourceTag": "*",
"onlyDependOnLibsWithTags": ["*"]
}
]
}
]
}
]
},
"overrides": [
},
{
"files": [
"**/*.spec.js",
"**/*.spec.jsx",
"**/*.spec.ts",
"**/*.spec.tsx"
],
"env": {
"jest": true
"files": ["*.ts", "*.tsx"],
"extends": ["plugin:@nrwl/nx/typescript"],
"parserOptions": {
"project": "./tsconfig.*?.json"
},
"rules": {
"no-unneeded-ternary": ["error"],
"no-nested-ternary": ["error"],
"multiline-ternary": ["error", "always-multiline"],
"operator-linebreak": ["error", "before"]
}
},
{
"files": [
"*.tsx"
],
"files": ["*.tsx"],
"rules": {
"@typescript-eslint/no-unused-vars": "off"
"react/jsx-max-props-per-line": [
"warn",
{ "maximum": 1, "when": "always" }
],
"react/jsx-first-prop-new-line": ["warn", "multiline"],
"react/jsx-indent-props": ["warn", 2]
}
},
{
"files": ["*.js", "*.jsx"],
"extends": ["plugin:@nrwl/nx/javascript"]
}
]
}
10 changes: 6 additions & 4 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: PR

on: [ pull_request ]
on: [pull_request]

jobs:
checks:
Expand All @@ -12,9 +12,9 @@ jobs:
fetch-depth: 0

- name: Use Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v2
with:
node-version: 12.x
node-version: 14.x

- uses: actions/cache@v2
with:
Expand All @@ -24,8 +24,10 @@ jobs:
- name: Install dependencies
run: yarn

- name: Build
run: yarn affected:build --base=origin/master

- name: Lint
run: yarn affected:lint --base=origin/master

# - name: Test
# run: yarn affected:test --base=master --head=HEAD
5 changes: 3 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"singleQuote": true,
"trailingComma": "all"
}
"trailingComma": "none",
"semi": false
}
9 changes: 4 additions & 5 deletions apps/api/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ module.exports = {
name: 'graphql-api',
preset: '../../jest.config.js',
globals: {
'ts-jest': {
tsConfig: '<rootDir>/tsconfig.spec.json',
},
'ts-jest': { tsconfig: '<rootDir>/tsconfig.spec.json' }
},
transform: {
'^.+\\.[tj]s$': 'ts-jest',
'^.+\\.[tj]s$': 'ts-jest'
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/apps/graphql-api',
};
testEnvironment: 'node'
}
2 changes: 1 addition & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pct-org/graphql-api",
"version": "1.0.0-alpha.1",
"version": "5.0.0",
"description": "GraphQL API for the PCT environment",
"repository": {
"type": "git",
Expand Down
49 changes: 49 additions & 0 deletions apps/api/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"root": "apps/api",
"sourceRoot": "apps/api/src",
"projectType": "application",
"prefix": "api",
"generators": {},
"targets": {
"build": {
"executor": "@nrwl/node:build",
"options": {
"outputPath": "dist/apps/api",
"main": "apps/api/src/main.ts",
"tsConfig": "apps/api/tsconfig.app.json"
},
"configurations": {
"production": {
"optimization": true,
"extractLicenses": false,
"inspect": false
}
}
},
"serve": {
"executor": "@nrwl/node:execute",
"options": {
"buildTarget": "api:build"
}
},
"lint": {
"executor": "@nrwl/linter:lint",
"options": {
"linter": "eslint",
"tsConfig": [
"apps/api/tsconfig.app.json",
"apps/api/tsconfig.spec.json"
],
"exclude": ["**/node_modules/**", "!apps/api/**/*"]
}
},
"test": {
"executor": "@nrwl/jest:jest",
"options": {
"jestConfig": "apps/api/jest.config.js",
"passWithNoTests": true
}
}
},
"tags": []
}
11 changes: 5 additions & 6 deletions apps/api/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Module } from '@nestjs/common'
import { GraphQLModule } from '@nestjs/graphql'
import { MongooseModule } from '@nestjs/mongoose'
import { ApolloDriver } from '@nestjs/apollo'
import { MongooseModule, MongooseModuleOptions } from '@nestjs/mongoose'

import { ModelsModule } from './shared/models.module'
import { ConfigModule } from './shared/config/config.module'
Expand Down Expand Up @@ -54,24 +55,22 @@ import { WatchModule } from './watch/watch.module'
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (configService: ConfigService) => ({
uri: configService.databaseUri,
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false
uri: configService.databaseUri
})
}),

// Enable Graphql
GraphQLModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
driver: ApolloDriver,
useFactory: (configService: ConfigService) => ({
debug: configService.isDevelopment,
tracing: configService.isDevelopment,
playground: true,
installSubscriptionHandlers: true,
autoSchemaFile: 'schema.gql',
introspection: true,
introspection: true
})
})
]
Expand Down
48 changes: 26 additions & 22 deletions apps/api/src/bookmarks/bookmarks.service.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { Injectable } from '@nestjs/common'
import { InjectModel } from '@nestjs/mongoose'
import { MovieModel, MOVIES_TYPE } from '@pct-org/types/movie'
import { ShowModel, SHOWS_TYPE } from '@pct-org/types/show'
import { MovieDocument, MOVIES_TYPE } from '@pct-org/types/movie'
import { ShowDocument, SHOWS_TYPE } from '@pct-org/types/show'
import { Content } from '@pct-org/types/shared'

import type { Model } from 'mongoose'

import { BookmarksArgs } from './dto/bookmarks.args'
import { NewBookmarkInput } from './dto/new-bookmark.input'

@Injectable()
export class BookmarksService {

@InjectModel('Movies')
private readonly movieModel: MovieModel
private readonly movieModel: Model<MovieDocument>

@InjectModel('Shows')
private readonly showModel: ShowModel
private readonly showModel: Model<ShowDocument>

public async findAll(bookmarksArgs: BookmarksArgs): Promise<Content[]> {
const movies = ['none', MOVIES_TYPE].includes(bookmarksArgs.filter)
Expand Down Expand Up @@ -65,24 +67,24 @@ export class BookmarksService {
* @param {boolean} add - Do we need to add or remove the bookmark
*/
public async updateBookmark(addBookmarksArgs: NewBookmarkInput, add: boolean): Promise<Content> {
return (
addBookmarksArgs.type === 'movie'
? this.movieModel
: this.showModel
const update = {
bookmarked: add,
bookmarkedOn: add
? Number(new Date())
: null
}

).findByIdAndUpdate(
addBookmarksArgs._id,
{
bookmarked: add,
bookmarkedOn: add
? Number(new Date())
: null
},
{
new: true, // Return the new updated object
lean: true
}
)
const options = {
new: true, // Return the new updated object
lean: true
}

if (addBookmarksArgs.type === 'movie') {
return this.movieModel.findByIdAndUpdate(addBookmarksArgs._id, update, options)

} else {
return this.showModel.findByIdAndUpdate(addBookmarksArgs._id, update, options)
}
}

/**
Expand All @@ -101,7 +103,9 @@ export class BookmarksService {
bookmarked: true,
title: {
// Update the query to make it better searchable
$regex: bookmarksArgs.query.trim().split(' ').join('.+'),
$regex: bookmarksArgs.query.trim()
.split(' ')
.join('.+'),
$options: 'i'
}
}
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/bookmarks/bookmarks.union.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ export const BookmarksUnion = createUnionType({
types: () => [Movie, Show],
resolveType(value) {
if (value.type === MOVIE_TYPE) {
return Movie
return 'Movie'
}

if (value.type === SHOW_TYPE) {
return Show
return 'Show'
}

return null
Expand Down
Loading

0 comments on commit 48b01c2

Please sign in to comment.