Skip to content

Commit

Permalink
Regression: Improve AggregationCursor types (#23692)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo authored Nov 12, 2021
1 parent f83a422 commit 8875f50
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 10 deletions.
44 changes: 36 additions & 8 deletions app/models/server/raw/Analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,14 @@ export class AnalyticsRaw extends BaseRaw<T> {
});
}

getMessagesSentTotalByDate({ start, end, options = {} }: { start: IAnalytic['date']; end: IAnalytic['date']; options?: { sort?: SortOptionObject<T>; count?: number } }): AggregationCursor<T> {
return this.col.aggregate([
getMessagesSentTotalByDate({ start, end, options = {} }: { start: IAnalytic['date']; end: IAnalytic['date']; options?: { sort?: SortOptionObject<T>; count?: number } }): AggregationCursor<{
_id: IAnalytic['date'];
messages: number;
}> {
return this.col.aggregate<{
_id: IAnalytic['date'];
messages: number;
}>([
{
$match: {
type: 'messages',
Expand All @@ -68,7 +74,10 @@ export class AnalyticsRaw extends BaseRaw<T> {
]);
}

getMessagesOrigin({ start, end }: { start: IAnalytic['date']; end: IAnalytic['date'] }): AggregationCursor<T> {
getMessagesOrigin({ start, end }: { start: IAnalytic['date']; end: IAnalytic['date'] }): AggregationCursor<{
t: 'message';
messages: number;
}> {
const params = [
{
$match: {
Expand All @@ -90,11 +99,24 @@ export class AnalyticsRaw extends BaseRaw<T> {
},
},
];
return this.col.aggregate(params);
return this.col.aggregate<{
t: 'message';
messages: number;
}>(params);
}

getMostPopularChannelsByMessagesSentQuantity({ start, end, options = {} }: { start: IAnalytic['date']; end: IAnalytic['date']; options?: { sort?: SortOptionObject<T>; count?: number } }): AggregationCursor<T> {
return this.col.aggregate([
getMostPopularChannelsByMessagesSentQuantity({ start, end, options = {} }: { start: IAnalytic['date']; end: IAnalytic['date']; options?: { sort?: SortOptionObject<T>; count?: number } }): AggregationCursor<{
t: 'messages';
name: string;
messages: number;
usernames: string[];
}> {
return this.col.aggregate<{
t: 'messages';
name: string;
messages: number;
usernames: string[];
}>([
{
$match: {
type: 'messages',
Expand All @@ -121,8 +143,14 @@ export class AnalyticsRaw extends BaseRaw<T> {
]);
}

getTotalOfRegisteredUsersByDate({ start, end, options = {} }: { start: IAnalytic['date']; end: IAnalytic['date']; options?: { sort?: SortOptionObject<T>; count?: number } }): AggregationCursor<T> {
return this.col.aggregate([
getTotalOfRegisteredUsersByDate({ start, end, options = {} }: { start: IAnalytic['date']; end: IAnalytic['date']; options?: { sort?: SortOptionObject<T>; count?: number } }): AggregationCursor<{
_id: IAnalytic['date'];
users: number;
}> {
return this.col.aggregate<{
_id: IAnalytic['date'];
users: number;
}>([
{
$match: {
type: 'users',
Expand Down
14 changes: 12 additions & 2 deletions app/models/server/raw/Sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,18 @@ const getProjectionByFullDate = (): { day: string; month: string; year: string }
});

export const aggregates = {
dailySessionsOfYesterday(collection: Collection<T>, { year, month, day }: DestructuredDate): AggregationCursor<T> {
return collection.aggregate([{
dailySessionsOfYesterday(collection: Collection<T>, { year, month, day }: DestructuredDate): AggregationCursor<Pick<T, 'mostImportantRole' | 'userId' | 'day' | 'year' | 'month' | 'type'> & {
time: number;
sessions: number;
devices: T['device'][];
_computedAt: string;
}> {
return collection.aggregate<Pick<T, 'mostImportantRole' | 'userId' | 'day' | 'year' | 'month' | 'type'> & {
time: number;
sessions: number;
devices: T['device'][];
_computedAt: string;
}>([{
$match: {
userId: { $exists: true },
lastActivityAt: { $exists: true },
Expand Down

0 comments on commit 8875f50

Please sign in to comment.