@greatapps/common 1.1.661 → 1.1.662
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/infra/route/parse-numeric.ts +16 -0
- package/src/modules/projects/handlers/list-all-account-users.handler.ts +7 -1
- package/src/modules/projects/handlers/list-available-users.handler.ts +7 -1
- package/src/modules/projects/handlers/list-project-users.handler.ts +7 -1
- package/src/modules/projects/handlers/list-projects.handler.ts +7 -1
- package/src/modules/users/hooks/messages.hook.ts +3 -3
- package/src/modules/users/schema/messages.schema.ts +2 -0
- package/src/route.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@greatapps/common",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.662",
|
|
4
4
|
"description": "Shared library for GreatApps frontend applications",
|
|
5
5
|
"main": "./dist/index.mjs",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"@hookform/resolvers": "^5.2.2",
|
|
80
|
-
"zod": "^4.3
|
|
80
|
+
"zod": "^4.4.3",
|
|
81
81
|
"@tanstack/react-query": "^5.95.2",
|
|
82
82
|
"@tanstack/react-query-devtools": "^5.95.2",
|
|
83
83
|
"@types/node": "^25.5.0",
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function parseNumericFields<T extends object>(
|
|
2
|
+
params: Partial<T>,
|
|
3
|
+
fields: readonly (keyof T)[]
|
|
4
|
+
): Partial<T> {
|
|
5
|
+
const result: Partial<T> = { ...params };
|
|
6
|
+
for (const field of fields) {
|
|
7
|
+
const v = result[field] as unknown;
|
|
8
|
+
if (typeof v === 'string' && v !== '') {
|
|
9
|
+
const n = Number(v);
|
|
10
|
+
if (Number.isFinite(n)) {
|
|
11
|
+
result[field] = n as T[keyof T];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import 'server-only';
|
|
2
2
|
|
|
3
3
|
import type { NextRequest } from 'next/server';
|
|
4
|
+
import { parseNumericFields } from '../../../infra/route/parse-numeric';
|
|
4
5
|
import { safeRouteHandler } from '../../../infra/route/safe-route-handler';
|
|
5
6
|
import { searchParamsToParams } from '../../../infra/route/search-params';
|
|
6
7
|
import { projectUsersService } from '../services/project-users.service';
|
|
7
8
|
import type { ListUsersParams } from '../types';
|
|
8
9
|
|
|
10
|
+
const NUMERIC_FIELDS = ['page', 'limit'] as const;
|
|
11
|
+
|
|
9
12
|
export function createListAllAccountUsersHandler() {
|
|
10
13
|
return async function GET(req: NextRequest) {
|
|
11
14
|
return safeRouteHandler(() =>
|
|
12
15
|
projectUsersService.listAllAccountUsers(
|
|
13
|
-
|
|
16
|
+
parseNumericFields<ListUsersParams>(
|
|
17
|
+
searchParamsToParams<ListUsersParams>(req.nextUrl.searchParams),
|
|
18
|
+
NUMERIC_FIELDS
|
|
19
|
+
)
|
|
14
20
|
)
|
|
15
21
|
);
|
|
16
22
|
};
|
|
@@ -2,18 +2,24 @@ import 'server-only';
|
|
|
2
2
|
|
|
3
3
|
import type { NextRequest } from 'next/server';
|
|
4
4
|
import { parseId } from '../../../infra/route/parse-id';
|
|
5
|
+
import { parseNumericFields } from '../../../infra/route/parse-numeric';
|
|
5
6
|
import { safeRouteHandler } from '../../../infra/route/safe-route-handler';
|
|
6
7
|
import { searchParamsToParams } from '../../../infra/route/search-params';
|
|
7
8
|
import { projectUsersService } from '../services/project-users.service';
|
|
8
9
|
import type { ListUsersParams } from '../types';
|
|
9
10
|
|
|
11
|
+
const NUMERIC_FIELDS = ['page', 'limit'] as const;
|
|
12
|
+
|
|
10
13
|
export function createListAvailableUsersHandler() {
|
|
11
14
|
return async function GET(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
|
12
15
|
return safeRouteHandler(async () => {
|
|
13
16
|
const { id } = await params;
|
|
14
17
|
return projectUsersService.listNotInProject(
|
|
15
18
|
parseId(id),
|
|
16
|
-
|
|
19
|
+
parseNumericFields<ListUsersParams>(
|
|
20
|
+
searchParamsToParams<ListUsersParams>(req.nextUrl.searchParams),
|
|
21
|
+
NUMERIC_FIELDS
|
|
22
|
+
)
|
|
17
23
|
);
|
|
18
24
|
});
|
|
19
25
|
};
|
|
@@ -2,18 +2,24 @@ import 'server-only';
|
|
|
2
2
|
|
|
3
3
|
import type { NextRequest } from 'next/server';
|
|
4
4
|
import { parseId } from '../../../infra/route/parse-id';
|
|
5
|
+
import { parseNumericFields } from '../../../infra/route/parse-numeric';
|
|
5
6
|
import { safeRouteHandler } from '../../../infra/route/safe-route-handler';
|
|
6
7
|
import { searchParamsToParams } from '../../../infra/route/search-params';
|
|
7
8
|
import { projectUsersService } from '../services/project-users.service';
|
|
8
9
|
import type { ListUsersParams } from '../types';
|
|
9
10
|
|
|
11
|
+
const NUMERIC_FIELDS = ['page', 'limit'] as const;
|
|
12
|
+
|
|
10
13
|
export function createListProjectUsersHandler() {
|
|
11
14
|
return async function GET(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
|
12
15
|
return safeRouteHandler(async () => {
|
|
13
16
|
const { id } = await params;
|
|
14
17
|
return projectUsersService.listInProject(
|
|
15
18
|
parseId(id),
|
|
16
|
-
|
|
19
|
+
parseNumericFields<ListUsersParams>(
|
|
20
|
+
searchParamsToParams<ListUsersParams>(req.nextUrl.searchParams),
|
|
21
|
+
NUMERIC_FIELDS
|
|
22
|
+
)
|
|
17
23
|
);
|
|
18
24
|
});
|
|
19
25
|
};
|
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import 'server-only';
|
|
2
2
|
|
|
3
3
|
import type { NextRequest } from 'next/server';
|
|
4
|
+
import { parseNumericFields } from '../../../infra/route/parse-numeric';
|
|
4
5
|
import { safeRouteHandler } from '../../../infra/route/safe-route-handler';
|
|
5
6
|
import { searchParamsToParams } from '../../../infra/route/search-params';
|
|
6
7
|
import { projectsService } from '../services/projects.service';
|
|
7
8
|
import type { ListProjectsActionParams } from '../actions/list-projects.action';
|
|
8
9
|
|
|
10
|
+
const NUMERIC_FIELDS = ['page', 'limit', 'deleted'] as const;
|
|
11
|
+
|
|
9
12
|
export function createListProjectsHandler() {
|
|
10
13
|
return async function GET(req: NextRequest) {
|
|
11
14
|
return safeRouteHandler(() =>
|
|
12
15
|
projectsService.list(
|
|
13
|
-
|
|
16
|
+
parseNumericFields<ListProjectsActionParams>(
|
|
17
|
+
searchParamsToParams<ListProjectsActionParams>(req.nextUrl.searchParams),
|
|
18
|
+
NUMERIC_FIELDS
|
|
19
|
+
)
|
|
14
20
|
)
|
|
15
21
|
);
|
|
16
22
|
};
|
|
@@ -5,7 +5,7 @@ import { apiFetch } from '../../../infra/http/api-fetch';
|
|
|
5
5
|
import { markMessageAsReadAction } from '../action/mark-message-as-read.action';
|
|
6
6
|
import { markAllMessagesAsReadAction } from '../action/mark-all-messages-as-read.action';
|
|
7
7
|
import { withAction } from '../../../utils/withAction';
|
|
8
|
-
import type { FindMessagesParams,
|
|
8
|
+
import type { FindMessagesParams, ListMessagesResult } from '../schema/messages.schema';
|
|
9
9
|
import { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';
|
|
10
10
|
|
|
11
11
|
export const MESSAGES_QUERY_KEY = ['messages'] as const;
|
|
@@ -18,7 +18,7 @@ export function useMessages(params?: Partial<FindMessagesParams>) {
|
|
|
18
18
|
return useQuery({
|
|
19
19
|
queryKey,
|
|
20
20
|
queryFn: ({ signal }) =>
|
|
21
|
-
apiFetch<
|
|
21
|
+
apiFetch<ListMessagesResult>('/api/messages', { params, signal }),
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -28,7 +28,7 @@ export function useInfiniteMessages(params?: Partial<Omit<FindMessagesParams, 'p
|
|
|
28
28
|
return useInfiniteQuery({
|
|
29
29
|
queryKey,
|
|
30
30
|
queryFn: ({ pageParam, signal }) =>
|
|
31
|
-
apiFetch<
|
|
31
|
+
apiFetch<ListMessagesResult>('/api/messages', {
|
|
32
32
|
params: {
|
|
33
33
|
...params,
|
|
34
34
|
page: pageParam as number,
|
package/src/route.ts
CHANGED