@@ -21,44 +21,66 @@ export const actions = {
2121
2222 'add-block' : async ( { request, params } ) => {
2323 const form = await request . formData ( ) ;
24+ const type = form . get ( 'type' ) ?. toString ( ) ;
25+ const content = form . get ( 'content' ) ?. toString ( ) ;
26+ const displayOrder = form . get ( 'displayOrder' ) ?. toString ( ) ;
27+
28+ if ( ! type || ! content || ! displayOrder ) {
29+ return { success : false , error : 'Missing required fields' } ;
30+ }
31+
2432 await prisma . blogContentBlock . create ( {
2533 data : {
2634 blogId : params . id ,
27- type : form . get ( 'type' ) ,
28- content : form . get ( ' content' ) ,
29- displayOrder : Number ( form . get ( ' displayOrder' ) ) ,
35+ type : /** @type { import('@prisma/client').ContentBlockType } */ ( type ) ,
36+ content : content ,
37+ displayOrder : Number ( displayOrder ) ,
3038 draft : form . get ( 'draft' ) === 'on'
3139 }
3240 } ) ;
3341 return { success : true } ;
3442 } ,
3543 'edit-block' : async ( { request } ) => {
3644 const form = await request . formData ( ) ;
45+ const id = form . get ( 'id' ) ?. toString ( ) ;
46+ const type = form . get ( 'type' ) ?. toString ( ) ;
47+ const content = form . get ( 'content' ) ?. toString ( ) ;
48+
49+ if ( ! id || ! type || ! content ) {
50+ return { success : false , error : 'Missing required fields' } ;
51+ }
52+
3753 await prisma . blogContentBlock . update ( {
38- where : { id : form . get ( 'id' ) } ,
54+ where : { id : id } ,
3955 data : {
40- type : form . get ( 'type' ) ,
41- content : form . get ( ' content' ) ,
56+ type : /** @type { import('@prisma/client').ContentBlockType } */ ( type ) ,
57+ content : content ,
4258 draft : form . get ( 'draft' ) === 'on'
4359 }
4460 } ) ;
4561 return { success : true } ;
4662 } ,
4763 'delete-block' : async ( { request } ) => {
4864 const form = await request . formData ( ) ;
65+ const id = form . get ( 'id' ) ?. toString ( ) ;
66+
67+ if ( ! id ) {
68+ return { success : false , error : 'Missing block ID' } ;
69+ }
70+
4971 await prisma . blogContentBlock . delete ( {
50- where : { id : form . get ( 'id' ) }
72+ where : { id : id }
5173 } ) ;
5274 return { success : true } ;
5375 } ,
5476 'update-blog' : async ( { request, params } ) => {
5577 const form = await request . formData ( ) ;
5678 const data = {
57- title : form . get ( 'title' ) ,
58- seoTitle : form . get ( 'seoTitle' ) ,
59- seoDescription : form . get ( 'seoDescription' ) ,
60- excerpt : form . get ( 'excerpt' ) ,
61- slug : form . get ( 'slug' ) ,
79+ title : form . get ( 'title' ) ?. toString ( ) || '' ,
80+ seoTitle : form . get ( 'seoTitle' ) ?. toString ( ) || '' ,
81+ seoDescription : form . get ( 'seoDescription' ) ?. toString ( ) || '' ,
82+ excerpt : form . get ( 'excerpt' ) ?. toString ( ) || '' ,
83+ slug : form . get ( 'slug' ) ?. toString ( ) || '' ,
6284 draft : form . get ( 'draft' ) === 'on'
6385 } ;
6486 await prisma . blogPost . update ( {
@@ -70,7 +92,13 @@ export const actions = {
7092 ,
7193 'reorder-blocks' : async ( { request, params } ) => {
7294 const form = await request . formData ( ) ;
73- const order = JSON . parse ( form . get ( 'order' ) ) ;
95+ const orderStr = form . get ( 'order' ) ?. toString ( ) ;
96+
97+ if ( ! orderStr ) {
98+ return { success : false , error : 'Missing order data' } ;
99+ }
100+
101+ const order = JSON . parse ( orderStr ) ;
74102 for ( const { id, displayOrder } of order ) {
75103 await prisma . blogContentBlock . update ( {
76104 where : { id } ,
0 commit comments