@odla-ai/crm 0.9.0 → 0.9.1
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.cjs +28 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +28 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -803,10 +803,14 @@ function resultAsWritten(result) {
|
|
|
803
803
|
|
|
804
804
|
// src/deps.ts
|
|
805
805
|
function readingAsWritten(db) {
|
|
806
|
+
const batch = db.aggregateBatch;
|
|
806
807
|
return {
|
|
807
808
|
query: async (query) => resultAsWritten(await db.query(query)),
|
|
808
809
|
transact: (ops, opts) => db.transact(ops, opts),
|
|
809
|
-
aggregate: (ns, spec, queryOpts) => db.aggregate(ns, spec, queryOpts)
|
|
810
|
+
aggregate: (ns, spec, queryOpts) => db.aggregate(ns, spec, queryOpts),
|
|
811
|
+
...batch ? {
|
|
812
|
+
aggregateBatch: (requests) => batch.call(db, requests)
|
|
813
|
+
} : {}
|
|
810
814
|
};
|
|
811
815
|
}
|
|
812
816
|
function resolveDeps(deps) {
|
|
@@ -1867,13 +1871,29 @@ async function typeSummary(deps, type) {
|
|
|
1867
1871
|
where: { and: [{ type }, { archived: false }, ...extra] }
|
|
1868
1872
|
});
|
|
1869
1873
|
const stageIds = (def.pipeline?.stages ?? []).map((s) => s.id);
|
|
1870
|
-
const
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1874
|
+
const requests = [
|
|
1875
|
+
{ ns: CRM_NS.record, aggregate: { count: true }, opts: live([]) },
|
|
1876
|
+
{
|
|
1877
|
+
ns: CRM_NS.activity,
|
|
1878
|
+
aggregate: { count: true },
|
|
1879
|
+
opts: {
|
|
1880
|
+
where: {
|
|
1881
|
+
and: [{ kind: "task" }, { status: { $in: ["open", "waiting"] } }]
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
},
|
|
1885
|
+
...stageIds.map((stage) => ({
|
|
1886
|
+
ns: CRM_NS.record,
|
|
1887
|
+
aggregate: { count: true },
|
|
1888
|
+
opts: live([{ stage }])
|
|
1889
|
+
}))
|
|
1890
|
+
];
|
|
1891
|
+
const batch = db.aggregateBatch;
|
|
1892
|
+
const [total, openTasks, ...stageCounts] = batch ? await batch(requests) : await Promise.all(
|
|
1893
|
+
requests.map(
|
|
1894
|
+
(request) => db.aggregate(request.ns, request.aggregate, request.opts)
|
|
1895
|
+
)
|
|
1896
|
+
);
|
|
1877
1897
|
const stages = {};
|
|
1878
1898
|
stageIds.forEach((stage, i) => {
|
|
1879
1899
|
stages[stage] = stageCounts[i]?.count ?? 0;
|