Skip to content

Commit 1cd7205

Browse files
committed
feat: $crud operator handles an array of objects
1 parent f8c6644 commit 1cd7205

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/server.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,25 @@ class CoCreateLazyLoader {
337337
} else if (operator.startsWith('$rawBody')) {
338338
return getValueFromObject(data, operator.substring(1))
339339
} else if (operator.startsWith('$crud')) {
340-
context = await this.processOperators(data, event, context);
341-
result = await this.crud.send(context)
342-
if (operator.startsWith('$crud.'))
343-
result = getValueFromObject(operator, operator.substring(6))
344-
return await this.processOperators(data, event, result);
340+
let results = context
341+
let isObject = false
342+
if (!Array.isArray(results)) {
343+
isObject = true
344+
results = [results]
345+
}
346+
347+
for (let i = 0; i < results.length; i++) {
348+
results[i] = await this.processOperators(data, event, results[i]);
349+
results[i] = await this.crud.send(results[i])
350+
if (operator.startsWith('$crud.'))
351+
results[i] = getValueFromObject(operator, operator.substring(6))
352+
results[i] = await this.processOperators(data, event, results[i])
353+
}
354+
355+
if (isObject)
356+
results = results[0]
357+
358+
return results;
345359
} else if (operator.startsWith('$socket')) {
346360
context = await this.processOperators(data, event, context);
347361
result = await this.socket.send(context)

0 commit comments

Comments
 (0)