Backend/models/ShortenedLink.ts

37 lines
990 B
TypeScript

import {sequelize} from "../app";
import * as crypto from "crypto";
import {DataTypes, InferAttributes, InferCreationAttributes, Model} from "sequelize";
export interface IShortenedLink extends Model<InferAttributes<IShortenedLink>, InferCreationAttributes<IShortenedLink>> {
shortenedId?: string
originalUrl: string
clientId?: number
clicks?: number
created?: Date
}
const ShortenedSchema = sequelize.define<IShortenedLink>('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;