Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add media wiki platform and hivemind support #169

Merged
merged 6 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions __tests__/unit/models/module.model.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Module, Platform, Community, User } from '../../../src/models';
import { IModule } from '../../../src/interfaces';
import { Types } from 'mongoose';
import { ModuleNames, PlatformNames } from '../../../src/config/enums';

// import setupTestDB from '../../utils/setupTestDB';

// setupTestDB();
Expand All @@ -10,7 +12,7 @@ describe('Module model', () => {
let module: IModule;
beforeEach(() => {
module = {
name: 'hivemind',
name: ModuleNames.Hivemind,
community: new Types.ObjectId(),
options: {
platforms: [
Expand All @@ -19,7 +21,7 @@ describe('Module model', () => {
metadata: {
selectedChannels: ['c1', 'c2'],
},
name: 'discord',
name: PlatformNames.Discord,
},
],
},
Expand Down
3 changes: 2 additions & 1 deletion __tests__/unit/models/platform.model.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Platform, Community, User, Module } from '../../../src/models';
import { IPlatform } from '../../../src/interfaces';
import { Types } from 'mongoose';
import { PlatformNames } from '../../../src/config/enums';
// import setupTestDB from '../../utils/setupTestDB';

// setupTestDB();
Expand All @@ -10,7 +11,7 @@ describe('Platform model', () => {
let platform: IPlatform;
beforeEach(() => {
platform = {
name: 'google',
name: PlatformNames.Google,
community: new Types.ObjectId(),
disconnectedAt: null,
};
Expand Down
12 changes: 9 additions & 3 deletions __tests__/unit/models/token.model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Token } from '../../../src/models';
import { IToken } from '../../../src/interfaces';
import { Types } from 'mongoose';
import moment from 'moment';
import { TokenTypeNames } from '../../../src/config/enums';

describe('Token model', () => {
describe('Token validation', () => {
Expand All @@ -10,7 +11,7 @@ describe('Token model', () => {
token = {
user: new Types.ObjectId(),
token: '4321',
type: 'google_refresh',
type: TokenTypeNames.GOOGLE_REFRESH,
expires: moment('2022-02-01 08:30:26.127Z').toDate(),
};
});
Expand All @@ -20,8 +21,13 @@ describe('Token model', () => {
});

test('should throw a validation error if type is invalid', async () => {
token.type = 'invalidToken';
await expect(new Token(token).validate()).rejects.toThrow();
const invalidToken = {
user: new Types.ObjectId(),
token: '4321',
type: 'invalidToken',
expires: moment('2022-02-01 08:30:26.127Z').toDate(),
};
await expect(new Token(invalidToken).validate()).rejects.toThrow();
});
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@togethercrew.dev/db",
"version": "3.0.55",
"version": "3.0.60",
"description": "All interactions with DB",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
32 changes: 32 additions & 0 deletions src/config/enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export enum PlatformNames {
Discord = 'discord',
Google = 'google',
GitHub = 'github',
Notion = 'notion',
MediaWiki = 'mediaWiki',
Twitter = 'twitter',
}

export enum ModuleNames {
Hivemind = 'hivemind',
}

export enum HivemindPlatformNames {
Discord = 'discord',
Google = 'google',
GitHub = 'github',
Notion = 'notion',
MediaWiki = 'mediaWiki',
}

export enum TokenTypeNames {
ACCESS = 'access',
REFRESH = 'refresh',
DISCORD_ACCESS = 'discord_access',
DISCORD_REFRESH = 'discord_refresh',
TWITTER_ACCESS = 'twitter_access',
TWITTER_REFRESH = 'twitter_refresh',
GOOGLE_ACCESS = 'google_access',
GOOGLE_REFRESH = 'google_refresh',
NOTION_ACCESS = 'notion_access',
}
11 changes: 0 additions & 11 deletions src/config/tokens.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './models';
export * from './models/schemas';
export * from './interfaces';
export * from './service';
export * from './config/enums';
7 changes: 4 additions & 3 deletions src/interfaces/Module.interface.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { type Model, type Types } from 'mongoose';
import { type PlatformNames, type ModuleNames } from '../config/enums';

export interface IModule {
name: 'hivemind';
name: ModuleNames;
community: Types.ObjectId;
options?: {
platforms: Array<{
platform: Types.ObjectId;
name: 'discord' | 'google' | 'github' | 'notion';
name: PlatformNames;
metadata?: Record<string, any>; // dynamic object since structure can change
}>;
};
Expand All @@ -15,7 +16,7 @@ export interface IModuleUpdateBody {
options?: {
platforms: Array<{
platform: Types.ObjectId;
name: 'discord' | 'google' | 'github' | 'notion';
name: PlatformNames;
metadata?: Record<string, any>; // dynamic object since structure can change
}>;
};
Expand Down
5 changes: 3 additions & 2 deletions src/interfaces/Platfrom.interface.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { type Model, type Types } from 'mongoose';
import { type PlatformNames } from '../config/enums';

export interface IPlatform {
name: 'google' | 'discord' | 'twitter';
name: PlatformNames;
community: Types.ObjectId;
metadata?: Record<string, any>; // dynamic object since structure can change
disconnectedAt?: Date | null;
connectedAt?: Date | null;
}

export interface IPlatformUpdateBody {
name?: 'google' | 'discord' | 'twitter';
name?: PlatformNames;
community?: Types.ObjectId;
metadata?: Record<string, any>;
disconnectedAt?: Date | null;
Expand Down
3 changes: 2 additions & 1 deletion src/interfaces/Token.interface.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { type Model, type Types } from 'mongoose';
import { type TokenTypeNames } from '../config/enums';

export interface IToken {
token: string;
user: Types.ObjectId;
type: string;
type: TokenTypeNames;
expires: Date;
blacklisted?: boolean;
}
Expand Down
5 changes: 3 additions & 2 deletions src/models/schemas/Module.schema.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Schema } from 'mongoose';
import { toJSON, paginate } from './plugins';
import { type IModule, type ModuleModel } from '../../interfaces';
import { PlatformNames, ModuleNames } from '../../config/enums';

const moduleSchema = new Schema<IModule, ModuleModel>(
{
name: {
type: String,
required: true,
enum: ['hivemind'],
enum: Object.values(ModuleNames),
},
community: {
type: Schema.Types.ObjectId,
Expand All @@ -28,7 +29,7 @@ const moduleSchema = new Schema<IModule, ModuleModel>(
name: {
type: String,
required: true,
enum: ['discord', 'google', 'github', 'notion'],
enum: Object.values(PlatformNames),
},
},
],
Expand Down
3 changes: 2 additions & 1 deletion src/models/schemas/Platform.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { Schema, type Document, Types } from 'mongoose';
import { toJSON, paginate } from './plugins';
import { type IPlatform, type PlatformModel } from '../../interfaces';
import { Announcement, Community, Platform, User, Module } from '../index';
import { PlatformNames } from '../../config/enums';

const platformSchema = new Schema<IPlatform, PlatformModel>(
{
name: {
type: String,
required: true,
enum: ['google', 'discord', 'twitter', 'github', 'notion'],
enum: Object.values(PlatformNames),
},
metadata: {
type: Schema.Types.Mixed,
Expand Down
4 changes: 2 additions & 2 deletions src/models/schemas/Token.schema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Schema } from 'mongoose';
import { toJSON } from './plugins';
import { tokenTypes } from '../../config/tokens';
import { type IToken } from '../../interfaces';
import { TokenTypeNames } from '../../config/enums';

const tokenSchema = new Schema<IToken>(
{
Expand All @@ -17,7 +17,7 @@ const tokenSchema = new Schema<IToken>(
},
type: {
type: String,
enum: Object.values(tokenTypes),
enum: Object.values(TokenTypeNames),
required: true,
},
expires: {
Expand Down
Loading