-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
124 additions
and
140 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { MiddlewareFn } from 'type-graphql'; | ||
|
||
import { ResolverContext } from '@typeDefs/resolver'; | ||
import storefront from '@data/course-storefront'; | ||
import { COURSE } from '@data/course-keys-types'; | ||
import { BUNDLE } from '@data/bundle-keys-types'; | ||
|
||
export const isFreeCourse: MiddlewareFn<ResolverContext> = async ( | ||
{ args }, | ||
next | ||
) => { | ||
const course = storefront[args.courseId as COURSE]; | ||
const bundle = course.bundles[args.bundleId as BUNDLE]; | ||
|
||
if (bundle.price !== 0) { | ||
throw new Error('This course is not for free.'); | ||
} | ||
|
||
return next(); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { MiddlewareFn } from 'type-graphql'; | ||
import { ForbiddenError } from 'apollo-server'; | ||
|
||
import { ResolverContext } from '@typeDefs/resolver'; | ||
import { hasPartnerRole } from '@validation/partner'; | ||
|
||
export const isPartner: MiddlewareFn<ResolverContext> = async ( | ||
{ context }, | ||
next | ||
) => { | ||
if (!context.me) { | ||
throw new ForbiddenError('Not authenticated as user.'); | ||
} | ||
|
||
if (!hasPartnerRole(context.me)) { | ||
throw new Error('No partner user.'); | ||
} | ||
|
||
return next(); | ||
}; |
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
Oops, something went wrong.