video-views.ts 781 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Table } from 'sequelize-typescript'
  2. import { VideoModel } from './video'
  3. import * as Sequelize from 'sequelize'
  4. @Table({
  5. tableName: 'videoView',
  6. indexes: [
  7. {
  8. fields: [ 'videoId' ]
  9. },
  10. {
  11. fields: [ 'startDate' ]
  12. }
  13. ]
  14. })
  15. export class VideoViewModel extends Model<VideoViewModel> {
  16. @CreatedAt
  17. createdAt: Date
  18. @AllowNull(false)
  19. @Column(Sequelize.DATE)
  20. startDate: Date
  21. @AllowNull(false)
  22. @Column(Sequelize.DATE)
  23. endDate: Date
  24. @AllowNull(false)
  25. @Column
  26. views: number
  27. @ForeignKey(() => VideoModel)
  28. @Column
  29. videoId: number
  30. @BelongsTo(() => VideoModel, {
  31. foreignKey: {
  32. allowNull: false
  33. },
  34. onDelete: 'CASCADE'
  35. })
  36. Video: VideoModel
  37. }