Skip to content

Commit

Permalink
Merge pull request #117 from TogetherCrew/114-new-db-models-schema-an…
Browse files Browse the repository at this point in the history
…d-methods

114 new db models schema and methods
  • Loading branch information
cyri113 authored Oct 7, 2023
2 parents 4584ef2 + ef06a71 commit 434e276
Show file tree
Hide file tree
Showing 19 changed files with 240 additions and 292 deletions.
163 changes: 72 additions & 91 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,56 +35,39 @@ docker compose -f docker-compose.test.yml up --exit-code-from app --build

Note: This will create a /coverage folder where you can review the coverage details.

### Schema for rawinfo

### User interface

```ts
rawinfo {
type: number,
author: Snowflake,
content: string,
createdDate: Date,
user_mentions: Array<Snowflake>,
role_mentions: Array<Snowflake>,
reactions: Array<Snowflake>,
replied_user: Snowflake | null | undefined,
messageId: Snowflake,
channelId: Snowflake,
channelName: string | null,
threadId: Snowflake | null,
threadName: string | null,
isGeneratedByWebhook: boolean
User {
discordId: Snowflake,
email?: string,
communities?: [Types.ObjectId]
}
```

### Schema for user
### Community interface

```ts
User {
discordId: Snowflake,
username?: string,
discriminator?: string,
avatar?: string,
bot?: boolean,
system?: boolean,
mfa_enabled?: boolean,
banner?: string,
accent_color?: number
locale?: string,
verified?: boolean
email?: string,
flags?: number,
premium_type?: number,
public_flags?: number,
twitterId?: string,
twitterUsername?: string,
twitterProfileImageUrl?: string,
twitterConnectedAt?:string,
twitterIsInProgress?:boolean

Community {
name: string,
avatarURL?: string,
users?: [Types.ObjectId],
platforms?: [Types.ObjectId],
}
```

### Schema for heatmap
### Platform interface

```ts
Platform {
name: string,
community: Types.ObjectId,
metadata?: Record<string, any>, // dynamic object since structure can change
disconnectedAt?: Date | null,
}
```
### Heatmap interface

```ts
HeatMap {
Expand All @@ -105,7 +88,7 @@ HeatMap {
}
```

### Schema for guildMembers
### GuildMembers interface

```ts
GuildMember {
Expand All @@ -124,7 +107,52 @@ GuildMember {

```

### Schema for memberactivities
### Channel interface

```ts
Channel {
id: Snowflake,
name?: string | null,
parent_id?: string | null,
permissionOverwrites?: IOverwrite[],
deletedAt?: Date | null
}
```


### Role interface

```ts
Role {
id: Snowflake,
name: string,
color: number,
deletedAt?: Date | null
}
```

### Rawinfo interface

```ts
rawinfo {
type: number,
author: Snowflake,
content: string,
createdDate: Date,
user_mentions: Array<Snowflake>,
role_mentions: Array<Snowflake>,
reactions: Array<Snowflake>,
replied_user: Snowflake | null | undefined,
messageId: Snowflake,
channelId: Snowflake,
channelName: string | null,
threadId: Snowflake | null,
threadName: string | null,
isGeneratedByWebhook: boolean
}
```

### Memberactivities interface

```ts
memberactivities {
Expand Down Expand Up @@ -153,7 +181,7 @@ memberactivities {
}
```

### Schema for token
### Token interface

```ts
Token {
Expand All @@ -163,51 +191,4 @@ Token {
expires: Date,
blacklisted?: boolean
}
```

### Schema for guild

```ts
Guild {
guildId: Snowflake,
user: Snowflake,
name?: string,
connectedAt?: Date,
isInProgress?: Boolean,
isDisconnected?: Boolean,
icon?: string,
selectedChannels?: Array<objects> [
{
channelId: Snowflake,
channelName?: string
}
],
period?: Date,
aciton: Array<number>,
window: Array<number>
}
```

### Schema for channel

```ts
Channel {
id: Snowflake,
name?: string | null,
parent_id?: string | null,
permissionOverwrites?: IOverwrite[],
deletedAt?: Date | null
}
```


### Schema for role

```ts
Role {
id: Snowflake,
name: string,
color: number,
deletedAt?: Date | null
}
```
```
19 changes: 19 additions & 0 deletions __tests__/unit/models/community.mode.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Community } from '../../../src/models';
import { ICommunity } from '../../../src/interfaces';
import { Types } from 'mongoose';

describe('Community model', () => {
describe('Community validation', () => {
let community: ICommunity;
beforeEach(() => {
community = {
name: 'community1',
users: [new Types.ObjectId()],
};
});

test('should correctly validate a valid community', async () => {
await expect(new Community(community).validate()).resolves.toBeUndefined();
});
});
});
33 changes: 0 additions & 33 deletions __tests__/unit/models/guild.model.test.ts

This file was deleted.

19 changes: 19 additions & 0 deletions __tests__/unit/models/platform.model.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Platfrom } from '../../../src/models';
import { IPlatform } from '../../../src/interfaces';
import { Types } from 'mongoose';

describe('Platfrom model', () => {
describe('Platform validation', () => {
let platfrom: IPlatform;
beforeEach(() => {
platfrom = {
name: 'Discord',
community: new Types.ObjectId(),
};
});

test('should correctly validate a valid platfrom', async () => {
await expect(new Platfrom(platfrom).validate()).resolves.toBeUndefined();
});
});
});
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": "2.5.02",
"version": "3.0.00",
"description": "All interactions with DB",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
19 changes: 19 additions & 0 deletions src/interfaces/Community.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { type Model, type Types } from 'mongoose';

export interface ICommunity {
name: string;
avatarURL?: string;
users: [Types.ObjectId];
platforms?: [Types.ObjectId];
}

export interface ICommunityUpdateBody {
name?: string;
avatarURL?: string;
users?: [Types.ObjectId];
platforms?: [Types.ObjectId];
}

export interface CommunityModel extends Model<ICommunity> {
paginate: (filter: object, options: object) => any;
}
34 changes: 0 additions & 34 deletions src/interfaces/Guild.interface.ts

This file was deleted.

19 changes: 19 additions & 0 deletions src/interfaces/Platfrom.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { type Model, type Types } from 'mongoose';

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

export interface IPlatformUpdateBody {
name?: string;
community?: Types.ObjectId;
metadata?: Record<string, any>;
disconnectedAt?: Date | null;
}

export interface PlatformModel extends Model<IPlatform> {
paginate: (filter: object, options: object) => any;
}
Loading

0 comments on commit 434e276

Please sign in to comment.