feat(api): add maximum value validation
This commit is contained in:
parent
7d9b5b958a
commit
23e93f43af
@ -5,27 +5,25 @@ import { validatorCompiler } from 'services/validation';
|
|||||||
import { UAParser } from 'ua-parser-js';
|
import { UAParser } from 'ua-parser-js';
|
||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
|
|
||||||
interface PostReportBody {
|
const PostBodyReportSchema = yup.object().shape({
|
||||||
readonly reason?: string;
|
reason: yup.string().min(10).max(1000).required(),
|
||||||
readonly url: string;
|
url: yup.string().max(1000).url().required(),
|
||||||
readonly userAgent?: string;
|
userAgent: yup.string().max(1000).optional(),
|
||||||
readonly version: string;
|
version: yup
|
||||||
}
|
.string()
|
||||||
|
.max(10)
|
||||||
|
.matches(/^\d+(\.\d+){0,3}$/)
|
||||||
|
.required(),
|
||||||
|
});
|
||||||
|
|
||||||
|
type PostReportBody = yup.InferType<typeof PostBodyReportSchema>;
|
||||||
|
|
||||||
export default (server: FastifyInstance, options: RouteShorthandOptions, done: () => void) => {
|
export default (server: FastifyInstance, options: RouteShorthandOptions, done: () => void) => {
|
||||||
server.post<{ Body: PostReportBody }>(
|
server.post<{ Body: PostReportBody }>(
|
||||||
'/report/',
|
'/report/',
|
||||||
{
|
{
|
||||||
schema: {
|
schema: {
|
||||||
body: yup.object().shape({
|
body: PostBodyReportSchema,
|
||||||
reason: yup.string().min(10).required(),
|
|
||||||
url: yup.string().url().required(),
|
|
||||||
userAgent: yup.string(),
|
|
||||||
version: yup
|
|
||||||
.string()
|
|
||||||
.matches(/^\d+(\.\d+){0,3}$/)
|
|
||||||
.required(),
|
|
||||||
}),
|
|
||||||
},
|
},
|
||||||
validatorCompiler,
|
validatorCompiler,
|
||||||
},
|
},
|
||||||
|
@ -5,27 +5,25 @@ import { validatorCompiler } from 'services/validation';
|
|||||||
import { UAParser } from 'ua-parser-js';
|
import { UAParser } from 'ua-parser-js';
|
||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
|
|
||||||
interface PostReportBody {
|
const PostBodyReportSchema = yup.object().shape({
|
||||||
readonly reason?: string;
|
reason: yup.string().min(10).max(1000).required(),
|
||||||
readonly url: string;
|
url: yup.string().max(1000).url().required(),
|
||||||
readonly userAgent?: string;
|
userAgent: yup.string().max(1000).optional(),
|
||||||
readonly version: string;
|
version: yup
|
||||||
}
|
.string()
|
||||||
|
.max(10)
|
||||||
|
.matches(/^\d+(\.\d+){0,3}$/)
|
||||||
|
.required(),
|
||||||
|
});
|
||||||
|
|
||||||
|
type PostReportBody = yup.InferType<typeof PostBodyReportSchema>;
|
||||||
|
|
||||||
export default (server: FastifyInstance, _options: RouteShorthandOptions, done: () => void) => {
|
export default (server: FastifyInstance, _options: RouteShorthandOptions, done: () => void) => {
|
||||||
server.post<{ Body: PostReportBody }>(
|
server.post<{ Body: PostReportBody }>(
|
||||||
'/report/',
|
'/report/',
|
||||||
{
|
{
|
||||||
schema: {
|
schema: {
|
||||||
body: yup.object().shape({
|
body: PostBodyReportSchema,
|
||||||
reason: yup.string().min(10).required(),
|
|
||||||
url: yup.string().url().required(),
|
|
||||||
userAgent: yup.string(),
|
|
||||||
version: yup
|
|
||||||
.string()
|
|
||||||
.matches(/^\d+(\.\d+){0,3}$/)
|
|
||||||
.required(),
|
|
||||||
}),
|
|
||||||
},
|
},
|
||||||
validatorCompiler,
|
validatorCompiler,
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user