Skip to content

Commit

Permalink
feat(ut): rr views (#530)
Browse files Browse the repository at this point in the history
* feat: add model and migration for review_request_views table

* chore: rename migration

* fix: add missing association with ReviewRequest model

* fix: revert adding association in ReviewRequest model

Co-authored-by: Hsu Zhong Jun <[email protected]>
  • Loading branch information
seaerchin and dcshzj authored Oct 13, 2022
1 parent c977dd1 commit c6c354c
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable("review_request_views", {
review_request_id: {
allowNull: false,
primaryKey: true,
type: Sequelize.BIGINT,
references: {
model: "review_requests",
key: "id",
},
onUpdate: "CASCADE",
onDelete: "CASCADE",
},
site_id: {
type: Sequelize.BIGINT,
allowNull: false,
primaryKey: true,
references: {
model: "sites",
key: "id",
},
onUpdate: "CASCADE",
onDelete: "CASCADE",
},
user_id: {
type: Sequelize.BIGINT,
allowNull: false,
primaryKey: true,
references: {
model: "users",
key: "id",
},
onUpdate: "CASCADE",
onDelete: "CASCADE",
},
last_viewed_at: {
type: Sequelize.DATE,
allowNull: true,
defaultValue: null,
},
created_at: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.fn("NOW"),
},
updated_at: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.fn("NOW"),
},
})
},

async down(queryInterface, Sequelize) {
await queryInterface.dropTable("review_request_views")
},
}
53 changes: 53 additions & 0 deletions src/database/models/ReviewRequestView.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import {
ForeignKey,
DataType,
Column,
Model,
Table,
BelongsTo,
PrimaryKey,
} from "sequelize-typescript"

import { ReviewRequest } from "@database/models/ReviewRequest"
import { Site } from "@database/models/Site"
import { User } from "@database/models/User"

@Table({ tableName: "review_request_views" })
// eslint-disable-next-line import/prefer-default-export
export class ReviewRequestView extends Model {
@ForeignKey(() => ReviewRequest)
@PrimaryKey
reviewRequestId!: number

@BelongsTo(() => ReviewRequest, {
onUpdate: "CASCADE",
onDelete: "CASCADE",
})
reviewRequest!: ReviewRequest

@ForeignKey(() => Site)
@PrimaryKey
siteId!: number

@BelongsTo(() => Site, {
onUpdate: "CASCADE",
onDelete: "CASCADE",
})
site!: Site

@ForeignKey(() => User)
@PrimaryKey
userId!: number

@BelongsTo(() => User, {
onUpdate: "CASCADE",
onDelete: "CASCADE",
})
user!: User

@Column({
allowNull: true,
type: DataType.DATE,
})
lastViewedAt!: Date
}
1 change: 1 addition & 0 deletions src/database/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from "@database/models/Notification"
export * from "@database/models/ReviewMeta"
export * from "@database/models/ReviewRequest"
export * from "@database/models/Reviewers"
export * from "@database/models/ReviewRequestView"

0 comments on commit c6c354c

Please sign in to comment.