address的过期checker

This commit is contained in:
Xu Chang 2023-11-11 21:33:41 +08:00
parent 47d27cc6b0
commit 2eac154a18
5 changed files with 4 additions and 90 deletions

View File

@ -1,39 +1,11 @@
import { isMobile } from 'oak-domain/lib/utils/validator';
import { OakInputIllegalException } from "oak-domain/lib/types";
import { checkAttributesNotNull } from 'oak-domain/lib/utils/validator';
const checkers = [
{
type: 'data',
action: 'create',
entity: 'address',
checker: (data) => {
if (data instanceof Array) {
data.forEach(ele => {
checkAttributesNotNull('address', ele, ['name', 'detail', 'phone' /* , 'areaId' */]);
if (!isMobile(ele.phone)) {
throw new OakInputIllegalException('address', ['phone'], '手机号非法');
}
});
}
else {
checkAttributesNotNull('address', data, ['name', 'detail', 'phone' /* , 'areaId' */]);
if (!isMobile(data.phone)) {
throw new OakInputIllegalException('address', ['phone'], '手机号非法');
}
}
},
},
{
type: 'data',
action: 'update',
entity: 'address',
checker: (data) => {
if (data.name === '') {
throw new OakInputIllegalException('address', ['name'], '姓名不可为空');
}
if (data.detail === '') {
throw new OakInputIllegalException('address', ['name'], '详细地址不可为空');
}
if (data.hasOwnProperty('phone') && !isMobile(data.phone)) {
throw new OakInputIllegalException('address', ['phone'], '手机号非法');
}

View File

@ -2,7 +2,7 @@
import { Style } from '../../../../types/Style';
declare const _default: (props: import("oak-frontend-base").ReactComponentProps<import("../../../../oak-app-domain").EntityDict, keyof import("../../../../oak-app-domain").EntityDict, false, {
style: Style;
entity: "system" | "application" | "platform";
entity: "application" | "system" | "platform";
entityId: string;
name: string;
}>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;

View File

@ -13,7 +13,7 @@ declare const _default: <ED2 extends EntityDict & BaseEntityDict, T2 extends key
type?: ButtonProps['type'] | AmButtonProps['type'];
executeText?: string | undefined;
buttonProps?: (ButtonProps & {
color?: "primary" | "success" | "warning" | "default" | "danger" | undefined;
color?: "default" | "success" | "primary" | "warning" | "danger" | undefined;
fill?: "none" | "solid" | "outline" | undefined;
size?: "small" | "large" | "middle" | "mini" | undefined;
block?: boolean | undefined;

View File

@ -2,40 +2,12 @@
Object.defineProperty(exports, "__esModule", { value: true });
const validator_1 = require("oak-domain/lib/utils/validator");
const types_1 = require("oak-domain/lib/types");
const validator_2 = require("oak-domain/lib/utils/validator");
const checkers = [
{
type: 'data',
action: 'create',
entity: 'address',
checker: (data) => {
if (data instanceof Array) {
data.forEach(ele => {
(0, validator_2.checkAttributesNotNull)('address', ele, ['name', 'detail', 'phone' /* , 'areaId' */]);
if (!(0, validator_1.isMobile)(ele.phone)) {
throw new types_1.OakInputIllegalException('address', ['phone'], '手机号非法');
}
});
}
else {
(0, validator_2.checkAttributesNotNull)('address', data, ['name', 'detail', 'phone' /* , 'areaId' */]);
if (!(0, validator_1.isMobile)(data.phone)) {
throw new types_1.OakInputIllegalException('address', ['phone'], '手机号非法');
}
}
},
},
{
type: 'data',
action: 'update',
entity: 'address',
checker: (data) => {
if (data.name === '') {
throw new types_1.OakInputIllegalException('address', ['name'], '姓名不可为空');
}
if (data.detail === '') {
throw new types_1.OakInputIllegalException('address', ['name'], '详细地址不可为空');
}
if (data.hasOwnProperty('phone') && !(0, validator_1.isMobile)(data.phone)) {
throw new types_1.OakInputIllegalException('address', ['phone'], '手机号非法');
}

View File

@ -6,41 +6,11 @@ import { RuntimeCxt } from '../types/RuntimeCxt';
const checkers: Checker<EntityDict, 'address', RuntimeCxt> [] = [
{
type: 'data',
action: 'create',
entity: 'address',
checker: (data) => {
if (data instanceof Array) {
data.forEach(
ele => {
checkAttributesNotNull('address', ele, ['name', 'detail', 'phone'/* , 'areaId' */]);
if (!isMobile(ele.phone!)) {
throw new OakInputIllegalException('address', ['phone'], '手机号非法');
}
}
);
}
else {
checkAttributesNotNull('address', data, ['name', 'detail', 'phone'/* , 'areaId' */]);
if (!isMobile(data.phone!)) {
throw new OakInputIllegalException('address', ['phone'], '手机号非法');
}
}
},
},
{
type: 'data',
action: 'update',
entity: 'address',
checker: (data: EntityDict['address']['Update']['data']) => {
if (data.name === '') {
throw new OakInputIllegalException('address', ['name'], '姓名不可为空');
}
if (data.detail === '') {
throw new OakInputIllegalException('address', ['name'], '详细地址不可为空');
}
if (data.hasOwnProperty('phone') && !isMobile(data.phone!)) {
checker: (data) => {
if (data.hasOwnProperty('phone') && !isMobile((data as EntityDict['address']['Update']['data']).phone!)) {
throw new OakInputIllegalException('address', ['phone'], '手机号非法');
}
return;