Skip to content

Commit

Permalink
Merge pull request #93 from TogetherCrew/92-add-permissions-field-to-…
Browse files Browse the repository at this point in the history
…guildmember-interface-and-permissionoverwrites-field-to-channel-interface

92 add permissions field to guildmember interface and permissionoverwrites field to channel interface
  • Loading branch information
cyri113 authored Jul 19, 2023
2 parents 1f48c5a + 66bb34e commit 941e1bf
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 12 deletions.
14 changes: 3 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ GuildMember {
roles: Snowflake[],
joinedAt: Date | null,
isBot?: boolean,
discriminator: string
discriminator?: string,
permissions?: string;
}

```
Expand Down Expand Up @@ -139,16 +140,6 @@ memberactivities {
}
```

### Schema for channels

```ts
Channels {
channel: string,
channelId: Snowflake,
last_update: Date
}
```

### Schema for token

```ts
Expand Down Expand Up @@ -191,6 +182,7 @@ Channel {
id: Snowflake,
name?: string | null,
parent_id?: string | null,
permissionOverwrites?: IOverwrite[]
}
```

Expand Down
14 changes: 14 additions & 0 deletions __tests__/unit/models/channel.model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ describe('Channel model', () => {
channelId: '123',
name: 'channel1',
parentId: 'admin',
permissionOverwrites: [
{
id: '1122334455', // example Snowflake ID for the role or member
type: 0,
allow: 'VIEW_CHANNEL',
deny: 'SEND_MESSAGES',
},
{
id: '9988776655', // another example Snowflake ID for the role or member
type: 1,
allow: 'VIEW_CHANNEL,SEND_MESSAGES',
deny: '',
},
],
};
});
test('should correctly validate a valid Channel data', async () => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/unit/models/guildMember.model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('guildMember model', () => {
avatar: '100',
isBot: true,
discriminator: 'str',
permissions: '137411140513354n',
};
});
test('should correctly validate a valid guildMember data', async () => {
Expand Down
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.4.8",
"version": "2.4.9",
"description": "All interactions with DB",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
9 changes: 9 additions & 0 deletions src/interfaces/Channel.interface.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import { type Snowflake } from 'discord.js';
import { type Model } from 'mongoose';

export interface IOverwrite {
id: Snowflake; // ID of the role or user this overwrite applies to
type: 0 | 1; // Specifies if this overwrite applies to a role(0) or a member(1)
allow: string; // Permissions allowed by this overwrite
deny: string; // Permissions denied by this overwrite
}

export interface IChannel {
channelId: Snowflake;
name?: string | null;
parentId?: string | null;
permissionOverwrites?: IOverwrite[];
}

export interface IChannelUpdateBody {
name?: string | null;
parentId?: string | null;
permissionOverwrites?: IOverwrite[];
}

export interface ChannelModel extends Model<IChannel> {
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/GuildMember.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface IGuildMember {
joinedAt: Date | null;
isBot?: boolean;
discriminator: string;
permissions?: string;
}

export interface IGuildMemberUpdateBody {
Expand All @@ -17,6 +18,7 @@ export interface IGuildMemberUpdateBody {
roles?: Snowflake[];
discriminator?: string;
joinedAt?: Date | null;
permissions?: string;
}

export interface GuildMemberModel extends Model<IGuildMember> {
Expand Down
11 changes: 11 additions & 0 deletions src/models/schemas/Channel.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ const channelSchema = new Schema<IChannel, ChannelModel>({
parentId: {
type: String,
},
permissionOverwrites: [
{
id: String, // or use mongoose.Schema.Types.ObjectId if Snowflake is an ObjectId
type: {
type: Number,
enum: [0, 1],
},
allow: String,
deny: String,
},
],
});

// Plugins
Expand Down
3 changes: 3 additions & 0 deletions src/models/schemas/GuildMember.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const guildMemberSchema = new Schema<IGuildMember, GuildMemberModel>({
discriminator: {
type: String,
},
permissions: {
type: String,
},
});

// Plugins
Expand Down

0 comments on commit 941e1bf

Please sign in to comment.