import { BeforeInsert , BeforeUpdate , Column , Entity } from 'typeorm' ; import { PrimaryGeneratedColumn } from 'typeorm/index' ; import { User } from './User' ; import { JoinColumn } from 'typeorm/index' ; import { ManyToOne } from 'typeorm/index' ; import { BaseModel } from './BaseModel' ; import moment = require ( 'moment' ) ; @ Entity ( 'access_token' ) export class AccessToken extends BaseModel { @ PrimaryGeneratedColumn ( { name : 'id' } ) public id : number ; @ Column ( { name : 'user_id' } ) public userId : number ; @ Column ( { name : 'token' } ) public token : string ; @ ManyToOne ( type => User , user => user . accessToken ) @ JoinColumn ( { name : 'user_id' } ) public user : User ; @ BeforeInsert ( ) public async createDetails ( ) { this . createdDate = moment ( ) . format ( 'YYYY-MM-DD HH:mm:ss' ) ; } @ BeforeUpdate ( ) public async updateDetails ( ) { this . modifiedDate = moment ( ) . format ( 'YYYY-MM-DD HH:mm:ss' ) ; } }