This repository has been archived by the owner on Sep 21, 2022. It is now read-only.
generated from reactioncommerce/api-plugin-example
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use field resolvers to join invitation data
Signed-off-by: Loan Laux <[email protected]>
- Loading branch information
Showing
7 changed files
with
64 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import ReactionError from "@reactioncommerce/reaction-error"; | ||
|
||
/** | ||
* @name accountByUserId | ||
* @method | ||
* @memberof Accounts/NoMeteorQueries | ||
* @summary query the Accounts collection and return user account data | ||
* @param {Object} context - an object containing the per-request state | ||
* @param {String} id - id of user to query | ||
* @returns {Object} user account object | ||
*/ | ||
export default async function accountByUserIdQuery(context, id) { | ||
const { collections } = context; | ||
const { Accounts } = collections; | ||
|
||
const account = await Accounts.findOne({ userId: id }); | ||
if (!account) throw new ReactionError("not-found", "No account found"); | ||
|
||
// Check to make sure current user has permissions to view queried user | ||
await context.validatePermissions("reaction:legacy:accounts", "read", { | ||
owner: account.userId | ||
}); | ||
|
||
return account; | ||
} |
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 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,12 @@ | ||
/** | ||
* Return group by ID | ||
* @param parent | ||
* @param _ | ||
* @param context | ||
* @returns {Promise<*[]>} | ||
*/ | ||
export default async function groups(parent, _, context) { | ||
const group = await context.queries.group(context, parent.groupId); | ||
|
||
return [group]; | ||
} |
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,11 @@ | ||
import resolveShopFromShopId from "@reactioncommerce/api-utils/graphql/resolveShopFromShopId.js"; | ||
import { encodeInvitationOpaqueId } from "../../xforms/id.js"; | ||
import groups from "./groups.js"; | ||
import invitedBy from "./invitedBy.js"; | ||
|
||
export default { | ||
_id: (node) => encodeInvitationOpaqueId(node._id), | ||
groups, | ||
invitedBy, | ||
shop: resolveShopFromShopId | ||
}; |
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,13 @@ | ||
/** | ||
* Returns the account that sent the invitation | ||
* @param parent | ||
* @param _ | ||
* @param context | ||
* @returns {Promise<Object|null>|null} | ||
*/ | ||
export default function invitedBy(parent, _, context) { | ||
const { invitedByUserId } = parent; | ||
if (!invitedByUserId) return null; | ||
|
||
return context.queries.accountByUserId(context, invitedByUserId); | ||
} |
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