@@ -22,7 +22,11 @@ import {
2222import { client } from 'app/graphql/client' ;
2323import { LIST_TEMPLATES } from 'app/pages/Dashboard/queries' ;
2424
25- import { transformSandbox } from '../utils/sandbox' ;
25+ import {
26+ transformSandbox ,
27+ transformDirectory ,
28+ transformModule ,
29+ } from '../utils/sandbox' ;
2630import apiFactory , { Api , ApiConfig } from './apiFactory' ;
2731
2832let api : Api ;
@@ -78,22 +82,26 @@ export default {
7882 return transformSandbox ( sandbox ) ;
7983 } ,
8084 createModule ( sandboxId : string , module : Module ) : Promise < Module > {
81- return api . post ( `/sandboxes/${ sandboxId } /modules` , {
82- module : {
83- title : module . title ,
84- directoryShortid : module . directoryShortid ,
85- code : module . code ,
86- isBinary : module . isBinary === undefined ? false : module . isBinary ,
87- } ,
88- } ) ;
85+ return api
86+ . post ( `/sandboxes/${ sandboxId } /modules` , {
87+ module : {
88+ title : module . title ,
89+ directoryShortid : module . directoryShortid ,
90+ code : module . code ,
91+ isBinary : module . isBinary === undefined ? false : module . isBinary ,
92+ } ,
93+ } )
94+ . then ( transformModule ) ;
8995 } ,
9096 deleteModule ( sandboxId : string , moduleShortid : string ) : Promise < void > {
9197 return api . delete ( `/sandboxes/${ sandboxId } /modules/${ moduleShortid } ` ) ;
9298 } ,
9399 saveModuleCode ( sandboxId : string , module : Module ) : Promise < Module > {
94- return api . put ( `/sandboxes/${ sandboxId } /modules/${ module . shortid } ` , {
95- module : { code : module . code } ,
96- } ) ;
100+ return api
101+ . put ( `/sandboxes/${ sandboxId } /modules/${ module . shortid } ` , {
102+ module : { code : module . code } ,
103+ } )
104+ . then ( transformModule ) ;
97105 } ,
98106 saveModules ( sandboxId : string , modules : Module [ ] ) {
99107 return api . put ( `/sandboxes/${ sandboxId } /modules/mupdate` , {
@@ -193,12 +201,14 @@ export default {
193201 directoryShortid : string ,
194202 title : string
195203 ) : Promise < Directory > {
196- return api . post ( `/sandboxes/${ sandboxId } /directories` , {
197- directory : {
198- title,
199- directoryShortid,
200- } ,
201- } ) ;
204+ return api
205+ . post ( `/sandboxes/${ sandboxId } /directories` , {
206+ directory : {
207+ title,
208+ directoryShortid,
209+ } ,
210+ } )
211+ . then ( transformDirectory ) ;
202212 } ,
203213 saveModuleDirectory (
204214 sandboxId : string ,
@@ -247,7 +257,7 @@ export default {
247257 name,
248258 } ) ;
249259 } ,
250- massCreateModules (
260+ async massCreateModules (
251261 sandboxId : string ,
252262 directoryShortid : string | null ,
253263 modules : Module [ ] ,
@@ -256,11 +266,18 @@ export default {
256266 modules : Module [ ] ;
257267 directories : Directory [ ] ;
258268 } > {
259- return api . post ( `/sandboxes/${ sandboxId } /modules/mcreate` , {
269+ const data = ( await api . post ( `/sandboxes/${ sandboxId } /modules/mcreate` , {
260270 directoryShortid,
261271 modules,
262272 directories,
263- } ) ;
273+ } ) ) as {
274+ modules : Module [ ] ;
275+ directories : Directory [ ] ;
276+ } ;
277+
278+ data . modules = data . modules . map ( transformModule ) ;
279+ data . directories = data . directories . map ( transformDirectory ) ;
280+ return data ;
264281 } ,
265282 createGit (
266283 sandboxId : string ,
0 commit comments