aboutsummaryrefslogtreecommitdiff
path: root/lib/models/instance/Reminder.ts
blob: 8d46edb6579ae6fad6dc7485f3817dba5ce9706b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { Snowflake } from 'discord.js';
import { nanoid } from 'nanoid';
import { DataTypes, type Sequelize } from 'sequelize';
import { BaseModel } from '../BaseModel.js';

export interface ReminderModel {
	id: string;
	user: Snowflake;
	messageUrl: string;
	content: string;
	created: Date;
	expires: Date;
	notified: boolean;
}

export interface ReminderModelCreationAttributes {
	id?: string;
	user: Snowflake;
	messageUrl: string;
	content: string;
	created: Date;
	expires: Date;
	notified?: boolean;
}

/**
 * Represents a reminder the a user has set.
 */
export class Reminder extends BaseModel<ReminderModel, ReminderModelCreationAttributes> implements ReminderModel {
	/**
	 * The id of the reminder.
	 */
	public declare id: string;

	/**
	 * The user that the reminder is for.
	 */
	public declare user: Snowflake;

	/**
	 * The url of the message where the reminder was created.
	 */
	public declare messageUrl: string;

	/**
	 * The content of the reminder.
	 */
	public declare content: string;

	/**
	 * The date the reminder was created.
	 */
	public declare created: Date;

	/**
	 * The date when the reminder expires.
	 */
	public declare expires: Date;

	/**
	 * Whether the user has been notified about the reminder.
	 */
	public declare notified: boolean;

	/**
	 * Initializes the model.
	 * @param sequelize The sequelize instance.
	 */
	public static initModel(sequelize: Sequelize): void {
		Reminder.init(
			{
				id: { type: DataTypes.STRING, primaryKey: true, defaultValue: nanoid },
				user: { type: DataTypes.STRING, allowNull: false },
				messageUrl: { type: DataTypes.STRING, allowNull: false },
				content: { type: DataTypes.TEXT, allowNull: false },
				created: { type: DataTypes.DATE, allowNull: false },
				expires: { type: DataTypes.DATE, allowNull: false },
				notified: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false }
			},
			{ sequelize }
		);
	}
}