refactor: lodash-es to lodash in server

This commit is contained in:
moonrailgun 2023-09-14 20:19:31 +08:00
parent f8a372006f
commit 78133b7227
4 changed files with 21 additions and 11 deletions

View File

@ -32,6 +32,7 @@
"express-validator": "^7.0.1", "express-validator": "^7.0.1",
"is-localhost-ip": "^2.0.0", "is-localhost-ip": "^2.0.0",
"jsonwebtoken": "^9.0.2", "jsonwebtoken": "^9.0.2",
"lodash": "^4.17.21",
"lodash-es": "^4.17.21", "lodash-es": "^4.17.21",
"maxmind": "^4.3.11", "maxmind": "^4.3.11",
"morgan": "^1.10.0", "morgan": "^1.10.0",
@ -57,6 +58,7 @@
"@types/compression": "^1.7.2", "@types/compression": "^1.7.2",
"@types/express": "^4.17.17", "@types/express": "^4.17.17",
"@types/jsonwebtoken": "^9.0.2", "@types/jsonwebtoken": "^9.0.2",
"@types/lodash": "^4.14.198",
"@types/lodash-es": "^4.17.9", "@types/lodash-es": "^4.17.9",
"@types/morgan": "^1.9.5", "@types/morgan": "^1.9.5",
"@types/node": "^18.17.12", "@types/node": "^18.17.12",

View File

@ -58,6 +58,9 @@ dependencies:
jsonwebtoken: jsonwebtoken:
specifier: ^9.0.2 specifier: ^9.0.2
version: 9.0.2 version: 9.0.2
lodash:
specifier: ^4.17.21
version: 4.17.21
lodash-es: lodash-es:
specifier: ^4.17.21 specifier: ^4.17.21
version: 4.17.21 version: 4.17.21
@ -129,6 +132,9 @@ devDependencies:
'@types/jsonwebtoken': '@types/jsonwebtoken':
specifier: ^9.0.2 specifier: ^9.0.2
version: 9.0.2 version: 9.0.2
'@types/lodash':
specifier: ^4.14.198
version: 4.14.198
'@types/lodash-es': '@types/lodash-es':
specifier: ^4.17.9 specifier: ^4.17.9
version: 4.17.9 version: 4.17.9
@ -1947,11 +1953,11 @@ packages:
/@types/lodash-es@4.17.9: /@types/lodash-es@4.17.9:
resolution: {integrity: sha512-ZTcmhiI3NNU7dEvWLZJkzG6ao49zOIjEgIE0RgV7wbPxU0f2xT3VSAHw2gmst8swH6V0YkLRGp4qPlX/6I90MQ==} resolution: {integrity: sha512-ZTcmhiI3NNU7dEvWLZJkzG6ao49zOIjEgIE0RgV7wbPxU0f2xT3VSAHw2gmst8swH6V0YkLRGp4qPlX/6I90MQ==}
dependencies: dependencies:
'@types/lodash': 4.14.197 '@types/lodash': 4.14.198
dev: true dev: true
/@types/lodash@4.14.197: /@types/lodash@4.14.198:
resolution: {integrity: sha512-BMVOiWs0uNxHVlHBgzTIqJYmj+PgCo4euloGF+5m4okL3rEYzM2EEv78mw8zWSMM57dM7kVIgJ2QDvwHSoCI5g==} resolution: {integrity: sha512-trNJ/vtMZYMLhfN45uLq4ShQSw0/S7xCTLLVM+WM1rmFpba/VS42jVUgaO3w/NOLiWR/09lnYk0yMaA/atdIsg==}
dev: true dev: true
/@types/mapbox-gl@1.13.6: /@types/mapbox-gl@1.13.6:

View File

@ -4,7 +4,8 @@ import { DATA_TYPE } from './const';
import { DynamicDataType } from './types'; import { DynamicDataType } from './types';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import jwt from 'jsonwebtoken'; import jwt from 'jsonwebtoken';
import { max } from 'lodash-es'; import _ from 'lodash';
import { getWorkspaceWebsiteDateRange } from '../model/workspace';
export function isUuid(value: string) { export function isUuid(value: string) {
return validate(value); return validate(value);
@ -151,7 +152,7 @@ export function parseToken(token: string, secret = jwtSecret) {
} }
export function maxDate(...args: any[]) { export function maxDate(...args: any[]) {
return max(args.filter((n) => dayjs(n).isValid())); return _.max(args.filter((n) => dayjs(n).isValid()));
} }
export async function parseDateRange({ export async function parseDateRange({
@ -167,10 +168,11 @@ export async function parseDateRange({
}) { }) {
// All-time // All-time
if (+startAt === 0 && +endAt === 1) { if (+startAt === 0 && +endAt === 1) {
const result = await getWorkspaceWebsiteDateRange(websiteId as string); const { min, max } = await getWorkspaceWebsiteDateRange(
const { min, max } = result[0]; websiteId as string
const startDate = new Date(min); );
const endDate = new Date(max); const startDate = new Date(min!);
const endDate = new Date(max!);
return { return {
startDate, startDate,

View File

@ -1,4 +1,4 @@
import { get } from 'lodash-es'; import _ from 'lodash';
import { loadWebsite } from '../model/website'; import { loadWebsite } from '../model/website';
import { maxDate } from './common'; import { maxDate } from './common';
import { FILTER_COLUMNS, OPERATORS, SESSION_COLUMNS } from './const'; import { FILTER_COLUMNS, OPERATORS, SESSION_COLUMNS } from './const';
@ -80,7 +80,7 @@ export function getFilterQuery(
const query = Object.keys(filters).reduce<string[]>((arr, name) => { const query = Object.keys(filters).reduce<string[]>((arr, name) => {
const value: any = filters[name as keyof QueryFilters]; const value: any = filters[name as keyof QueryFilters];
const operator = value?.filter ?? OPERATORS.equals; const operator = value?.filter ?? OPERATORS.equals;
const column = get(FILTER_COLUMNS, name, options?.columns?.[name]); const column = _.get(FILTER_COLUMNS, name, options?.columns?.[name]);
if (value !== undefined && column) { if (value !== undefined && column) {
arr.push(`and ${mapFilter(column, operator, name)}`); arr.push(`and ${mapFilter(column, operator, name)}`);