stuff
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import vine from '@vinejs/vine'
|
||||
|
||||
export const createCategoryValidator = vine.compile(
|
||||
vine.object({
|
||||
name: vine.string().unique(async (db, value) => {
|
||||
const match = await db.from('categories').select('id').where('name', value).first()
|
||||
return !match
|
||||
}),
|
||||
nameHu: vine.string().optional(),
|
||||
nameEn: vine.string().optional(),
|
||||
slug: vine.string().unique(async (db, value) => {
|
||||
const match = await db.from('categories').select('id').where('slug', value).first()
|
||||
return !match
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
export const updateCategoryValidator = vine.compile(
|
||||
vine.object({
|
||||
id: vine.number(),
|
||||
name: vine
|
||||
.string()
|
||||
.unique(async (db, value, field) => {
|
||||
const match = await db
|
||||
.from('categories')
|
||||
.select('id')
|
||||
.where('name', value)
|
||||
.whereNot('id', field.data.id)
|
||||
.first()
|
||||
return !match
|
||||
})
|
||||
.optional(),
|
||||
nameHu: vine.string().optional(),
|
||||
nameEn: vine.string().optional(),
|
||||
slug: vine
|
||||
.string()
|
||||
.unique(async (db, value, field) => {
|
||||
const match = await db
|
||||
.from('categories')
|
||||
.select('id')
|
||||
.where('slug', value)
|
||||
.whereNot('id', field.data.id)
|
||||
.first()
|
||||
return !match
|
||||
})
|
||||
.optional(),
|
||||
})
|
||||
)
|
||||
@@ -0,0 +1,32 @@
|
||||
import vine from '@vinejs/vine'
|
||||
|
||||
export const createUserValidator = vine.compile(
|
||||
vine.object({
|
||||
email: vine.string().email().normalizeEmail(),
|
||||
password: vine.string().minLength(8),
|
||||
fullName: vine.string(),
|
||||
role: vine.string(),
|
||||
})
|
||||
)
|
||||
export const updateUserValidator = vine.compile(
|
||||
vine.object({
|
||||
id: vine.number(),
|
||||
email: vine
|
||||
.string()
|
||||
.email()
|
||||
.normalizeEmail()
|
||||
.unique(async (db, value, field) => {
|
||||
const match = await db
|
||||
.from('users')
|
||||
.select('id')
|
||||
.where('email', value)
|
||||
.whereNot('id', field.data.id)
|
||||
.first()
|
||||
return !match
|
||||
})
|
||||
.optional(),
|
||||
password: vine.string().minLength(8).optional(),
|
||||
fullName: vine.string().optional(),
|
||||
role: vine.string().optional(),
|
||||
})
|
||||
)
|
||||
Reference in New Issue
Block a user