|
| 1 | +import type { ProjectId } from '../project/project' |
| 2 | +import { apiAccessSchema, type ApiAccess, type ApiAccessId, type ApiKey } from './api-access' |
1 | 3 | import { |
2 | 4 | createApiAccess, |
3 | 5 | getApiAccessForProject, |
4 | 6 | projectHasKey, |
5 | 7 | setApiAccessName |
6 | 8 | } from './api-access.repository' |
7 | 9 |
|
8 | | -export const checkApiKeyAccess = async (apiKey: string, projectId: number): Promise<boolean> => { |
9 | | - return await projectHasKey(projectId, apiKey) |
10 | | -} |
| 10 | +export const checkApiKeyAccess = async (apiKey: ApiKey, projectId: ProjectId): Promise<boolean> => |
| 11 | + projectHasKey(projectId, apiKey) |
11 | 12 |
|
12 | | -export const addApiKey = async (projectId: number): Promise<string> => { |
| 13 | +export const addApiAccess = async (projectId: ProjectId): Promise<ApiAccess> => { |
13 | 14 | const key = await createApiAccess(projectId) |
14 | | - return key.apikey |
| 15 | + return apiAccessSchema.parse(key) |
15 | 16 | } |
16 | 17 |
|
17 | | -export const changeApiKeyName = async (apiAccessId: number, name: string) => { |
| 18 | +export const changeApiAccessName = async (apiAccessId: ApiAccessId, name: string) => { |
18 | 19 | await setApiAccessName(apiAccessId, name) |
19 | 20 | } |
20 | 21 |
|
21 | | -export const listApiKeys = async (projectId: number): Promise<string[]> => { |
22 | | - const result = await getApiAccessForProject(projectId) |
23 | | - return result.map((it) => it.apikey) |
| 22 | +export const listApiAccessForProject = async (projectId: ProjectId): Promise<ApiAccess[]> => { |
| 23 | + const queryResult = await getApiAccessForProject(projectId) |
| 24 | + return apiAccessSchema.array().parse(queryResult) |
24 | 25 | } |
0 commit comments