@@ -31,6 +31,20 @@ export async function deleteLeela(id: string) {
3131 revalidatePath ( '/admin/leela' , 'layout' ) ;
3232}
3333
34+ export async function getLeelasPaged ( page : number = 1 , pageSize : number = 20 ) {
35+ if ( ! await isAdmin ( ) ) throw new Error ( 'Unauthorized' ) ;
36+ const skip = ( page - 1 ) * pageSize ;
37+ const [ items , total ] = await Promise . all ( [
38+ prisma . leela . findMany ( {
39+ skip,
40+ take : pageSize ,
41+ orderBy : { orderId : 'asc' }
42+ } ) ,
43+ prisma . leela . count ( )
44+ ] ) ;
45+ return { items, total, hasMore : total > skip + items . length } ;
46+ }
47+
3448// Bodhakatha Actions
3549export async function saveBodhakatha ( data : any ) {
3650 if ( ! await isAdmin ( ) ) throw new Error ( 'Unauthorized' ) ;
@@ -57,6 +71,20 @@ export async function deleteBodhakatha(id: string) {
5771 revalidatePath ( '/admin/bodhakatha' , 'layout' ) ;
5872}
5973
74+ export async function getBodhakathasPaged ( page : number = 1 , pageSize : number = 20 ) {
75+ if ( ! await isAdmin ( ) ) throw new Error ( 'Unauthorized' ) ;
76+ const skip = ( page - 1 ) * pageSize ;
77+ const [ items , total ] = await Promise . all ( [
78+ prisma . bodhakatha . findMany ( {
79+ skip,
80+ take : pageSize ,
81+ orderBy : { orderId : 'asc' }
82+ } ) ,
83+ prisma . bodhakatha . count ( )
84+ ] ) ;
85+ return { items, total, hasMore : total > skip + items . length } ;
86+ }
87+
6088// Glossary Actions
6189export async function saveGlossary ( data : any ) {
6290 if ( ! await isAdmin ( ) ) throw new Error ( 'Unauthorized' ) ;
@@ -82,3 +110,59 @@ export async function deleteGlossary(id: string) {
82110 revalidatePath ( '/admin/glossary' ) ;
83111 revalidatePath ( '/admin/glossary' , 'layout' ) ;
84112}
113+
114+ export async function getGlossaryPaged ( page : number = 1 , pageSize : number = 20 ) {
115+ if ( ! await isAdmin ( ) ) throw new Error ( 'Unauthorized' ) ;
116+ const skip = ( page - 1 ) * pageSize ;
117+ const [ items , total ] = await Promise . all ( [
118+ prisma . glossary . findMany ( {
119+ skip,
120+ take : pageSize ,
121+ orderBy : { term : 'asc' }
122+ } ) ,
123+ prisma . glossary . count ( )
124+ ] ) ;
125+ return { items, total, hasMore : total > skip + items . length } ;
126+ }
127+ // Public Fetchers (No Auth Required)
128+ export async function getPublicLeelas ( page : number = 1 , pageSize : number = 10 ) {
129+ const skip = ( page - 1 ) * pageSize ;
130+ const [ items , total ] = await Promise . all ( [
131+ prisma . leela . findMany ( {
132+ skip,
133+ take : pageSize ,
134+ orderBy : { orderId : 'asc' }
135+ } ) ,
136+ prisma . leela . count ( )
137+ ] ) ;
138+ return {
139+ items : items . map ( ( item : any ) => ( {
140+ ...item ,
141+ createdAt : item . createdAt ?. toISOString ( ) ,
142+ updatedAt : item . updatedAt ?. toISOString ( )
143+ } ) ) ,
144+ total,
145+ hasMore : total > skip + items . length
146+ } ;
147+ }
148+
149+ export async function getPublicBodhakathas ( page : number = 1 , pageSize : number = 10 ) {
150+ const skip = ( page - 1 ) * pageSize ;
151+ const [ items , total ] = await Promise . all ( [
152+ prisma . bodhakatha . findMany ( {
153+ skip,
154+ take : pageSize ,
155+ orderBy : { orderId : 'asc' }
156+ } ) ,
157+ prisma . bodhakatha . count ( )
158+ ] ) ;
159+ return {
160+ items : items . map ( ( item : any ) => ( {
161+ ...item ,
162+ createdAt : item . createdAt ?. toISOString ( ) ,
163+ updatedAt : item . updatedAt ?. toISOString ( )
164+ } ) ) ,
165+ total,
166+ hasMore : total > skip + items . length
167+ } ;
168+ }
0 commit comments