-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi-access.service.ts
More file actions
27 lines (21 loc) · 910 Bytes
/
api-access.service.ts
File metadata and controls
27 lines (21 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import type { ProjectId } from '../project/project'
import { type ApiAccess, type ApiAccessId, type ApiKey, apiAccessSchema } from './api-access'
import {
createApiAccess,
getApiAccessForProject,
projectHasKey,
setApiAccessName
} from './api-access.repository'
export const checkApiKeyAccess = async (apiKey: ApiKey, projectId: ProjectId): Promise<boolean> =>
projectHasKey(projectId, apiKey)
export const addApiAccess = async (projectId: ProjectId): Promise<ApiAccess> => {
const key = await createApiAccess(projectId)
return apiAccessSchema.parse(key)
}
export const changeApiAccessName = async (apiAccessId: ApiAccessId, name: string) => {
await setApiAccessName(apiAccessId, name)
}
export const listApiAccessForProject = async (projectId: ProjectId): Promise<ApiAccess[]> => {
const queryResult = await getApiAccessForProject(projectId)
return apiAccessSchema.array().parse(queryResult)
}