Skip to content

Commit

Permalink
Convert other indexes to same pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego committed Apr 7, 2022
1 parent 8b970c5 commit 049a303
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 52 deletions.
10 changes: 3 additions & 7 deletions app/models/server/raw/Banners.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { Collection, Cursor, FindOneOptions, UpdateWriteOpResult, WithoutProjection, InsertOneWriteOpResult } from 'mongodb';
import { Cursor, FindOneOptions, UpdateWriteOpResult, WithoutProjection, InsertOneWriteOpResult } from 'mongodb';

import { BannerPlatform, IBanner } from '../../../../definition/IBanner';
import { BaseRaw } from './BaseRaw';

type T = IBanner;
export class BannersRaw extends BaseRaw<T> {
constructor(public readonly col: Collection<T>, trash?: Collection<T>) {
super(col, trash);

this.col.createIndexes([{ key: { platform: 1, startAt: 1, expireAt: 1 } }]);

this.col.createIndexes([{ key: { platform: 1, startAt: 1, expireAt: 1, active: 1 } }]);
protected modelIndexes() {
return [{ key: { platform: 1, startAt: 1, expireAt: 1 } }, { key: { platform: 1, startAt: 1, expireAt: 1, active: 1 } }];
}

create(doc: IBanner): Promise<InsertOneWriteOpResult<IBanner>> {
Expand Down
8 changes: 3 additions & 5 deletions app/models/server/raw/BannersDismiss.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { Collection, Cursor, FindOneOptions, WithoutProjection } from 'mongodb';
import { Cursor, FindOneOptions, WithoutProjection } from 'mongodb';

import { IBannerDismiss } from '../../../../definition/IBanner';
import { BaseRaw } from './BaseRaw';

export class BannersDismissRaw extends BaseRaw<IBannerDismiss> {
constructor(public readonly col: Collection<IBannerDismiss>, trash?: Collection<IBannerDismiss>) {
super(col, trash);

this.col.createIndexes([{ key: { userId: 1, bannerId: 1 } }]);
modelIndexes() {
return [{ key: { userId: 1, bannerId: 1 } }];
}

findByUserIdAndBannerId(userId: string, bannerIds: string[]): Cursor<IBannerDismiss>;
Expand Down
8 changes: 3 additions & 5 deletions app/models/server/raw/Nps.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { UpdateWriteOpResult, Collection } from 'mongodb';
import { UpdateWriteOpResult } from 'mongodb';

import { BaseRaw } from './BaseRaw';
import { INps, NPSStatus } from '../../../../definition/INps';

type T = INps;
export class NpsRaw extends BaseRaw<T> {
constructor(public readonly col: Collection<T>, trash?: Collection<T>) {
super(col, trash);

this.col.createIndexes([{ key: { status: 1, expireAt: 1 } }]);
modelIndexes() {
return [{ key: { status: 1, expireAt: 1 } }];
}

// get expired surveys still in progress
Expand Down
8 changes: 3 additions & 5 deletions app/models/server/raw/NpsVote.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { ObjectId, Collection, Cursor, FindOneOptions, UpdateWriteOpResult, WithoutProjection } from 'mongodb';
import { ObjectId, Cursor, FindOneOptions, UpdateWriteOpResult, WithoutProjection } from 'mongodb';

import { INpsVote, INpsVoteStatus } from '../../../../definition/INps';
import { BaseRaw } from './BaseRaw';

type T = INpsVote;
export class NpsVoteRaw extends BaseRaw<T> {
constructor(public readonly col: Collection<T>, trash?: Collection<T>) {
super(col, trash);

this.col.createIndexes([{ key: { npsId: 1, status: 1, sentAt: 1 } }, { key: { npsId: 1, identifier: 1 } }]);
modelIndexes() {
return [{ key: { npsId: 1, status: 1, sentAt: 1 } }, { key: { npsId: 1, identifier: 1 } }];
}

findNotSentByNpsId(npsId: string, options?: WithoutProjection<FindOneOptions<T>>): Cursor<T> {
Expand Down
20 changes: 3 additions & 17 deletions app/models/server/raw/Team.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
import {
Collection,
WithoutProjection,
FindOneOptions,
Cursor,
UpdateWriteOpResult,
DeleteWriteOpResultObject,
FilterQuery,
} from 'mongodb';
import { WithoutProjection, FindOneOptions, Cursor, UpdateWriteOpResult, DeleteWriteOpResultObject, FilterQuery } from 'mongodb';

import { BaseRaw } from './BaseRaw';
import { ITeam, TEAM_TYPE } from '../../../../definition/ITeam';

export class TeamRaw extends BaseRaw<ITeam> {
constructor(public readonly col: Collection<ITeam>, trash?: Collection<ITeam>) {
super(col, trash);

this.col.createIndex({ name: 1 }, { unique: true });

// this.col.createIndexes([
// { key: { status: 1, expireAt: 1 } },
// ]);
protected modelIndexes() {
return [{ key: { name: 1 }, unique: true }];
}

findByNames(names: Array<string>): Cursor<ITeam>;
Expand Down
18 changes: 10 additions & 8 deletions app/models/server/raw/TeamMember.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
Collection,
WithoutProjection,
FindOneOptions,
Cursor,
Expand All @@ -15,13 +14,16 @@ import type { IUser, IRole } from '../../../../definition/IUser';

type T = ITeamMember;
export class TeamMemberRaw extends BaseRaw<T> {
constructor(public readonly col: Collection<T>, trash?: Collection<T>) {
super(col, trash);

this.col.createIndexes([{ key: { teamId: 1 } }]);

// teamId => userId should be unique
this.col.createIndex({ teamId: 1, userId: 1 }, { unique: true });
protected modelIndexes() {
return [
{
key: { teamId: 1 },
},
{
key: { teamId: 1, userId: 1 },
unique: true,
},
];
}

findByUserId(userId: string): Cursor<ITeamMember>;
Expand Down
8 changes: 3 additions & 5 deletions app/models/server/raw/WebdavAccounts.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
/**
* Webdav Accounts model
*/
import type { Collection, FindOneOptions, Cursor, DeleteWriteOpResultObject } from 'mongodb';
import type { FindOneOptions, Cursor, DeleteWriteOpResultObject } from 'mongodb';

import { BaseRaw } from './BaseRaw';
import { IWebdavAccount } from '../../../../definition/IWebdavAccount';

type T = IWebdavAccount;

export class WebdavAccountsRaw extends BaseRaw<T> {
constructor(public readonly col: Collection<T>, trash?: Collection<T>) {
super(col, trash);

this.col.createIndex({ userId: 1 });
protected modelIndexes() {
return [{ key: { userId: 1 } }];
}

findOneByIdAndUserId(_id: string, userId: string, options: FindOneOptions<T>): Promise<T | null> {
Expand Down

0 comments on commit 049a303

Please sign in to comment.