gatsby-pingbot/lib/schema.ts

28 lines
450 B
TypeScript

import { model, models, Schema } from 'mongoose'
interface URL {
url: string
}
const schema = new Schema<URL>({
url: {
type: String,
required: true,
unique: true
}
})
schema.path('url').validate(async function(value) {
if (models.url) {
return true
}
const count = await models.url.countDocuments({ url: value })
return !count
}, 'URL already exists')
const URLModel = model<URL>('url', schema)
export = URLModel