-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MC-1618: adding corpus admin query getSectionsWithSectionItems
- Loading branch information
1 parent
b290d41
commit 318d9bc
Showing
8 changed files
with
96 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 5 additions & 7 deletions
12
servers/curated-corpus-api/src/admin/resolvers/queries/Section/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,29 @@ | ||
import { AuthenticationError } from '@pocket-tools/apollo-utils'; | ||
|
||
import { | ||
getSectionWithSectionItems as dbGetSectionWithSectionItems | ||
getSectionsWithSectionItems as dbGetSectionsWithSectionItems | ||
} from '../../../../database/queries'; | ||
import { Section } from '../../../../database/types'; | ||
import { ACCESS_DENIED_ERROR } from '../../../../shared/types'; | ||
import { IAdminContext } from '../../../context'; | ||
|
||
/** | ||
* Retrieve a Section with its SectionItems. Returns null if the Section | ||
* externalId is not found. | ||
* Retrieve all Sections with their SectionItems. Returns empty array if no Sections found. | ||
* | ||
* @param parent | ||
* @param externalId | ||
* @param context | ||
*/ | ||
export async function getSectionWithSectionItems( | ||
export async function getSectionsWithSectionItems( | ||
parent, | ||
args, | ||
context: IAdminContext, | ||
): Promise<Section | null> { | ||
): Promise<Section[]> { | ||
// Check if the user does not have the permissions to access this query | ||
if ( | ||
!context.authenticatedUser.hasReadOnly && | ||
!context.authenticatedUser.canWriteToCorpus() | ||
) { | ||
throw new AuthenticationError(ACCESS_DENIED_ERROR); | ||
} | ||
return await dbGetSectionWithSectionItems(context.db, args.externalId); | ||
return await dbGetSectionsWithSectionItems(context.db); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters