Page MenuHomeSealhub

aggregate.ts
No OneTemporary

aggregate.ts

import {
CalculatedField,
Context,
App,
Queries,
Collection,
CollectionItem,
} from "../../../main";
type StagesGetter = (
context: Context,
item: CollectionItem,
db_document: any
) => Queries.QueryStage[];
export default class Aggregate extends CalculatedField<any> {
name = "aggregate";
stages_getter: StagesGetter;
constructor(app: App, collection: Collection, stages_getter: StagesGetter) {
super(app, collection);
this.stages_getter = stages_getter;
}
async calculate(context: Context, item: CollectionItem, db_document: any) {
const stages = this.stages_getter(context, item, db_document);
const documents = await this.app.Datastore.aggregate(
this.collection.name,
stages
);
if (documents.length) {
return documents[0].result;
} else {
return null;
}
}
}

File Metadata

Mime Type
text/plain
Expires
Wed, Aug 13, 17:13 (1 d, 8 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
870066
Default Alt Text
aggregate.ts (808 B)

Event Timeline