From ce02958bc22a653749d9a967ed79a648cebfd45f Mon Sep 17 00:00:00 2001 From: Brian Cao Date: Fri, 18 Nov 2022 11:22:03 -0800 Subject: [PATCH] Fix enum issue. --- interface/enum.d.ts => lib/enum.ts | 2 +- queries/admin/user.ts | 28 ++++++++----------- queries/analytics/event/getEventData.ts | 2 +- queries/analytics/event/getEventMetrics.ts | 2 +- queries/analytics/event/saveEvent.ts | 2 +- .../analytics/pageview/getPageviewMetrics.ts | 2 +- .../analytics/pageview/getPageviewStats.ts | 2 +- queries/analytics/pageview/savePageView.ts | 2 +- 8 files changed, 18 insertions(+), 24 deletions(-) rename interface/enum.d.ts => lib/enum.ts (79%) diff --git a/interface/enum.d.ts b/lib/enum.ts similarity index 79% rename from interface/enum.d.ts rename to lib/enum.ts index 8b09039c..d8270333 100644 --- a/interface/enum.d.ts +++ b/lib/enum.ts @@ -1,6 +1,6 @@ /* eslint-disable no-unused-vars */ export namespace UmamiApi { - enum EventType { + export enum EventType { Pageview = 1, Event = 2, } diff --git a/queries/admin/user.ts b/queries/admin/user.ts index 98eadc1b..e03974f2 100644 --- a/queries/admin/user.ts +++ b/queries/admin/user.ts @@ -1,5 +1,5 @@ import { Prisma } from '@prisma/client'; -import { UmamiApi } from 'interface/enum'; +import { UmamiApi } from 'lib/enum'; import cache from 'lib/cache'; import prisma from 'lib/prisma'; @@ -82,22 +82,16 @@ export async function updateUser( data: Prisma.UserUpdateInput, where: Prisma.UserWhereUniqueInput, ): Promise { - return prisma.client.user - .update({ - where, - data, - select: { - id: true, - username: true, - createdAt: true, - userRole: true, - }, - }) - .then(user => { - const { userRole, ...rest } = user; - - return { ...rest, isAdmin: userRole.some(a => a.roleId === UmamiApi.SystemRole.Admin) }; - }); + return prisma.client.user.update({ + where, + data, + select: { + id: true, + username: true, + createdAt: true, + userRole: true, + }, + }); } export async function deleteUser( diff --git a/queries/analytics/event/getEventData.ts b/queries/analytics/event/getEventData.ts index 2e776f52..3c6bd460 100644 --- a/queries/analytics/event/getEventData.ts +++ b/queries/analytics/event/getEventData.ts @@ -3,7 +3,7 @@ import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db'; import prisma from 'lib/prisma'; import cache from 'lib/cache'; import { WebsiteMetric } from 'interface/api/models'; -import { UmamiApi } from 'interface/enum'; +import { UmamiApi } from 'lib/enum'; export async function getEventData( ...args: [ diff --git a/queries/analytics/event/getEventMetrics.ts b/queries/analytics/event/getEventMetrics.ts index c2e819c4..96843dce 100644 --- a/queries/analytics/event/getEventMetrics.ts +++ b/queries/analytics/event/getEventMetrics.ts @@ -3,7 +3,7 @@ import clickhouse from 'lib/clickhouse'; import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db'; import cache from 'lib/cache'; import { WebsiteEventMetric } from 'interface/api/models'; -import { UmamiApi } from 'interface/enum'; +import { UmamiApi } from 'lib/enum'; export async function getEventMetrics( ...args: [ diff --git a/queries/analytics/event/saveEvent.ts b/queries/analytics/event/saveEvent.ts index 6bb44ef5..02a349e3 100644 --- a/queries/analytics/event/saveEvent.ts +++ b/queries/analytics/event/saveEvent.ts @@ -4,7 +4,7 @@ import kafka from 'lib/kafka'; import prisma from 'lib/prisma'; import { uuid } from 'lib/crypto'; import cache from 'lib/cache'; -import { UmamiApi } from 'interface/enum'; +import { UmamiApi } from 'lib/enum'; export async function saveEvent(args: { id: string; diff --git a/queries/analytics/pageview/getPageviewMetrics.ts b/queries/analytics/pageview/getPageviewMetrics.ts index 106d14a9..de8fe448 100644 --- a/queries/analytics/pageview/getPageviewMetrics.ts +++ b/queries/analytics/pageview/getPageviewMetrics.ts @@ -3,7 +3,7 @@ import clickhouse from 'lib/clickhouse'; import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db'; import cache from 'lib/cache'; import { Prisma } from '@prisma/client'; -import { UmamiApi } from 'interface/enum'; +import { UmamiApi } from 'lib/enum'; export async function getPageviewMetrics( ...args: [ diff --git a/queries/analytics/pageview/getPageviewStats.ts b/queries/analytics/pageview/getPageviewStats.ts index 4a7a7782..f9cda5fe 100644 --- a/queries/analytics/pageview/getPageviewStats.ts +++ b/queries/analytics/pageview/getPageviewStats.ts @@ -2,7 +2,7 @@ import cache from 'lib/cache'; import clickhouse from 'lib/clickhouse'; import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db'; import prisma from 'lib/prisma'; -import { UmamiApi } from 'interface/enum'; +import { UmamiApi } from 'lib/enum'; export async function getPageviewStats( ...args: [ diff --git a/queries/analytics/pageview/savePageView.ts b/queries/analytics/pageview/savePageView.ts index 134dfd09..793a8cd4 100644 --- a/queries/analytics/pageview/savePageView.ts +++ b/queries/analytics/pageview/savePageView.ts @@ -4,7 +4,7 @@ import kafka from 'lib/kafka'; import prisma from 'lib/prisma'; import cache from 'lib/cache'; import { uuid } from 'lib/crypto'; -import { UmamiApi } from 'interface/enum'; +import { UmamiApi } from 'lib/enum'; export async function savePageView(args: { id: string;