mirror of
https://github.com/ngthanhvu/kr-phim.git
synced 2026-08-10 16:47:46 +00:00
feat: add episode total handling and display across movie pages
- Implemented `getEpisodeDisplay` function to format episode information for movies. - Updated movie display components to show episode information using the new function. - Added `episodeTotal` field to the movies schema and updated related API endpoints to handle this new field. - Enhanced movie synchronization process to fetch and store episode totals from external sources. - Created a new error page component for better user experience on 404 errors. - Added migration scripts to update the database schema for episode totals.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { movies } from '../../database/schema'
|
||||
import { desc, eq, like, sql } from 'drizzle-orm'
|
||||
import { desc, eq, like, and, sql } from 'drizzle-orm'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const db = useDb()
|
||||
@@ -9,17 +9,18 @@ export default defineEventHandler(async (event) => {
|
||||
const offset = (page - 1) * limit
|
||||
const keyword = typeof query.keyword === 'string' ? query.keyword.trim() : ''
|
||||
const status = typeof query.status === 'string' ? query.status : ''
|
||||
const source = typeof query.source === 'string' ? query.source : ''
|
||||
const type = typeof query.type === 'string' ? query.type : ''
|
||||
|
||||
let whereClause = undefined
|
||||
if (keyword && status === 'active') {
|
||||
whereClause = sql`${like(movies.name, `%${keyword}%`)} AND ${movies.active} = true`
|
||||
} else if (keyword) {
|
||||
whereClause = like(movies.name, `%${keyword}%`)
|
||||
} else if (status === 'active') {
|
||||
whereClause = eq(movies.active, true)
|
||||
} else if (status === 'inactive') {
|
||||
whereClause = eq(movies.active, false)
|
||||
}
|
||||
const conditions: any[] = []
|
||||
|
||||
if (keyword) conditions.push(like(movies.name, `%${keyword}%`))
|
||||
if (status === 'active') conditions.push(eq(movies.active, true))
|
||||
else if (status === 'inactive') conditions.push(eq(movies.active, false))
|
||||
if (source) conditions.push(eq(movies.source, source))
|
||||
if (type) conditions.push(eq(movies.type, type))
|
||||
|
||||
const whereClause = conditions.length > 0 ? and(...conditions) : undefined
|
||||
|
||||
const [items, countResult] = await Promise.all([
|
||||
db
|
||||
|
||||
Reference in New Issue
Block a user