Merge pull request #2932 from specklesystems/fabians/accessreq-ioc-3

chore(server): accessrequests IoC 3 - deleteRequestByIdFactory
This commit is contained in:
Alessandro Magionami
2024-09-11 09:56:46 +02:00
committed by GitHub
4 changed files with 17 additions and 15 deletions
@@ -96,16 +96,18 @@ export const getPendingAccessRequestFactory =
return await q
}
export async function deleteRequestById(requestId: string) {
if (!requestId) {
throw new InvalidArgumentError('Request ID missing')
}
export const deleteRequestByIdFactory =
(deps: { db: Knex }) => async (requestId: string) => {
if (!requestId) {
throw new InvalidArgumentError('Request ID missing')
}
const q = await ServerAccessRequests.knex()
.where(ServerAccessRequests.col.id, requestId)
.del()
return !!q
}
const q = await tables
.serverAccessRequests(deps.db)
.where(ServerAccessRequests.col.id, requestId)
.del()
return !!q
}
type AccessRecordInput<
T extends AccessRequestType = AccessRequestType,
@@ -7,7 +7,7 @@ import { StreamAccessRequestGraphQLReturn } from '@/modules/accessrequests/helpe
import {
AccessRequestType,
createNewRequest,
deleteRequestById,
deleteRequestByIdFactory,
generateId,
getPendingAccessRequestFactory,
getPendingAccessRequestsFactory,
@@ -178,7 +178,7 @@ export async function processPendingStreamRequest(
)
}
await deleteRequestById(req.id)
await deleteRequestByIdFactory({ db })(req.id)
await AccessRequestsEmitter.emit(AccessRequestsEmitter.events.Finalized, {
request: req,
@@ -1,6 +1,6 @@
import { db } from '@/db/knex'
import {
deleteRequestById,
deleteRequestByIdFactory,
getPendingAccessRequestFactory
} from '@/modules/accessrequests/repositories'
import { requestProjectAccess } from '@/modules/accessrequests/services/stream'
@@ -271,7 +271,7 @@ describe('Project access requests', () => {
})
it('returns null if no req found', async () => {
await deleteRequestById(myRequestId)
await deleteRequestByIdFactory({ db })(myRequestId)
const results = await getActiveUserReq(otherGuysPrivateStream.id)
expect(results).to.not.haveGraphQLErrors()
@@ -1,7 +1,7 @@
import { buildApolloServer } from '@/app'
import { db } from '@/db/knex'
import {
deleteRequestById,
deleteRequestByIdFactory,
getPendingAccessRequestFactory
} from '@/modules/accessrequests/repositories'
import { requestStreamAccess } from '@/modules/accessrequests/services/stream'
@@ -249,7 +249,7 @@ describe('Stream access requests', () => {
})
it('returns null if no req found', async () => {
await deleteRequestById(myRequestId)
await deleteRequestByIdFactory({ db })(myRequestId)
const results = await getReq(otherGuysPrivateStream.id)
expect(results).to.not.haveGraphQLErrors()