Migrated the Token.ts model
This commit is contained in:
parent
5b322bf580
commit
8b4fc500a2
@ -1,40 +1,41 @@
|
|||||||
import mongoose, {Schema} from 'mongoose';
|
import {sequelize} from "../app";
|
||||||
import * as crypto from "crypto";
|
import * as crypto from "crypto";
|
||||||
|
import {DataTypes, InferAttributes, InferCreationAttributes, Model} from "sequelize";
|
||||||
|
|
||||||
export enum TokenType {
|
export enum TokenType {
|
||||||
API, SESSION
|
API, SESSION
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IToken {
|
export interface IToken extends Model<InferAttributes<IToken>, InferCreationAttributes<IToken>> {
|
||||||
token: string
|
token?: string
|
||||||
clientId: number
|
clientId: number
|
||||||
type: TokenType
|
type?: TokenType
|
||||||
userAgent?: string
|
userAgent?: string
|
||||||
created: Date
|
created?: Date
|
||||||
}
|
}
|
||||||
|
|
||||||
const TokenSchema = new Schema<IToken>({
|
const TokenSchema = sequelize.define<IToken>('tokens', {
|
||||||
token: {
|
token: {
|
||||||
type: String,
|
type: DataTypes.STRING,
|
||||||
default: () => crypto.randomBytes(48).toString('hex')
|
defaultValue: () => crypto.randomBytes(48).toString('hex'),
|
||||||
|
primaryKey: true
|
||||||
},
|
},
|
||||||
clientId: {
|
clientId: {
|
||||||
type: Number,
|
type: DataTypes.BIGINT,
|
||||||
required: true
|
allowNull: false
|
||||||
},
|
},
|
||||||
type: {
|
type: {
|
||||||
type: Number,
|
type: DataTypes.STRING,
|
||||||
enum: TokenType,
|
defaultValue: TokenType.API
|
||||||
default: TokenType.SESSION
|
|
||||||
},
|
},
|
||||||
userAgent: {
|
userAgent: {
|
||||||
type: String,
|
type: DataTypes.STRING,
|
||||||
required: false
|
allowNull: true
|
||||||
},
|
},
|
||||||
created: {
|
created: {
|
||||||
type: Date,
|
type: DataTypes.DATE,
|
||||||
default: Date.now
|
defaultValue: Date.now
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export const Token = mongoose.model('tokens', TokenSchema);
|
export const Token = TokenSchema;
|
Loading…
x
Reference in New Issue
Block a user