Skip to content

Commit 6b03dc1

Browse files
authored
Merge pull request #95 from TogetherCrew/94-add-deletedat-field-to-role-channel-and-guild-member-schemas
[FEATURE]: add deletedAt to channel-role-guild member schema and soft…
2 parents 941e1bf + 84033f2 commit 6b03dc1

File tree

12 files changed

+57
-14
lines changed

12 files changed

+57
-14
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ GuildMember {
107107
isBot?: boolean,
108108
discriminator?: string,
109109
permissions?: string;
110+
deletedAt?: Date | null
110111
}
111112

112113
```
@@ -182,7 +183,8 @@ Channel {
182183
id: Snowflake,
183184
name?: string | null,
184185
parent_id?: string | null,
185-
permissionOverwrites?: IOverwrite[]
186+
permissionOverwrites?: IOverwrite[],
187+
deletedAt?: Date | null
186188
}
187189
```
188190

@@ -194,5 +196,6 @@ Role {
194196
id: Snowflake,
195197
name: string,
196198
color: number,
199+
deletedAt?: Date | null
197200
}
198201
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@togethercrew.dev/db",
3-
"version": "2.4.9",
3+
"version": "2.4.91",
44
"description": "All interactions with DB",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

src/interfaces/Channel.interface.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,19 @@ export interface IChannel {
1313
name?: string | null;
1414
parentId?: string | null;
1515
permissionOverwrites?: IOverwrite[];
16+
deletedAt?: Date | null;
1617
}
1718

1819
export interface IChannelUpdateBody {
1920
name?: string | null;
2021
parentId?: string | null;
2122
permissionOverwrites?: IOverwrite[];
23+
deletedAt?: Date | null;
24+
}
25+
export interface IChannelMethods {
26+
softDelete: () => void;
2227
}
2328

24-
export interface ChannelModel extends Model<IChannel> {
29+
export interface ChannelModel extends Model<IChannel, Record<string, unknown>, IChannelMethods> {
2530
paginate: (filter: object, options: object) => any;
2631
}

src/interfaces/GuildMember.interface.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface IGuildMember {
1010
isBot?: boolean;
1111
discriminator: string;
1212
permissions?: string;
13+
deletedAt?: Date | null;
1314
}
1415

1516
export interface IGuildMemberUpdateBody {
@@ -19,8 +20,13 @@ export interface IGuildMemberUpdateBody {
1920
discriminator?: string;
2021
joinedAt?: Date | null;
2122
permissions?: string;
23+
deletedAt?: Date | null;
2224
}
2325

24-
export interface GuildMemberModel extends Model<IGuildMember> {
26+
export interface IGuildMemberMethods {
27+
softDelete: () => void;
28+
}
29+
30+
export interface GuildMemberModel extends Model<IGuildMember, Record<string, unknown>, IGuildMemberMethods> {
2531
paginate: (filter: object, options: object) => any;
2632
}

src/interfaces/Role.interface.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@ export interface IRole {
55
roleId: Snowflake;
66
name: string;
77
color: number;
8+
deletedAt?: Date | null;
89
}
910

1011
export interface IRoleUpdateBody {
1112
name?: string;
1213
color?: number;
14+
deletedAt?: Date | null;
1315
}
1416

15-
export interface RoleModel extends Model<IRole> {
17+
export interface IRoleMethods {
18+
softDelete: () => void;
19+
}
20+
21+
export interface RoleModel extends Model<IRole, Record<string, unknown>, IRoleMethods> {
1622
paginate: (filter: object, options: object) => any;
1723
}

src/models/schemas/Channel.schema.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Schema } from 'mongoose';
22
import { toJSON } from './plugins';
3-
import { IChannel, ChannelModel } from '../../interfaces';
3+
import { type IChannel, type ChannelModel } from '../../interfaces';
44

55
const channelSchema = new Schema<IChannel, ChannelModel>({
66
channelId: {
@@ -24,6 +24,15 @@ const channelSchema = new Schema<IChannel, ChannelModel>({
2424
deny: String,
2525
},
2626
],
27+
deletedAt: {
28+
type: Date,
29+
default: null,
30+
},
31+
});
32+
33+
channelSchema.method('softDelete', function softDelete() {
34+
this.deletedAt = Date.now();
35+
this.save();
2736
});
2837

2938
// Plugins

src/models/schemas/Guild.schema.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Schema } from 'mongoose';
22
import { paginate, toJSON } from './plugins';
3-
import { IGuild, GuildModel } from '../../interfaces';
3+
import { type IGuild, type GuildModel } from '../../interfaces';
44

55
const guildSchema = new Schema<IGuild, GuildModel>({
66
guildId: {
@@ -48,7 +48,7 @@ const guildSchema = new Schema<IGuild, GuildModel>({
4848
type: Array<number>,
4949
default: [7, 1],
5050
validate: {
51-
validator: function (arr: Array<number>) {
51+
validator: function (arr: number[]) {
5252
return arr.length === 2;
5353
},
5454
message: 'Window must be an array with exactly 2 numbers',
@@ -58,7 +58,7 @@ const guildSchema = new Schema<IGuild, GuildModel>({
5858
type: Array<number>,
5959
default: [1, 1, 1, 4, 3, 5, 5, 4, 3, 2, 2, 2, 1],
6060
validate: {
61-
validator: function (arr: Array<number>) {
61+
validator: function (arr: number[]) {
6262
return arr.length === 13;
6363
},
6464
message: 'Action must be an array with exactly 11 numbers',

src/models/schemas/GuildMember.schema.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Schema } from 'mongoose';
22
import { toJSON } from './plugins';
3-
import { IGuildMember, GuildMemberModel } from '../../interfaces';
3+
import { type IGuildMember, type GuildMemberModel } from '../../interfaces';
44

55
const guildMemberSchema = new Schema<IGuildMember, GuildMemberModel>({
66
discordId: {
@@ -32,6 +32,11 @@ const guildMemberSchema = new Schema<IGuildMember, GuildMemberModel>({
3232
},
3333
});
3434

35+
guildMemberSchema.method('softDelete', function softDelete() {
36+
this.deletedAt = Date.now();
37+
this.save();
38+
});
39+
3540
// Plugins
3641
guildMemberSchema.plugin(toJSON);
3742

src/models/schemas/HeatMap.schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Schema } from 'mongoose';
22
import { toJSON } from './plugins';
3-
import { IHeatMap } from '../../interfaces';
3+
import { type IHeatMap } from '../../interfaces';
44

55
const heatMapSchema = new Schema<IHeatMap>({
66
date: {

src/models/schemas/Role.schema.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Schema } from 'mongoose';
22
import { toJSON } from './plugins';
3-
import { IRole, RoleModel } from '../../interfaces';
3+
import { type IRole, type RoleModel } from '../../interfaces';
44

55
const roleSchema = new Schema<IRole, RoleModel>({
66
roleId: {
@@ -13,6 +13,15 @@ const roleSchema = new Schema<IRole, RoleModel>({
1313
color: {
1414
type: Number,
1515
},
16+
deletedAt: {
17+
type: Date,
18+
default: null,
19+
},
20+
});
21+
22+
roleSchema.method('softDelete', function softDelete() {
23+
this.deletedAt = Date.now();
24+
this.save();
1625
});
1726

1827
// Plugins

0 commit comments

Comments
 (0)