adonisjs / validator

Schema based validator for AdonisJS
MIT License
116 stars 39 forks source link

How to change data values in validator #181

Closed sublymus closed 9 months ago

sublymus commented 9 months ago

Package version

@ioc:Adonis/Core/Validator

Describe the bug

import { validator } from "@ioc:Adonis/Core/Validator";

validator.rule("flleList", async (value, _, options) => { const { root, mutate } = options;

try {
 const fileList =   JSON.parse(value);
 console.log({fileList});

 if(Array.isArray(fileList)){
    options.mutate(fileList);
    root.photos = fileList
 }
} catch (error) {}

},() => ({ allowUndefineds: true, async: true, }));

Reproduction repo

No response

sublymus commented 9 months ago

// I receive the same value when I use trim or my validator

export const update_product_validator = schema.create({ id:schema.string(), photos:schema.string({},[ rules.trim(), rules.flleList(), // My validation ]) })