import {sequelize} from "../app"; import * as crypto from "crypto"; import {DataTypes, InferAttributes, InferCreationAttributes, Model} from "sequelize"; export interface IShortenedLink extends Model, InferCreationAttributes> { shortenedId?: string originalUrl: string clientId?: number clicks?: number created?: Date } const ShortenedSchema = sequelize.define('shortened_links', { shortenedId: { type: DataTypes.STRING, defaultValue: () => crypto.randomBytes(3).toString('hex'), allowNull: true }, originalUrl: { type: DataTypes.STRING, allowNull: false }, clientId: { type: DataTypes.BIGINT, allowNull: false }, clicks: { type: DataTypes.INTEGER, defaultValue: 0 }, created: { type: DataTypes.DATE, defaultValue: Date.now } }); export const ShortenedLink = ShortenedSchema;