Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | 19x 19x 28x 1x 27x | import * as yup from 'yup';
import { MESSAGES } from '../../config/messages';
import { isValidDocumentIdForYup, isValidIntegerForYup } from '../../utils';
import { optionalBaseRequestSchema } from '../main/main.request.schema';
import { FeedbackDocument, RecommendFeedbackDocument } from './feedback.document.type';
// @ts-ignore
export const feedbackDocumentSchema: yup.SchemaOf<FeedbackDocument> =
optionalBaseRequestSchema.concat(
yup.object().shape({
query: yup.string().required(MESSAGES.QUERY_IS_REQUIRED),
url: yup.string().url(MESSAGES.URL_IS_NOT_VALID).optional(),
itemId: yup.string().optional().test('test-id', MESSAGES.IS_INVALID_DOCUMENT_ID, isValidDocumentIdForYup),
itemOrder: yup.number().optional().test('is-integer', MESSAGES.ITEM_ORDER_IS_NOT_INTEGER, isValidIntegerForYup),
})
);
// @ts-ignore
export const recommendFeedbackDocumentSchema: yup.SchemaOf<RecommendFeedbackDocument> =
optionalBaseRequestSchema.concat(
yup.object().shape({
sourceId: yup.string().required(MESSAGES.SOURCE_ID_IS_REQUIRED).test('test-id', MESSAGES.SOURCE_ID_IS_INVALID_DOCUMENT_ID, isValidDocumentIdForYup),
sourceTitle: yup.string().optional().min(1, MESSAGES.SOURCE_TITLE_LENGTH_IS_INVALID),
sourceUrl: yup.string().optional().url(MESSAGES.URL_IS_NOT_VALID),
targetId: yup
.string()
.required(MESSAGES.TARGET_ID_IS_REQUIRED)
.test('test-id', MESSAGES.TARGET_ID_IS_INVALID_DOCUMENT_ID, isValidDocumentIdForYup)
.test(
'test-equal-with-source-id',
MESSAGES.TARGET_ID_MUST_BE_DIFFERENT_THAN_SOURCE_ID,
function notEqualToSourceId(value, context) {
if (context.parent.sourceId == context.parent.targetId)
return false;
return true;
}),
targetTitle: yup.string().optional().min(1, MESSAGES.TARGET_TITLE_LENGTH_IS_INVALID),
targetUrl: yup.string().optional().url(MESSAGES.URL_IS_NOT_VALID),
itemOrder: yup.number().optional().test('is-integer', MESSAGES.ITEM_ORDER_IS_NOT_INTEGER, isValidIntegerForYup),
})
);
|