Merge pull request #2933 from specklesystems/fabians/accessreq-ioc-4
chore(server): accessrequests IoC 4 - createNewRequestFactory
This commit is contained in:
@@ -114,17 +114,23 @@ type AccessRecordInput<
|
||||
I extends Nullable<string> = Nullable<string>
|
||||
> = Omit<ServerAccessRequestRecord<T, I>, 'createdAt' | 'updatedAt'>
|
||||
|
||||
export async function createNewRequest<
|
||||
T extends AccessRequestType = AccessRequestType,
|
||||
I extends Nullable<string> = Nullable<string>
|
||||
>(input: AccessRecordInput<T, I>) {
|
||||
const results = await ServerAccessRequests.knex().insert<
|
||||
string,
|
||||
ServerAccessRequestRecord<T, I>[]
|
||||
>(input, ServerAccessRequests.cols)
|
||||
export const createNewRequestFactory =
|
||||
(deps: { db: Knex }) =>
|
||||
async <
|
||||
T extends AccessRequestType = AccessRequestType,
|
||||
I extends Nullable<string> = Nullable<string>
|
||||
>(
|
||||
input: AccessRecordInput<T, I>
|
||||
) => {
|
||||
const results = await tables
|
||||
.serverAccessRequests(deps.db)
|
||||
.insert<string, ServerAccessRequestRecord<T, I>[]>(
|
||||
input,
|
||||
ServerAccessRequests.cols
|
||||
)
|
||||
|
||||
return results[0]
|
||||
}
|
||||
return results[0]
|
||||
}
|
||||
|
||||
export async function getUsersPendingAccessRequest<
|
||||
T extends AccessRequestType = AccessRequestType,
|
||||
|
||||
@@ -6,7 +6,7 @@ import { AccessRequestsEmitter } from '@/modules/accessrequests/events/emitter'
|
||||
import { StreamAccessRequestGraphQLReturn } from '@/modules/accessrequests/helpers/graphTypes'
|
||||
import {
|
||||
AccessRequestType,
|
||||
createNewRequest,
|
||||
createNewRequestFactory,
|
||||
deleteRequestByIdFactory,
|
||||
generateId,
|
||||
getPendingAccessRequestFactory,
|
||||
@@ -87,7 +87,7 @@ export async function requestProjectAccess(userId: string, projectId: string) {
|
||||
)
|
||||
}
|
||||
|
||||
const req = await createNewRequest<AccessRequestType.Stream, string>({
|
||||
const req = await createNewRequestFactory({ db })<AccessRequestType.Stream, string>({
|
||||
id: generateId(),
|
||||
requesterId: userId,
|
||||
resourceType: AccessRequestType.Stream,
|
||||
|
||||
Reference in New Issue
Block a user