@nextlyhq/plugin-form-builder 0.0.2-alpha.64 → 0.0.2-alpha.65
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +32 -25
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
package/dist/index.js
CHANGED
|
@@ -1541,30 +1541,11 @@ function formBuilder(options = {}) {
|
|
|
1541
1541
|
}
|
|
1542
1542
|
return ctx.data;
|
|
1543
1543
|
});
|
|
1544
|
-
nextly.hooks.on(
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
const form = record;
|
|
1550
|
-
if (typeof form.id !== "string") return;
|
|
1551
|
-
try {
|
|
1552
|
-
form.submissionCount = await nextly.services.collections.count(
|
|
1553
|
-
submissionSlug,
|
|
1554
|
-
{
|
|
1555
|
-
where: {
|
|
1556
|
-
form: { equals: form.id },
|
|
1557
|
-
status: { not_equals: "spam" }
|
|
1558
|
-
}
|
|
1559
|
-
},
|
|
1560
|
-
{ as: "system" }
|
|
1561
|
-
);
|
|
1562
|
-
} catch {
|
|
1563
|
-
form.submissionCount = 0;
|
|
1564
|
-
}
|
|
1565
|
-
})
|
|
1566
|
-
);
|
|
1567
|
-
});
|
|
1544
|
+
nextly.hooks.on(
|
|
1545
|
+
"afterRead",
|
|
1546
|
+
formsSlug,
|
|
1547
|
+
(context) => injectSubmissionCount(context, submissionSlug, nextly)
|
|
1548
|
+
);
|
|
1568
1549
|
}
|
|
1569
1550
|
});
|
|
1570
1551
|
return {
|
|
@@ -1836,12 +1817,38 @@ async function handleSubmissionCreated(context, config, nextly) {
|
|
|
1836
1817
|
}
|
|
1837
1818
|
}
|
|
1838
1819
|
}
|
|
1820
|
+
async function injectSubmissionCount(context, submissionSlug, nextly) {
|
|
1821
|
+
const hook = context;
|
|
1822
|
+
if (hook.context?.[SCHEMA_ONLY_READ] === true) return;
|
|
1823
|
+
const records = Array.isArray(hook.data) ? hook.data : hook.data ? [hook.data] : [];
|
|
1824
|
+
await Promise.all(
|
|
1825
|
+
records.map(async (record) => {
|
|
1826
|
+
const form = record;
|
|
1827
|
+
if (typeof form.id !== "string") return;
|
|
1828
|
+
try {
|
|
1829
|
+
form.submissionCount = await nextly.services.collections.count(
|
|
1830
|
+
submissionSlug,
|
|
1831
|
+
{
|
|
1832
|
+
where: {
|
|
1833
|
+
form: { equals: form.id },
|
|
1834
|
+
status: { not_equals: "spam" }
|
|
1835
|
+
}
|
|
1836
|
+
},
|
|
1837
|
+
{ as: "system" }
|
|
1838
|
+
);
|
|
1839
|
+
} catch {
|
|
1840
|
+
form.submissionCount = 0;
|
|
1841
|
+
}
|
|
1842
|
+
})
|
|
1843
|
+
);
|
|
1844
|
+
}
|
|
1845
|
+
var SCHEMA_ONLY_READ = "formBuilder.schemaOnlyRead";
|
|
1839
1846
|
async function fetchParentForm(formsSlug, formId, nextly) {
|
|
1840
1847
|
try {
|
|
1841
1848
|
const form = await nextly.services.collections.findEntryById(
|
|
1842
1849
|
formsSlug,
|
|
1843
1850
|
formId,
|
|
1844
|
-
{ as: "system" }
|
|
1851
|
+
{ as: "system", context: { [SCHEMA_ONLY_READ]: true } }
|
|
1845
1852
|
);
|
|
1846
1853
|
return form;
|
|
1847
1854
|
} catch (err) {
|