mirror of
https://github.com/ArthurDanjou/artdanj-shortener.git
synced 2026-01-14 15:54:08 +01:00
Add Expire date and redirection type
This commit is contained in:
@@ -1,22 +0,0 @@
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import {rules, schema} from '@ioc:Adonis/Core/Validator'
|
||||
|
||||
export default class StoreValidator {
|
||||
constructor (private ctx: HttpContextContract) {
|
||||
}
|
||||
|
||||
public schema = schema.create({
|
||||
code: schema.string({}, [
|
||||
rules.unique({table: 'links', column: 'code' }),
|
||||
rules.maxLength(10)
|
||||
]),
|
||||
target: schema.string({}),
|
||||
})
|
||||
|
||||
public cacheKey = this.ctx.routeKey
|
||||
|
||||
public messages = {
|
||||
'code.unique': 'The code already exist !',
|
||||
'code.maxLength': 'The code is too long ! (max 10 caracteres)'
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import {schema} from '@ioc:Adonis/Core/Validator'
|
||||
|
||||
export default class UpdateValidator {
|
||||
constructor (private ctx: HttpContextContract) {
|
||||
}
|
||||
|
||||
public schema = schema.create({
|
||||
target: schema.string()
|
||||
})
|
||||
|
||||
|
||||
public cacheKey = this.ctx.routeKey
|
||||
|
||||
|
||||
public messages = {}
|
||||
}
|
||||
24
app/Validators/links/LinkStoreValidator.ts
Executable file
24
app/Validators/links/LinkStoreValidator.ts
Executable file
@@ -0,0 +1,24 @@
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import {rules, schema} from '@ioc:Adonis/Core/Validator'
|
||||
|
||||
export default class LinkStoreValidator {
|
||||
constructor (protected ctx: HttpContextContract) {}
|
||||
|
||||
public schema = schema.create({
|
||||
code: schema.string({}, [
|
||||
rules.unique({table: 'links', column: 'code' }),
|
||||
rules.maxLength(10)
|
||||
]),
|
||||
target: schema.string({
|
||||
trim: true
|
||||
}),
|
||||
type: schema.enum(
|
||||
['TEMPORARY', 'PERMANENT'] as const
|
||||
),
|
||||
expire: schema.date.optional({
|
||||
format: 'yyyy-MM-dd HH:mm:ss',
|
||||
})
|
||||
})
|
||||
|
||||
public messages = {}
|
||||
}
|
||||
20
app/Validators/links/LinkUpdateValidator.ts
Executable file
20
app/Validators/links/LinkUpdateValidator.ts
Executable file
@@ -0,0 +1,20 @@
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import {schema} from '@ioc:Adonis/Core/Validator'
|
||||
|
||||
export default class LinkUpdateValidator {
|
||||
constructor (protected ctx: HttpContextContract) {}
|
||||
|
||||
public schema = schema.create({
|
||||
target: schema.string.optional({
|
||||
trim: true
|
||||
}),
|
||||
type: schema.enum.optional(
|
||||
['TEMPORARY', 'PERMANENT'] as const
|
||||
),
|
||||
expire: schema.date.optional({
|
||||
format: 'yyyy-MM-dd HH:mm:ss',
|
||||
})
|
||||
})
|
||||
|
||||
public messages = {}
|
||||
}
|
||||
Reference in New Issue
Block a user