Tweet.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import {
  2. Table,
  3. Column,
  4. AllowNull,
  5. DataType,
  6. Model,
  7. Default,
  8. } from 'sequelize-typescript'
  9. export interface TweetData {
  10. username: string
  11. statusId: string
  12. url: string
  13. cleanHTML: string
  14. body: object
  15. order: number
  16. }
  17. @Table({
  18. modelName: 'tweet',
  19. indexes: [
  20. {
  21. fields: ['statusId'],
  22. unique: true,
  23. },
  24. ],
  25. })
  26. export default class Tweet extends Model {
  27. @AllowNull(false)
  28. @Column(DataType.CHAR(255))
  29. get username(): string {
  30. return this.getDataValue('username')
  31. }
  32. @AllowNull(false)
  33. @Column(DataType.CHAR(30))
  34. get statusId(): string {
  35. return this.getDataValue('statusId')
  36. }
  37. @AllowNull(false)
  38. @Column(DataType.TEXT)
  39. get url(): string {
  40. return this.getDataValue('url')
  41. }
  42. @AllowNull(false)
  43. @Column(DataType.TEXT)
  44. get cleanHTML(): string {
  45. return this.getDataValue('cleanHTML')
  46. }
  47. @AllowNull(false)
  48. @Default(false)
  49. @Column(DataType.BOOLEAN)
  50. get disabled(): boolean {
  51. return this.getDataValue('disabled')
  52. }
  53. @AllowNull(false)
  54. @Column(DataType.JSON)
  55. get body(): object {
  56. return this.getDataValue('body')
  57. }
  58. @AllowNull(false)
  59. @Default(0)
  60. @Column(DataType.INTEGER.UNSIGNED)
  61. get order(): number {
  62. return this.getDataValue('order')
  63. }
  64. getData(): TweetData {
  65. return {
  66. username: this.username,
  67. statusId: this.statusId,
  68. url: this.url,
  69. cleanHTML: this.cleanHTML,
  70. body: this.body,
  71. order: this.order,
  72. }
  73. }
  74. }