Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Validation #90

Open
STDigitalIN opened this issue Dec 9, 2024 · 0 comments
Open

Custom Validation #90

STDigitalIN opened this issue Dec 9, 2024 · 0 comments

Comments

@STDigitalIN
Copy link

Sometime async custom validation is return before async request completes.

niv.extend('existsS3', async ({ value, args }) => {
let bucket = args[0];
let prefix = args[1];
let s3Client = new S3Client({
region: process.env.AWS_REGION,
});

try {
    await s3Client.send(
        new HeadObjectCommand({
            Bucket: bucket,
            Key: path.join(prefix, value),
        })
    );
    return true;
} catch (error) {
    console.log('errrrr');

    return false;
}

});

const v = new niv.Validator(metadata, {
tracks: 'required|array|between:1,100',
'tracks..title': 'required|string|maxLength:150',
'tracks.
.mediaUrl': required|string|wavFile|existsS3:${sourceBucket},${sourcePrefix},
});
const matched = await v.check();

matched returns true before existsS3 rule completes its execution .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant