@@ -16,9 +16,6 @@ import { ShapeForm, ShapePreview } from "..";
1616// Toast
1717import toast from "react-hot-toast" ;
1818
19- // harperDb fetch call
20- import { harperFetch } from "../../utils/HarperFetch" ;
21-
2219const CreateShape = ( props ) => {
2320
2421 // Store the default state as a variable so resetting form is easier
@@ -337,30 +334,43 @@ const CreateShape = (props) => {
337334 } else {
338335
339336 // Create the shape in the DB
340- const insertShape = await harperFetch ( {
341- operation : "sql" ,
342- sql : `INSERT into tryshape.shapes(backgroundColor, createdAt, createdBy, edges, email, formula, likes, name, notes, private, type, vertices)
343- values('${ shapeInformation . backgroundColor } ', null, '${ props . user . email } ', ${ shapeInformation . edges } , null, '${ shapeInformation . formula } ', 0, '${ shapeInformation . name } ', '${ shapeInformation . notes } ', ${ shapeInformation . private } , '${ shapeInformation . clipPathType } ', ${ shapeInformation . vertices } )` ,
337+ const insertShapeResponse = await axios . post ( '/api/POST/shape' , {
338+ name : shapeInformation . name ,
339+ formula : shapeInformation . formula ,
340+ vertices : shapeInformation . vertices ,
341+ visibility : shapeInformation . private ,
342+ edges : shapeInformation . edges ,
343+ notes : shapeInformation . notes ,
344+ type : shapeInformation . clipPathType ,
345+ backgroundColor : shapeInformation . backgroundColor ,
346+ createdBy : props . user . email ,
347+ likes : 0
344348 } ) ;
349+ const insertShape = insertShapeResponse . data
345350
346- console . log ( insertShape ) ;
351+ console . log ( { insertShape} ) ;
347352
348353 // Create the user in the db
349- if ( insertShape [ 'inserted_hashes' ] . length > 0 ) {
354+ if ( insertShape . data [ 'inserted_hashes' ] . length > 0 ) {
350355 // First check if the user exist
351- const result = await harperFetch ( {
352- operation : "sql" ,
353- sql : `SELECT count(*) from tryshape.users WHERE email='${ props . user . email } '` ,
354- } ) ;
355- const count = ( result [ 0 ] [ 'COUNT(*)' ] ) ;
356+ const userResponse = await axios . get ( "/api/GET/user" , {
357+ params : {
358+ email : props . user . email
359+ }
360+ } ) ;
361+ const result = userResponse . data ;
362+ const count = result . length ;
356363 console . log ( { count} ) ;
364+
357365 // If doesn't exist, create in db
358366 if ( count === 0 ) {
359- const insertUser = await harperFetch ( {
360- operation : "sql" ,
361- sql : `INSERT into tryshape.users( email, name, photoURL)
362- values(' ${ props . user . email } ', ' ${ props . user . displayName } ', ' ${ props . user . photoURL } ')` ,
367+ const insertUserResponse = await axios . post ( '/api/POST/user' , {
368+ displayName : props . user . displayName ,
369+ email : props . user . email ,
370+ photoURL : props . user . photoURL
363371 } ) ;
372+ const insertUser = insertUserResponse . data ;
373+ console . log ( { insertUser} ) ;
364374 } else {
365375 console . log ( `The user ${ props . user . email } present in DB` ) ;
366376 }
@@ -375,7 +385,7 @@ const CreateShape = (props) => {
375385 ...props . shapeAction ,
376386 "action" : "add" ,
377387 "payload" : {
378- "shape_id" : insertShape [ 'inserted_hashes' ]
388+ "shape_id" : insertShape . data [ 'inserted_hashes' ]
379389 }
380390 } ) ;
381391
0 commit comments