-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Feat: add notification database model and update related models * Chore: add migrations Also adds id to site_members table for easier reference * Feat: add notificationService * Feat: add notificationUtils * Feat: add notifications router * Chore: initialise Notifications table and services * Fix: remove unused imports * Fix: change behaviour of quick retrieval Always returns only new notifications now, unless there are none, in which case it returns most recent 6 * Chore: remove unused imports * Refactor: findAll method * Chore: add notificationResponse type * Feat: add created_at sorting criteria * Fix: notification sorting order * Chore: add documentation for sort criteria * Fix: rebase errors * Fix: rebase errors for tests
- Loading branch information
1 parent
90eb48e
commit a78d7e4
Showing
12 changed files
with
695 additions
and
2 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
src/database/migrations/20220926081632-change-primary-key-site-members.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
module.exports = { | ||
async up(queryInterface, Sequelize) { | ||
await queryInterface.sequelize.transaction(async (transaction) => { | ||
Promise.all([ | ||
queryInterface.changeColumn("site_members", "user_id", { | ||
allowNull: false, | ||
primaryKey: false, | ||
type: Sequelize.BIGINT, | ||
references: { | ||
model: "users", | ||
key: "id", | ||
}, | ||
onUpdate: "CASCADE", | ||
onDelete: "CASCADE", | ||
transaction, | ||
}), | ||
queryInterface.changeColumn("site_members", "site_id", { | ||
type: Sequelize.BIGINT, | ||
allowNull: false, | ||
primaryKey: false, | ||
references: { | ||
model: "sites", | ||
key: "id", | ||
}, | ||
onUpdate: "CASCADE", | ||
onDelete: "CASCADE", | ||
transaction, | ||
}), | ||
queryInterface.addColumn( | ||
"site_members", // name of Source model | ||
"id", // name of column we're adding | ||
{ | ||
unique: true, | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.BIGINT, | ||
transaction, | ||
} | ||
), | ||
]) | ||
}) | ||
}, | ||
|
||
async down(queryInterface, Sequelize) { | ||
await queryInterface.sequelize.transaction(async (transaction) => { | ||
Promise.all([ | ||
queryInterface.removeColumn( | ||
"site_members", // name of Source Model | ||
"id", // name of column we want to remove | ||
{ transaction } | ||
), | ||
queryInterface.changeColumn("site_members", "user_id", { | ||
allowNull: false, | ||
primaryKey: true, | ||
type: Sequelize.BIGINT, | ||
references: { | ||
model: "users", | ||
key: "id", | ||
}, | ||
onUpdate: "CASCADE", | ||
onDelete: "CASCADE", | ||
transaction, | ||
}), | ||
queryInterface.changeColumn("site_members", "site_id", { | ||
type: Sequelize.BIGINT, | ||
allowNull: false, | ||
primaryKey: true, | ||
references: { | ||
model: "sites", | ||
key: "id", | ||
}, | ||
onUpdate: "CASCADE", | ||
onDelete: "CASCADE", | ||
transaction, | ||
}), | ||
]) | ||
}) | ||
}, | ||
} |
80 changes: 80 additions & 0 deletions
80
src/database/migrations/20220926081632-create-notifications.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
module.exports = { | ||
up: async (queryInterface, Sequelize) => { | ||
await queryInterface.createTable("notifications", { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.BIGINT, | ||
}, | ||
site_member_id: { | ||
allowNull: false, | ||
type: Sequelize.BIGINT, | ||
references: { | ||
model: "site_members", | ||
key: "id", | ||
}, | ||
onUpdate: "CASCADE", | ||
onDelete: "CASCADE", | ||
}, | ||
site_id: { | ||
allowNull: false, | ||
type: Sequelize.BIGINT, | ||
references: { | ||
model: "sites", | ||
key: "id", | ||
}, | ||
onUpdate: "CASCADE", | ||
onDelete: "CASCADE", | ||
}, | ||
user_id: { | ||
allowNull: false, | ||
type: Sequelize.BIGINT, | ||
references: { | ||
model: "users", | ||
key: "id", | ||
}, | ||
onUpdate: "CASCADE", | ||
onDelete: "CASCADE", | ||
}, | ||
message: { | ||
allowNull: true, | ||
type: Sequelize.STRING, | ||
}, | ||
link: { | ||
allowNull: true, | ||
type: Sequelize.STRING, | ||
}, | ||
source_username: { | ||
allowNull: false, | ||
type: Sequelize.STRING, | ||
}, | ||
type: { | ||
allowNull: false, | ||
type: Sequelize.STRING, | ||
}, | ||
first_read_time: { | ||
allowNull: true, | ||
type: Sequelize.DATE, | ||
}, | ||
priority: { | ||
allowNull: false, | ||
type: Sequelize.BIGINT, | ||
}, | ||
created_at: { | ||
type: Sequelize.DATE, | ||
allowNull: false, | ||
defaultValue: Sequelize.fn("NOW"), | ||
}, | ||
updated_at: { | ||
type: Sequelize.DATE, | ||
allowNull: false, | ||
defaultValue: Sequelize.fn("NOW"), | ||
}, | ||
}) | ||
}, | ||
|
||
down: async (queryInterface) => { | ||
await queryInterface.dropTable("notifications") | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { | ||
DataType, | ||
Column, | ||
Model, | ||
Table, | ||
CreatedAt, | ||
UpdatedAt, | ||
DeletedAt, | ||
BelongsToMany, | ||
HasOne, | ||
BelongsTo, | ||
ForeignKey, | ||
} from "sequelize-typescript" | ||
|
||
import { Site } from "@database/models/Site" | ||
import { SiteMember } from "@database/models/SiteMember" | ||
import { User } from "@database/models/User" | ||
|
||
@Table({ tableName: "notifications" }) | ||
export class Notification extends Model { | ||
@Column({ | ||
autoIncrement: true, | ||
primaryKey: true, | ||
allowNull: false, | ||
type: DataType.BIGINT, | ||
}) | ||
id!: number | ||
|
||
@ForeignKey(() => SiteMember) | ||
siteMemberId!: number | ||
|
||
@BelongsTo(() => SiteMember) | ||
siteMember!: SiteMember | ||
|
||
@ForeignKey(() => Site) | ||
siteId!: number | ||
|
||
@BelongsTo(() => Site) | ||
site!: Site | ||
|
||
@ForeignKey(() => User) | ||
userId!: number | ||
|
||
@BelongsTo(() => User) | ||
user!: Site | ||
|
||
@Column({ | ||
allowNull: true, | ||
type: DataType.TEXT, | ||
}) | ||
message!: string | ||
|
||
@Column({ | ||
allowNull: true, | ||
type: DataType.TEXT, | ||
}) | ||
link!: string | ||
|
||
@Column({ | ||
allowNull: true, | ||
type: DataType.TEXT, | ||
}) | ||
sourceUsername!: string | ||
|
||
@Column({ | ||
allowNull: false, | ||
type: DataType.TEXT, | ||
}) | ||
type!: string | ||
|
||
@Column({ | ||
allowNull: true, | ||
type: DataType.DATE, | ||
}) | ||
firstReadTime!: Date | null | ||
|
||
@Column({ | ||
allowNull: false, | ||
type: DataType.BIGINT, | ||
}) | ||
priority!: number | ||
|
||
@CreatedAt | ||
createdAt!: Date | ||
|
||
@UpdatedAt | ||
updatedAt!: Date | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.