Files
outline/server/models/Notification.ts
Apoorv Mishra 1e39b564fe Throttle email notifications upon updating document frequently (#4026)
* feat: add needed columns for throttling notifs

* feat: update model

* feat: deliver only one notif in a 12 hour window

* fix: address review comments

* prevent retry if notification update fails
* fix type compatibility instead of circumventing it
* add index for emailedAt

* fix: add metadata attr to EmailProps

* chore: decouple metadata from EmailProps

* chore: add test

* chore: revert sending metadata in props
2022-09-07 16:51:30 +05:30

80 lines
1.2 KiB
TypeScript

import {
Table,
ForeignKey,
Model,
Column,
PrimaryKey,
IsUUID,
CreatedAt,
BelongsTo,
DataType,
Default,
AllowNull,
} from "sequelize-typescript";
import Document from "./Document";
import Team from "./Team";
import User from "./User";
import Fix from "./decorators/Fix";
@Table({
tableName: "notifications",
modelName: "notification",
updatedAt: false,
})
@Fix
class Notification extends Model {
@IsUUID(4)
@PrimaryKey
@Default(DataType.UUIDV4)
@Column(DataType.UUID)
id: string;
@AllowNull
@Column
emailedAt: Date;
@AllowNull
@Column
viewedAt: Date;
@CreatedAt
createdAt: Date;
@Column
event: string;
// associations
@BelongsTo(() => User, "userId")
user: User;
@ForeignKey(() => User)
@Column(DataType.UUID)
userId: string;
@BelongsTo(() => User, "actorId")
actor: User;
@AllowNull
@ForeignKey(() => User)
@Column(DataType.UUID)
actorId: string;
@BelongsTo(() => Document, "documentId")
document: Document;
@AllowNull
@ForeignKey(() => Document)
@Column(DataType.UUID)
documentId: string;
@BelongsTo(() => Team, "teamId")
team: Team;
@ForeignKey(() => Team)
@Column(DataType.UUID)
teamId: string;
}
export default Notification;