mirror of
https://github.com/ArthurDanjou/artdanj-shortener.git
synced 2026-01-27 16:55:14 +01:00
Reset Visit count while updating
This commit is contained in:
@@ -49,9 +49,12 @@ export default class LinksController {
|
||||
|
||||
public async updateLink ({request, auth}: HttpContextContract) {
|
||||
await auth.authenticate()
|
||||
const link = await Link.findByOrFail('code', request.input('link'))
|
||||
const link = await Link.findByOrFail('code', request.input('code'))
|
||||
const data = await request.validate(UpdateValidator)
|
||||
await link.merge(data).save()
|
||||
await link.merge({
|
||||
target: data.target,
|
||||
visitCount: 0
|
||||
}).save()
|
||||
return link
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import {rules, schema} from '@ioc:Adonis/Core/Validator'
|
||||
import {schema} from '@ioc:Adonis/Core/Validator'
|
||||
|
||||
export default class UpdateValidator {
|
||||
constructor (private ctx: HttpContextContract) {
|
||||
}
|
||||
|
||||
public schema = schema.create({
|
||||
code: schema.string.optional({}, [
|
||||
rules.unique({table: 'links', column: 'code' }),
|
||||
rules.maxLength(10)
|
||||
]),
|
||||
target: schema.string.optional({}),
|
||||
visit_count: schema.number.optional()
|
||||
target: schema.string()
|
||||
})
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user