66 CreateRecordsCommand ,
77 DeleteRecordCommand ,
88 DuplicateRecordCommand ,
9+ SubmitFormCommand ,
910 TriggerRecordButtonCommand ,
1011 UpdateRecordCommand ,
1112} from "@undb/commands"
@@ -36,7 +37,8 @@ export class RecordOpenApi {
3637 . get (
3738 "/records" ,
3839 async ( ctx ) => {
39- const { baseName, tableName } = ctx . params
40+ const baseName = decodeURIComponent ( ctx . params . baseName )
41+ const tableName = decodeURIComponent ( ctx . params . tableName )
4042 const result = ( await this . queryBus . execute (
4143 new GetReadableRecordsQuery ( { baseName, tableName, ignoreView : true } ) ,
4244 ) ) as PaginatedDTO < IRecordReadableValueDTO >
@@ -57,7 +59,9 @@ export class RecordOpenApi {
5759 . get (
5860 "/views/:viewName/records" ,
5961 async ( ctx ) => {
60- const { baseName, tableName, viewName } = ctx . params
62+ const baseName = decodeURIComponent ( ctx . params . baseName )
63+ const tableName = decodeURIComponent ( ctx . params . tableName )
64+ const viewName = decodeURIComponent ( ctx . params . viewName )
6165 const result = ( await this . queryBus . execute (
6266 new GetReadableRecordsQuery ( { baseName, tableName, viewName } ) ,
6367 ) ) as PaginatedDTO < IRecordReadableValueDTO >
@@ -78,7 +82,10 @@ export class RecordOpenApi {
7882 . get (
7983 "/views/:viewName/records/:recordId" ,
8084 async ( ctx ) => {
81- const { baseName, tableName, viewName, recordId } = ctx . params
85+ const baseName = decodeURIComponent ( ctx . params . baseName )
86+ const tableName = decodeURIComponent ( ctx . params . tableName )
87+ const viewName = decodeURIComponent ( ctx . params . viewName )
88+ const recordId = ctx . params . recordId
8289 const result = await this . queryBus . execute (
8390 new GetReadableRecordByIdQuery ( { baseName, tableName, viewName, id : recordId } ) ,
8491 )
@@ -103,9 +110,11 @@ export class RecordOpenApi {
103110 . get (
104111 "/records/:recordId" ,
105112 async ( ctx ) => {
106- const { baseName, tableName } = ctx . params
113+ const baseName = decodeURIComponent ( ctx . params . baseName )
114+ const tableName = decodeURIComponent ( ctx . params . tableName )
115+ const recordId = ctx . params . recordId
107116 const result = await this . queryBus . execute (
108- new GetReadableRecordByIdQuery ( { baseName, tableName, id : ctx . params . recordId , ignoreView : true } ) ,
117+ new GetReadableRecordByIdQuery ( { baseName, tableName, id : recordId , ignoreView : true } ) ,
109118 )
110119 return {
111120 data : result ,
@@ -123,7 +132,8 @@ export class RecordOpenApi {
123132 . post (
124133 "/records" ,
125134 async ( ctx ) => {
126- const { baseName, tableName } = ctx . params
135+ const baseName = decodeURIComponent ( ctx . params . baseName )
136+ const tableName = decodeURIComponent ( ctx . params . tableName )
127137 return withTransaction ( this . qb ) ( ( ) =>
128138 this . commandBus . execute ( new CreateRecordCommand ( { baseName, tableName, values : ctx . body . values } ) ) ,
129139 )
@@ -141,7 +151,8 @@ export class RecordOpenApi {
141151 . post (
142152 "/records/bulk" ,
143153 async ( ctx ) => {
144- const { baseName, tableName } = ctx . params
154+ const baseName = decodeURIComponent ( ctx . params . baseName )
155+ const tableName = decodeURIComponent ( ctx . params . tableName )
145156 return withTransaction ( this . qb ) ( ( ) =>
146157 this . commandBus . execute ( new CreateRecordsCommand ( { baseName, tableName, records : ctx . body . records } ) ) ,
147158 )
@@ -159,7 +170,8 @@ export class RecordOpenApi {
159170 . patch (
160171 "/records/:recordId" ,
161172 async ( ctx ) => {
162- const { baseName, tableName } = ctx . params
173+ const baseName = decodeURIComponent ( ctx . params . baseName )
174+ const tableName = decodeURIComponent ( ctx . params . tableName )
163175 return withTransaction ( this . qb ) ( ( ) =>
164176 this . commandBus . execute (
165177 new UpdateRecordCommand ( {
@@ -184,7 +196,8 @@ export class RecordOpenApi {
184196 . patch (
185197 "/records" ,
186198 async ( ctx ) => {
187- const { tableName, baseName } = ctx . params
199+ const baseName = decodeURIComponent ( ctx . params . baseName )
200+ const tableName = decodeURIComponent ( ctx . params . tableName )
188201 return withTransaction ( this . qb ) ( ( ) =>
189202 this . commandBus . execute (
190203 new BulkUpdateRecordsCommand ( {
@@ -213,7 +226,8 @@ export class RecordOpenApi {
213226 . post (
214227 "/records/:recordId/duplicate" ,
215228 async ( ctx ) => {
216- const { baseName, tableName } = ctx . params
229+ const baseName = decodeURIComponent ( ctx . params . baseName )
230+ const tableName = decodeURIComponent ( ctx . params . tableName )
217231 return withTransaction ( this . qb ) ( ( ) =>
218232 this . commandBus . execute ( new DuplicateRecordCommand ( { baseName, tableName, id : ctx . params . recordId } ) ) ,
219233 )
@@ -230,7 +244,10 @@ export class RecordOpenApi {
230244 . post (
231245 "/records/:recordId/trigger/:field" ,
232246 async ( ctx ) => {
233- const { baseName, tableName, recordId, field } = ctx . params
247+ const baseName = decodeURIComponent ( ctx . params . baseName )
248+ const tableName = decodeURIComponent ( ctx . params . tableName )
249+ const recordId = ctx . params . recordId
250+ const field = ctx . params . field
234251 return withTransaction ( this . qb ) ( async ( ) => {
235252 const result = ( await this . commandBus . execute (
236253 new TriggerRecordButtonCommand ( { baseName, tableName, recordId, field } ) ,
@@ -241,7 +258,12 @@ export class RecordOpenApi {
241258 } )
242259 } ,
243260 {
244- params : t . Object ( { baseName : t . String ( ) , tableName : t . String ( ) , recordId : t . String ( ) , field : t . String ( ) } ) ,
261+ params : t . Object ( {
262+ baseName : t . String ( ) ,
263+ tableName : t . String ( ) ,
264+ recordId : t . String ( ) ,
265+ field : t . String ( ) ,
266+ } ) ,
245267 detail : {
246268 tags : [ "Record" , "Button" ] ,
247269 summary : "Trigger record button" ,
@@ -252,7 +274,8 @@ export class RecordOpenApi {
252274 . post (
253275 "/records/duplicate" ,
254276 async ( ctx ) => {
255- const { baseName, tableName } = ctx . params
277+ const baseName = decodeURIComponent ( ctx . params . baseName )
278+ const tableName = decodeURIComponent ( ctx . params . tableName )
256279 return withTransaction ( this . qb ) ( ( ) =>
257280 this . commandBus . execute (
258281 new BulkDuplicateRecordsCommand ( {
@@ -277,7 +300,8 @@ export class RecordOpenApi {
277300 . delete (
278301 "/records/:recordId" ,
279302 async ( ctx ) => {
280- const { baseName, tableName } = ctx . params
303+ const baseName = decodeURIComponent ( ctx . params . baseName )
304+ const tableName = decodeURIComponent ( ctx . params . tableName )
281305 return withTransaction ( this . qb ) ( ( ) =>
282306 this . commandBus . execute ( new DeleteRecordCommand ( { baseName, tableName, id : ctx . params . recordId } ) ) ,
283307 )
@@ -294,7 +318,8 @@ export class RecordOpenApi {
294318 . delete (
295319 "/records" ,
296320 async ( ctx ) => {
297- const { baseName, tableName } = ctx . params
321+ const baseName = decodeURIComponent ( ctx . params . baseName )
322+ const tableName = decodeURIComponent ( ctx . params . tableName )
298323 return withTransaction ( this . qb ) ( ( ) =>
299324 this . commandBus . execute (
300325 new BulkDeleteRecordsCommand ( {
@@ -316,6 +341,28 @@ export class RecordOpenApi {
316341 } ,
317342 } ,
318343 )
344+ . post (
345+ "/forms/:formName/submit" ,
346+ async ( ctx ) => {
347+ const baseName = decodeURIComponent ( ctx . params . baseName )
348+ const tableName = decodeURIComponent ( ctx . params . tableName )
349+ const formName = decodeURIComponent ( ctx . params . formName )
350+ return withTransaction ( this . qb ) ( ( ) =>
351+ this . commandBus . execute (
352+ new SubmitFormCommand ( { baseName, tableName, form : formName , values : ctx . body . values } ) ,
353+ ) ,
354+ )
355+ } ,
356+ {
357+ params : t . Object ( { baseName : t . String ( ) , tableName : t . String ( ) , formName : t . String ( ) } ) ,
358+ body : t . Object ( { values : t . Record ( t . String ( ) , t . Any ( ) ) } ) ,
359+ detail : {
360+ tags : [ "Record" , "Form" ] ,
361+ summary : "Submit form" ,
362+ description : "Submit form" ,
363+ } ,
364+ } ,
365+ )
319366 } )
320367 }
321368}
0 commit comments