gatsby-pingbot/lib/schema.ts

24 lines
409 B
TypeScript
Raw Normal View History

2021-09-15 19:39:07 +00:00
import { model, models, Schema } from "mongoose"
interface URL {
url: string
}
const schema = new Schema<URL>({
url: {
type: String,
required: true,
unique: true
}
})
2021-09-15 20:26:37 +00:00
schema.path('url').validate(async function(value) {
2021-09-15 19:39:07 +00:00
const count = await models.URL.countDocuments({ url: value })
return !count
}, 'URL already exists')
2021-09-15 20:26:37 +00:00
const URLModel = model<URL>('url', schema)
2021-09-15 19:39:07 +00:00
export = URLModel