Files
t-admin/unpackage/dist/dev/mp-weixin/js_sdk/validator/uni-id-log.js
T
2025-06-13 21:16:12 +08:00

185 lines
3.5 KiB
JavaScript

"use strict";
const validator = {
"create_date": {
"rules": [
{
"format": "timestamp"
}
]
},
"device_uuid": {
"rules": [
{
"format": "string"
}
]
},
"ip": {
"rules": [
{
"format": "string"
}
]
},
"state": {
"rules": [
{
"format": "int"
}
]
},
"type": {
"rules": [
{
"format": "string"
},
{
"range": [
{
"value": "logout",
"text": "logout"
},
{
"value": "login",
"text": "login"
},
{
"value": "register",
"text": "register"
},
{
"value": "reset-pwd",
"text": "reset-pwd"
},
{
"value": "bind-mobile",
"text": "bind-mobile"
},
{
"value": "bind-weixin",
"text": "bind-weixin"
},
{
"value": "bind-qq",
"text": "bind-qq"
},
{
"value": "bind-apple",
"text": "bind-apple"
},
{
"value": "bind-alipay",
"text": "bind-alipay"
}
]
}
]
},
"ua": {
"rules": [
{
"format": "string"
}
]
},
"user_id": {
"rules": [
{
"required": true
},
{
"format": "string"
}
]
},
"username": {
"rules": [
{
"format": "string"
}
]
},
"email": {
"rules": [
{
"format": "string"
}
]
},
"mobile": {
"rules": [
{
"format": "string"
}
]
},
"appid": {
"rules": [
{
"format": "string"
}
]
}
};
const enumConverter = {
"type_valuetotext": {
"logout": "logout",
"login": "login",
"register": "register",
"reset-pwd": "reset-pwd",
"bind-mobile": "bind-mobile",
"bind-weixin": "bind-weixin",
"bind-qq": "bind-qq",
"bind-apple": "bind-apple",
"bind-alipay": "bind-alipay"
}
};
function filterToWhere(filter, command) {
let where = {};
for (let field in filter) {
let { type, value } = filter[field];
switch (type) {
case "search":
if (typeof value === "string" && value.length) {
where[field] = new RegExp(value);
}
break;
case "select":
if (value.length) {
let selectValue = [];
for (let s of value) {
selectValue.push(command.eq(s));
}
where[field] = command.or(selectValue);
}
break;
case "range":
if (value.length) {
let gt = value[0];
let lt = value[1];
where[field] = command.and([command.gte(gt), command.lte(lt)]);
}
break;
case "date":
if (value.length) {
let [s, e] = value;
let startDate = new Date(s);
let endDate = new Date(e);
where[field] = command.and([command.gte(startDate), command.lte(endDate)]);
}
break;
case "timestamp":
if (value.length) {
let [startDate, endDate] = value;
where[field] = command.and([command.gte(startDate), command.lte(endDate)]);
}
break;
}
}
return where;
}
exports.enumConverter = enumConverter;
exports.filterToWhere = filterToWhere;
exports.validator = validator;
//# sourceMappingURL=../../../.sourcemap/mp-weixin/js_sdk/validator/uni-id-log.js.map