diff --git a/models/ShortenedLink.ts b/models/ShortenedLink.ts index 34cceee..6ec5b3d 100644 --- a/models/ShortenedLink.ts +++ b/models/ShortenedLink.ts @@ -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, InferCreationAttributes> { + shortenedId?: string originalUrl: string - clientId: number - clicks: number - created: Date + clientId?: number + clicks?: number + created?: Date } -const ShortenedSchema = new Schema({ +const ShortenedSchema = sequelize.define('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); \ No newline at end of file +export const ShortenedLink = ShortenedSchema; \ No newline at end of file