@@ -256,40 +256,36 @@ export const createDocument = async (
256256 collectionId : string ,
257257 data : object
258258) => {
259- return graphql
260- . mutation ( {
261- query : `mutation CreateDocument ($databaseId: String!, $collectionId: String!, $documentId: String!, $data: Json!) {
259+ const response = await graphql . mutation ( {
260+ query : `mutation CreateDocument ($databaseId: String!, $collectionId: String!, $documentId: String!, $data: Json!) {
262261 databasesCreateDocument(databaseId: $databaseId, collectionId: $collectionId, documentId: $documentId, data: $data) { _id data }
263262 }` ,
264- variables : {
265- databaseId,
266- collectionId,
267- documentId : ID . unique ( ) ,
268- data,
269- } ,
270- } )
271- . then ( function ( response : any ) {
272- console . log ( response ) ;
273-
274- if ( "errors" in response ) {
275- alert ( "Failed to create document!" ) ;
276- return ;
277- }
278-
279- return response as {
280- data : { databasesCreateDocument : { _id : string ; data : string } } ;
281- } ;
282- } ) ;
263+ variables : {
264+ databaseId,
265+ collectionId,
266+ documentId : ID . unique ( ) ,
267+ data,
268+ } ,
269+ } ) ;
270+ console . log ( response ) ;
271+
272+ if ( "errors" in response ) {
273+ alert ( "Failed to create document!" ) ;
274+ return ;
275+ }
276+
277+ return response as {
278+ data : { databasesCreateDocument : { _id : string ; data : string } } ;
279+ } ;
283280} ;
284281
285282export const getDocument = async (
286283 databaseId : string ,
287284 collectionId : string ,
288285 documentId : string
289286) => {
290- graphql
291- . query ( {
292- query : `query GetDocument ($databaseId: String!, $collectionId: String!, $documentId: String!) {
287+ const response = await graphql . query ( {
288+ query : `query GetDocument ($databaseId: String!, $collectionId: String!, $documentId: String!) {
293289 databasesGetDocument(databaseId: $databaseId, collectionId: $collectionId, documentId: $documentId) {
294290 _id
295291 _createdAt
@@ -299,56 +295,51 @@ export const getDocument = async (
299295 size
300296 }
301297 }` ,
302- variables : {
303- databaseId,
304- collectionId,
305- documentId,
306- } ,
307- } )
308- . then ( function ( response ) {
309- console . log ( response ) ;
310-
311- if ( "errors" in response ) {
312- alert ( "Failed to get document!" ) ;
313- return ;
314- }
315-
316- return response ;
317- } ) ;
298+ variables : {
299+ databaseId,
300+ collectionId,
301+ documentId,
302+ } ,
303+ } ) ;
304+ console . log ( response ) ;
305+
306+ if ( "errors" in response ) {
307+ alert ( "Failed to get document!" ) ;
308+ return ;
309+ }
310+
311+ return response ;
318312} ;
319313
320314export const listDocuments = async (
321315 databaseId : string ,
322316 collectionId : string ,
323317 fields ?: string
324318) => {
325- return graphql
326- . query ( {
327- query : `query ListDocuments ($databaseId: String!, $collectionId: String!) {
328- databasesListDocuments(databaseId: $databaseId, collectionId: $collectionId) { total documents { data } }
319+ const response = await graphql . query ( {
320+ query : `query ListDocuments ($databaseId: String!, $collectionId: String!) {
321+ databasesListDocuments(databaseId: $databaseId, collectionId: $collectionId) { total documents { _id data } }
329322 }` ,
330- variables : {
331- databaseId,
332- collectionId,
333- } ,
334- } )
335- . then ( function ( response ) {
336- console . log ( response ) ;
337-
338- if ( "errors" in response ) {
339- alert ( "Failed to list documents!" ) ;
340- return ;
341- }
342-
343- return response as {
344- data : {
345- databasesListDocuments : {
346- total : number ;
347- documents : [ { data : string } ] ;
348- } ;
349- } ;
323+ variables : {
324+ databaseId,
325+ collectionId,
326+ } ,
327+ } ) ;
328+ console . log ( response ) ;
329+
330+ if ( "errors" in response ) {
331+ alert ( "Failed to list documents!" ) ;
332+ return ;
333+ }
334+
335+ return response as {
336+ data : {
337+ databasesListDocuments : {
338+ total : number ;
339+ documents : [ { _id : string ; data : string } ] ;
350340 } ;
351- } ) ;
341+ } ;
342+ } ;
352343} ;
353344
354345export const updateDocument = async (
@@ -357,54 +348,48 @@ export const updateDocument = async (
357348 documentId : string ,
358349 data : object
359350) => {
360- return graphql
361- . query ( {
362- query : `mutation UpdateDocument ($databaseId: String!, $collectionId: String!, $documentId: String!, $data: JSON) {
351+ const response = await graphql . query ( {
352+ query : `mutation UpdateDocument ($databaseId: String!, $collectionId: String!, $documentId: String!, $data: JSON) {
363353 databasesUpdateDocument(databaseId: $databaseId, collectionId: $collectionId, documentId: $documentId, data: $data) { _id }
364354 }` ,
365- variables : {
366- databaseId,
367- collectionId,
368- documentId,
369- data,
370- } ,
371- } )
372- . then ( function ( response ) {
373- console . log ( response ) ;
374-
375- if ( "errors" in response ) {
376- alert ( "Failed to update document!" ) ;
377- return ;
378- }
379-
380- return response ;
381- } ) ;
355+ variables : {
356+ databaseId,
357+ collectionId,
358+ documentId,
359+ data,
360+ } ,
361+ } ) ;
362+ console . log ( response ) ;
363+
364+ if ( "errors" in response ) {
365+ alert ( "Failed to update document!" ) ;
366+ return ;
367+ }
368+
369+ return response ;
382370} ;
383371
384372export const deleteDocument = async (
385373 databaseId : string ,
386374 collectionId : string ,
387375 documentId : string
388376) => {
389- return graphql
390- . mutation ( {
391- query : `mutation DeleteDocument ($databaseId: String!, $collectionId: String!, $documentId: String!) {
377+ const response = await graphql . mutation ( {
378+ query : `mutation DeleteDocument ($databaseId: String!, $collectionId: String!, $documentId: String!) {
392379 databasesDeleteDocument(databaseId: $databaseId, collectionId: $collectionId, documentId: $documentId) { status }
393380 }` ,
394- variables : {
395- databaseId,
396- collectionId,
397- documentId,
398- } ,
399- } )
400- . then ( function ( response ) {
401- console . log ( response ) ;
402-
403- if ( "errors" in response ) {
404- alert ( "Failed to delete document!" ) ;
405- return ;
406- }
407-
408- return response ;
409- } ) ;
381+ variables : {
382+ databaseId,
383+ collectionId,
384+ documentId,
385+ } ,
386+ } ) ;
387+ console . log ( response ) ;
388+
389+ if ( "errors" in response ) {
390+ alert ( "Failed to delete document!" ) ;
391+ return ;
392+ }
393+
394+ return response ;
410395} ;
0 commit comments