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 * as crypto from "crypto";
|
||||||
|
import {DataTypes, InferAttributes, InferCreationAttributes, Model} from "sequelize";
|
||||||
|
|
||||||
export interface IShortenedLink {
|
export interface IShortenedLink extends Model<InferAttributes<IShortenedLink>, InferCreationAttributes<IShortenedLink>> {
|
||||||
shortenedId: string
|
shortenedId?: string
|
||||||
originalUrl: string
|
originalUrl: string
|
||||||
clientId: number
|
clientId?: number
|
||||||
clicks: number
|
clicks?: number
|
||||||
created: Date
|
created?: Date
|
||||||
}
|
}
|
||||||
|
|
||||||
const ShortenedSchema = new Schema<IShortenedLink>({
|
const ShortenedSchema = sequelize.define<IShortenedLink>('shortened_links', {
|
||||||
shortenedId: {
|
shortenedId: {
|
||||||
type: String,
|
type: DataTypes.STRING,
|
||||||
default: () => crypto.randomBytes(3).toString('hex')
|
defaultValue: () => crypto.randomBytes(3).toString('hex'),
|
||||||
|
allowNull: true
|
||||||
},
|
},
|
||||||
originalUrl: {
|
originalUrl: {
|
||||||
type: String,
|
type: DataTypes.STRING,
|
||||||
required: true
|
allowNull: false
|
||||||
},
|
},
|
||||||
clientId: {
|
clientId: {
|
||||||
type: Number,
|
type: DataTypes.BIGINT,
|
||||||
required: true
|
allowNull: false
|
||||||
},
|
},
|
||||||
clicks: {
|
clicks: {
|
||||||
type: Number,
|
type: DataTypes.INTEGER,
|
||||||
default: 0
|
defaultValue: 0
|
||||||
},
|
},
|
||||||
created: {
|
created: {
|
||||||
type: Date,
|
type: DataTypes.DATE,
|
||||||
default: Date.now
|
defaultValue: Date.now
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export const ShortenedLink = mongoose.model('shortened_links', ShortenedSchema);
|
export const ShortenedLink = ShortenedSchema;
|
Loading…
x
Reference in New Issue
Block a user