]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-tag.ts
Stricter models typing
[github/Chocobozzz/PeerTube.git] / server / models / video / video-tag.ts
index 71ca85332a6f32c7715bb40f43599331dfd98794..1285d375bb91cebbab4237e71f5cbe3d18231463 100644 (file)
@@ -1,27 +1,31 @@
-import * as Sequelize from 'sequelize'
+import { Column, CreatedAt, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript'
+import { AttributesOnly } from '@shared/core-utils'
+import { TagModel } from './tag'
+import { VideoModel } from './video'
 
-import { addMethodsToModel } from '../utils'
-import {
-  VideoTagClass,
-  VideoTagInstance,
-  VideoTagAttributes,
+@Table({
+  tableName: 'videoTag',
+  indexes: [
+    {
+      fields: [ 'videoId' ]
+    },
+    {
+      fields: [ 'tagId' ]
+    }
+  ]
+})
+export class VideoTagModel extends Model<Partial<AttributesOnly<VideoTagModel>>> {
+  @CreatedAt
+  createdAt: Date
 
-  VideoTagMethods
-} from './video-tag-interface'
+  @UpdatedAt
+  updatedAt: Date
 
-let VideoTag: Sequelize.Model<VideoTagInstance, VideoTagAttributes>
+  @ForeignKey(() => VideoModel)
+  @Column
+  videoId: number
 
-export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
-  VideoTag = sequelize.define<VideoTagInstance, VideoTagAttributes>('VideoTag', {}, {
-    indexes: [
-      {
-        fields: [ 'videoId' ]
-      },
-      {
-        fields: [ 'tagId' ]
-      }
-    ]
-  })
-
-  return VideoTag
+  @ForeignKey(() => TagModel)
+  @Column
+  tagId: number
 }