Migrated the ShortenedLink.ts model
This commit is contained in:
parent
606df61f2c
commit
5b322bf580
@ -1,35 +1,37 @@
|
||||
import mongoose, {Schema} from 'mongoose';
|
||||
import {sequelize} from "../app";
|
||||
import * as crypto from "crypto";
|
||||
import {DataTypes, InferAttributes, InferCreationAttributes, Model} from "sequelize";
|
||||
|
||||
export interface IShortenedLink {
|
||||
shortenedId: string
|
||||
export interface IShortenedLink extends Model<InferAttributes<IShortenedLink>, InferCreationAttributes<IShortenedLink>> {
|
||||
shortenedId?: string
|
||||
originalUrl: string
|
||||
clientId: number
|
||||
clicks: number
|
||||
created: Date
|
||||
clientId?: number
|
||||
clicks?: number
|
||||
created?: Date
|
||||
}
|
||||
|
||||
const ShortenedSchema = new Schema<IShortenedLink>({
|
||||
const ShortenedSchema = sequelize.define<IShortenedLink>('shortened_links', {
|
||||
shortenedId: {
|
||||
type: String,
|
||||
default: () => crypto.randomBytes(3).toString('hex')
|
||||
type: DataTypes.STRING,
|
||||
defaultValue: () => crypto.randomBytes(3).toString('hex'),
|
||||
allowNull: true
|
||||
},
|
||||
originalUrl: {
|
||||
type: String,
|
||||
required: true
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
clientId: {
|
||||
type: Number,
|
||||
required: true
|
||||
type: DataTypes.BIGINT,
|
||||
allowNull: false
|
||||
},
|
||||
clicks: {
|
||||
type: Number,
|
||||
default: 0
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 0
|
||||
},
|
||||
created: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
type: DataTypes.DATE,
|
||||
defaultValue: Date.now
|
||||
}
|
||||
});
|
||||
|
||||
export const ShortenedLink = mongoose.model('shortened_links', ShortenedSchema);
|
||||
export const ShortenedLink = ShortenedSchema;
|
Loading…
x
Reference in New Issue
Block a user