-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from Mango-Entertainment/cleanup-code
Cleanup code
Showing
43 changed files
with
1,170 additions
and
824 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const eslintConfigPrettier = require('eslint-config-prettier') | ||
|
||
module.exports = { | ||
root: true, | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { ecmaVersion: 12, sourceType: 'module' }, | ||
plugins: ['@typescript-eslint'], | ||
extends: ['next/core-web-vitals', 'prettier'], | ||
overrides: [ | ||
{ | ||
files: ['*.ts', '*.tsx'], | ||
parserOptions: { | ||
project: ['./tsconfig.json'], | ||
tsconfigRootDir: __dirname, | ||
}, | ||
extends: [ | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:@typescript-eslint/recommended-requiring-type-checking', | ||
|
||
//declaring 'next/core-web-vitals' and 'prettier' again in case | ||
//the two plugin:... configs above overrode any of their rules | ||
//Also, 'prettier' needs to be last in any extends array | ||
'next/core-web-vitals', | ||
'prettier', | ||
], | ||
}, | ||
], | ||
rules: { | ||
'@typescript-eslint/no-unused-vars': 'error', | ||
'@typescript-eslint/consistent-type-definitions': ['error', 'type'], | ||
}, | ||
eslintConfigPrettier, | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"semi": false, | ||
"singleQuote": true, | ||
"tabWidth": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,206 +1,105 @@ | ||
import { | ||
TrendingThumbs, | ||
Selection, | ||
RegularThumbs, | ||
TrendingData, | ||
RegularData, | ||
} from "@/app/lib/definitions"; | ||
import postgres from "postgres"; | ||
import { TrendingData, RegularData } from '@/app/lib/definitions' | ||
import postgres from 'postgres' | ||
|
||
const connectionString = `${process.env.SUPABASE_POSTGRES_CONNECTION_STRING}` | ||
const sql = postgres(connectionString) | ||
|
||
export const getTrending = async () => { | ||
try { | ||
const result: TrendingData[] = [] | ||
const data = await sql`SELECT selections.id, selections.title, selections.rating, selections.year, selections.category, selections.is_bookmarked, trending_thumbs.large, trending_thumbs.small | ||
FROM selections | ||
JOIN trending_thumbs ON trending_thumbs.selection_id = selections.id`; | ||
data.forEach(item => { | ||
const {id, title, rating, year, category, is_bookmarked, large, small} = item | ||
result.push({id, title, rating, year, category, is_bookmarked, large, small})}) | ||
return result | ||
const data = | ||
await sql`SELECT selections.id, selections.title, selections.rating, selections.year, selections.category, selections.is_bookmarked, trending_thumbs.large, trending_thumbs.small | ||
FROM selections | ||
JOIN trending_thumbs ON trending_thumbs.selection_id = selections.id` | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
data.forEach((item) => result.push(item)) | ||
return result | ||
} catch (error) { | ||
console.error('Database Error:', error); | ||
throw new Error('Failed to fetch trending data.'); | ||
console.error('Database Error:', error) | ||
throw new Error('Failed to fetch trending data.') | ||
} | ||
}; | ||
} | ||
|
||
export const getRecommended = async () => { | ||
try { | ||
const result: RegularData[] = []; | ||
const result: RegularData[] = [] | ||
const data = | ||
await sql`SELECT selections.id, selections.title, selections.rating, selections.year, selections.category, selections.is_bookmarked, regular_thumbs.large, regular_thumbs.medium, regular_thumbs.small, selections.is_trending | ||
FROM selections | ||
JOIN regular_thumbs ON regular_thumbs.selection_id = selections.id | ||
WHERE selections.is_trending != true`; | ||
data.forEach((item) => { | ||
const {id, title, rating, year, category, is_bookmarked, large, medium, small} = | ||
item; | ||
result.push({ | ||
id, | ||
title, | ||
rating, | ||
year, | ||
category, | ||
is_bookmarked, | ||
large, | ||
medium, | ||
small, | ||
}); | ||
}); | ||
return result; | ||
FROM selections | ||
JOIN regular_thumbs ON regular_thumbs.selection_id = selections.id | ||
WHERE selections.is_trending != true` | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
data.forEach((item) => result.push(item)) | ||
return result | ||
} catch (error) { | ||
console.error("Database Error:", error); | ||
throw new Error("Failed to fetch recommended data."); | ||
console.error('Database Error:', error) | ||
throw new Error('Failed to fetch recommended data.') | ||
} | ||
}; | ||
} | ||
|
||
export const getMovies = async () => { | ||
try { | ||
const result: RegularData[] = []; | ||
const result: RegularData[] = [] | ||
const data = | ||
await sql`SELECT selections.id, selections.title, selections.rating, selections.year, selections.category, selections.is_bookmarked, regular_thumbs.large, regular_thumbs.medium, regular_thumbs.small, selections.is_trending | ||
FROM selections | ||
JOIN regular_thumbs ON regular_thumbs.selection_id = selections.id | ||
WHERE selections.category = 'Movie'`; | ||
data.forEach((item) => { | ||
const { | ||
id, | ||
title, | ||
rating, | ||
year, | ||
category, | ||
is_bookmarked, | ||
large, | ||
medium, | ||
small, | ||
} = item; | ||
result.push({ | ||
id, | ||
title, | ||
rating, | ||
year, | ||
category, | ||
is_bookmarked, | ||
large, | ||
medium, | ||
small, | ||
}); | ||
}); | ||
return result; | ||
FROM selections | ||
JOIN regular_thumbs ON regular_thumbs.selection_id = selections.id | ||
WHERE selections.category = 'Movie'` | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
data.forEach((item) => result.push(item)) | ||
return result | ||
} catch (error) { | ||
console.error("Database Error:", error); | ||
throw new Error("Failed to fetch recommended data."); | ||
console.error('Database Error:', error) | ||
throw new Error('Failed to fetch movie data.') | ||
} | ||
} | ||
|
||
export const getSeries = async () => { | ||
try { | ||
const result: RegularData[] = []; | ||
const result: RegularData[] = [] | ||
const data = | ||
await sql`SELECT selections.id, selections.title, selections.rating, selections.year, selections.category, selections.is_bookmarked, regular_thumbs.large, regular_thumbs.medium, regular_thumbs.small, selections.is_trending | ||
FROM selections | ||
JOIN regular_thumbs ON regular_thumbs.selection_id = selections.id | ||
WHERE selections.category = 'TV Series'`; | ||
data.forEach((item) => { | ||
const { | ||
id, | ||
title, | ||
rating, | ||
year, | ||
category, | ||
is_bookmarked, | ||
large, | ||
medium, | ||
small, | ||
} = item; | ||
result.push({ | ||
id, | ||
title, | ||
rating, | ||
year, | ||
category, | ||
is_bookmarked, | ||
large, | ||
medium, | ||
small, | ||
}); | ||
}); | ||
return result; | ||
FROM selections | ||
JOIN regular_thumbs ON regular_thumbs.selection_id = selections.id | ||
WHERE selections.category = 'TV Series'` | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
data.forEach((item) => result.push(item)) | ||
return result | ||
} catch (error) { | ||
console.error("Database Error:", error); | ||
throw new Error("Failed to fetch recommended data."); | ||
console.error('Database Error:', error) | ||
throw new Error('Failed to fetch series data.') | ||
} | ||
}; | ||
} | ||
|
||
export const getBookmarks = async () => { | ||
try { | ||
const movieResult: RegularData[] = []; | ||
const seriesResult: RegularData[] = []; | ||
const movieResult: RegularData[] = [] | ||
const seriesResult: RegularData[] = [] | ||
const movieData = | ||
await sql`SELECT selections.id, selections.title, selections.rating, selections.year, selections.category, selections.is_bookmarked, regular_thumbs.large, regular_thumbs.medium, regular_thumbs.small, selections.is_trending | ||
FROM selections | ||
JOIN regular_thumbs ON regular_thumbs.selection_id = selections.id | ||
WHERE selections.category = 'Movie' | ||
AND selections.is_bookmarked = true`; | ||
FROM selections | ||
JOIN regular_thumbs ON regular_thumbs.selection_id = selections.id | ||
WHERE selections.category = 'Movie' | ||
AND selections.is_bookmarked = true` | ||
const seriesData = | ||
await sql`SELECT selections.id, selections.title, selections.rating, selections.year, selections.category, selections.is_bookmarked, regular_thumbs.large, regular_thumbs.medium, regular_thumbs.small, selections.is_trending | ||
FROM selections | ||
JOIN regular_thumbs ON regular_thumbs.selection_id = selections.id | ||
WHERE selections.category = 'TV Series' | ||
AND selections.is_bookmarked = true`; | ||
movieData.forEach((item) => { | ||
const { | ||
id, | ||
title, | ||
rating, | ||
year, | ||
category, | ||
is_bookmarked, | ||
large, | ||
medium, | ||
small, | ||
} = item; | ||
movieResult.push({ | ||
id, | ||
title, | ||
rating, | ||
year, | ||
category, | ||
is_bookmarked, | ||
large, | ||
medium, | ||
small, | ||
}); | ||
}); | ||
seriesData.forEach((item) => { | ||
const { | ||
id, | ||
title, | ||
rating, | ||
year, | ||
category, | ||
is_bookmarked, | ||
large, | ||
medium, | ||
small, | ||
} = item; | ||
seriesResult.push({ | ||
id, | ||
title, | ||
rating, | ||
year, | ||
category, | ||
is_bookmarked, | ||
large, | ||
medium, | ||
small, | ||
}); | ||
}); | ||
return {movies: movieResult, series: seriesResult}; | ||
FROM selections | ||
JOIN regular_thumbs ON regular_thumbs.selection_id = selections.id | ||
WHERE selections.category = 'TV Series' | ||
AND selections.is_bookmarked = true` | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
movieData.forEach((item) => movieResult.push(item)) | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
seriesData.forEach((item) => seriesResult.push(item)) | ||
return { movies: movieResult, series: seriesResult } | ||
} catch (error) { | ||
console.error("Database Error:", error); | ||
throw new Error("Failed to fetch recommended data."); | ||
console.error('Database Error:', error) | ||
throw new Error('Failed to fetch bookmark data.') | ||
} | ||
}; | ||
} |
Oops, something went wrong.