Skip to content

Commit

Permalink
feat: remaining changes 139
Browse files Browse the repository at this point in the history
Signed-off-by: Sujith <[email protected]>
  • Loading branch information
sujithvn committed Feb 7, 2023
1 parent f7c2834 commit 0fb7781
Show file tree
Hide file tree
Showing 139 changed files with 410 additions and 248 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js";
import { decodeAccountOpaqueId } from "../../xforms/id.js";

/**
Expand All @@ -15,7 +16,7 @@ import { decodeAccountOpaqueId } from "../../xforms/id.js";
*/
export default async function addAccountAddressBookEntry(parentResult, { input }, context) {
const { accountId, address, clientMutationId = null } = input;
const dbAccountId = decodeAccountOpaqueId(accountId);
const dbAccountId = isOpaqueId(accountId) ? decodeAccountOpaqueId(accountId) : accountId;
const updatedAddress = await context.mutations.addressBookAdd(context, address, dbAccountId);
return {
address: updatedAddress,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js";
import { decodeAccountOpaqueId } from "../../xforms/id.js";

/**
Expand All @@ -15,7 +16,7 @@ import { decodeAccountOpaqueId } from "../../xforms/id.js";
*/
export default async function addAccountEmailRecord(_, { input }, context) {
const { accountId, email, clientMutationId = null } = input;
const decodedAccountId = decodeAccountOpaqueId(accountId);
const decodedAccountId = isOpaqueId(accountId) ? decodeAccountOpaqueId(accountId) : accountId;

const updatedAccount = await context.mutations.addAccountEmailRecord(context, {
accountId: decodedAccountId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js";
import { decodeAccountOpaqueId, decodeGroupOpaqueId } from "../../xforms/id.js";

/**
Expand All @@ -16,8 +17,8 @@ import { decodeAccountOpaqueId, decodeGroupOpaqueId } from "../../xforms/id.js";
export default async function addAccountToGroup(parentResult, { input }, context) {
const { accountId: opaqueAccountId, groupId: opaqueGroupId, clientMutationId = null } = input;

const accountId = decodeAccountOpaqueId(opaqueAccountId);
const groupId = decodeGroupOpaqueId(opaqueGroupId);
const accountId = isOpaqueId(opaqueAccountId) ? decodeAccountOpaqueId(opaqueAccountId) : opaqueAccountId;
const groupId = isOpaqueId(opaqueGroupId) ? decodeGroupOpaqueId(opaqueGroupId) : opaqueGroupId;

const group = await context.mutations.addAccountToGroup(context, {
accountId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js";
import { decodeShopOpaqueId } from "../../xforms/id.js";

/**
Expand All @@ -14,7 +15,7 @@ import { decodeShopOpaqueId } from "../../xforms/id.js";
*/
export default async function createAccount(_, { input }, context) {
const { shopId, clientMutationId } = input;
const decodedShopId = decodeShopOpaqueId(shopId);
const decodedShopId = isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId;

const transformedInput = { ...input, shopId: decodedShopId };

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js";
import { decodeShopOpaqueId } from "../../xforms/id.js";

/**
Expand All @@ -19,8 +20,7 @@ import { decodeShopOpaqueId } from "../../xforms/id.js";
*/
export default async function createAccountGroup(_, { input }, context) {
const { shopId } = input;
const decodedShopId = decodeShopOpaqueId(shopId);

const decodedShopId = isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId;
const transformedInput = { ...input, shopId: decodedShopId };

return context.mutations.createAccountGroup(context, transformedInput);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js";
import { decodeAccountOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js";

/**
Expand All @@ -18,8 +19,8 @@ export default async function grantAdminUIAccess(parentResult, { input = {} }, c
shopId: opaqueShopId
} = input;

const accountId = decodeAccountOpaqueId(opaqueAccountId);
const shopId = decodeShopOpaqueId(opaqueShopId);
const accountId = isOpaqueId(opaqueAccountId) ? decodeAccountOpaqueId(opaqueAccountId) : opaqueAccountId;
const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId;

const account = await context.mutations.grantAdminUIAccess(context, { accountId, shopId });

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ReactionError from "@reactioncommerce/reaction-error";
import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js";
import { decodeGroupOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js";

/**
Expand Down Expand Up @@ -32,9 +33,8 @@ export default async function inviteShopMember(_, { input }, context) {
groupIds = [groupId];
}

const decodedGroupIds = groupIds.map((encodedGroupId) => decodeGroupOpaqueId(encodedGroupId));
const decodedShopId = decodeShopOpaqueId(shopId);

const decodedGroupIds = groupIds.map((encodedGroupId) => (isOpaqueId(encodedGroupId) ? decodeGroupOpaqueId(encodedGroupId) : encodedGroupId));
const decodedShopId = isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId;
const account = await context.mutations.inviteShopMember(context, {
email,
groupIds: decodedGroupIds,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js";
import { decodeAccountOpaqueId, decodeAddressOpaqueId } from "../../xforms/id.js";

/**
Expand All @@ -15,8 +16,8 @@ import { decodeAccountOpaqueId, decodeAddressOpaqueId } from "../../xforms/id.js
*/
export default async function removeAccountAddressBookEntry(_, { input }, context) {
const { accountId, addressId, clientMutationId = null } = input;
const decodedAccountId = decodeAccountOpaqueId(accountId);
const decodedAddressId = decodeAddressOpaqueId(addressId);
const decodedAccountId = isOpaqueId(accountId) ? decodeAccountOpaqueId(accountId) : accountId;
const decodedAddressId = isOpaqueId(addressId) ? decodeAddressOpaqueId(addressId) : addressId;

const removedAddress = await context.mutations.removeAccountAddressBookEntry(context, {
addressId: decodedAddressId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js";
import { decodeAccountOpaqueId } from "../../xforms/id.js";

/**
Expand All @@ -15,7 +16,7 @@ import { decodeAccountOpaqueId } from "../../xforms/id.js";
*/
export default async function removeAccountEmailRecord(_, { input }, context) {
const { accountId, email, clientMutationId = null } = input;
const decodedAccountId = decodeAccountOpaqueId(accountId);
const decodedAccountId = isOpaqueId(accountId) ? decodeAccountOpaqueId(accountId) : accountId;

const updatedAccount = await context.mutations.removeAccountEmailRecord(context, {
accountId: decodedAccountId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js";
import { decodeAccountOpaqueId, decodeGroupOpaqueId } from "../../xforms/id.js";

/**
Expand All @@ -16,8 +17,8 @@ import { decodeAccountOpaqueId, decodeGroupOpaqueId } from "../../xforms/id.js";
export default async function removeAccountFromGroup(parentResult, { input }, context) {
const { accountId: opaqueAccountId, groupId: opaqueGroupId, clientMutationId = null } = input;

const accountId = decodeAccountOpaqueId(opaqueAccountId);
const groupId = decodeGroupOpaqueId(opaqueGroupId);
const accountId = isOpaqueId(opaqueAccountId) ? decodeAccountOpaqueId(opaqueAccountId) : opaqueAccountId;
const groupId = isOpaqueId(opaqueGroupId) ? decodeGroupOpaqueId(opaqueGroupId) : opaqueGroupId;

const group = await context.mutations.removeAccountFromGroup(context, {
accountId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js";
import { decodeGroupOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js";

/**
Expand All @@ -15,8 +16,8 @@ import { decodeGroupOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js";
export default async function removeAccountGroup(_, { input }, context) {
const { groupId, shopId, clientMutationId } = input;

const decodedGroupId = decodeGroupOpaqueId(groupId);
const decodedShopId = decodeShopOpaqueId(shopId);
const decodedGroupId = isOpaqueId(groupId) ? decodeGroupOpaqueId(groupId) : groupId;
const decodedShopId = isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId;

const group = context.mutations.removeAccountGroup(context, {
groupId: decodedGroupId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js";
import { decodeAccountOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js";

/**
Expand All @@ -18,8 +19,8 @@ export default async function revokeAdminUIAccess(parentResult, { input = {} },
shopId: opaqueShopId
} = input;

const accountId = decodeAccountOpaqueId(opaqueAccountId);
const shopId = decodeShopOpaqueId(opaqueShopId);
const accountId = isOpaqueId(opaqueAccountId) ? decodeAccountOpaqueId(opaqueAccountId) : opaqueAccountId;
const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId;

const account = await context.mutations.revokeAdminUIAccess(context, { accountId, shopId });

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js";
import { decodeAccountOpaqueId } from "../../xforms/id.js";

/**
Expand All @@ -15,7 +16,7 @@ import { decodeAccountOpaqueId } from "../../xforms/id.js";
*/
export default async function setAccountDefaultEmail(_, { input }, context) {
const { accountId, email, clientMutationId = null } = input;
const decodedAccountId = decodeAccountOpaqueId(accountId);
const decodedAccountId = isOpaqueId(accountId) ? decodeAccountOpaqueId(accountId) : accountId;

const updatedAccount = await context.mutations.setAccountDefaultEmail(context, {
accountId: decodedAccountId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js";
import { decodeAccountOpaqueId } from "../../xforms/id.js";

/**
Expand All @@ -19,7 +20,7 @@ import { decodeAccountOpaqueId } from "../../xforms/id.js";
*/
export default async function updateAccount(_, { input }, context) {
const { accountId, clientMutationId = null, ...otherInput } = input;
const decodedAccountId = decodeAccountOpaqueId(accountId);
const decodedAccountId = isOpaqueId(accountId) ? decodeAccountOpaqueId(accountId) : accountId;

const updatedAccount = await context.mutations.updateAccount(context, {
...otherInput,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js";
import { assocAddressInternalId, decodeAccountOpaqueId } from "../../xforms/id.js";

/**
Expand All @@ -17,7 +18,7 @@ import { assocAddressInternalId, decodeAccountOpaqueId } from "../../xforms/id.j
*/
export default async function updateAccountAddressBookEntry(_, { input }, context) {
const { accountId, addressId, clientMutationId, type, updates } = input;
const decodedAccountId = decodeAccountOpaqueId(accountId);
const decodedAccountId = isOpaqueId(accountId) ? decodeAccountOpaqueId(accountId) : accountId;
const address = assocAddressInternalId({ ...updates, _id: addressId });

const updatedAddress = await context.mutations.updateAccountAddressBookEntry(context, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js";
import { decodeGroupOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js";

/**
Expand All @@ -19,8 +20,8 @@ import { decodeGroupOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js";
export default async function updateAccountGroup(_, { input }, context) {
const { groupId, shopId, clientMutationId } = input;

const decodedGroupId = decodeGroupOpaqueId(groupId);
const decodedShopId = decodeShopOpaqueId(shopId);
const decodedGroupId = isOpaqueId(groupId) ? decodeGroupOpaqueId(groupId) : groupId;
const decodedShopId = isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId;

const group = context.mutations.updateAccountGroup(context, {
...input,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js";
import { decodeAccountOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js";

/**
Expand All @@ -18,8 +19,8 @@ export default async function updateAdminUIAccess(parentResult, { input = {} },
shopIds: opaqueShopIds
} = input;

const accountIds = opaqueAccountIds.map((opaqueAccountId) => decodeAccountOpaqueId(opaqueAccountId));
const shopIds = opaqueShopIds.map((opaqueShopId) => decodeShopOpaqueId(opaqueShopId));
const accountIds = opaqueAccountIds.map((opaqueAccountId) => (isOpaqueId(opaqueAccountId) ? decodeAccountOpaqueId(opaqueAccountId) : opaqueAccountId));
const shopIds = opaqueShopIds.map((opaqueShopId) => (isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId));

const accounts = await context.mutations.updateAdminUIAccess(context, { accountIds, shopIds });

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js";
import { decodeAccountOpaqueId, decodeGroupOpaqueId } from "../../xforms/id.js";

/**
Expand All @@ -16,8 +17,8 @@ import { decodeAccountOpaqueId, decodeGroupOpaqueId } from "../../xforms/id.js";
export default async function updateGroupsForAccounts(parentResult, { input }, context) {
const { accountIds: opaqueAccountIds, groupIds: opaqueGroupIds, clientMutationId = null } = input;

const accountIds = opaqueAccountIds.map((id) => decodeAccountOpaqueId(id));
const groupIds = opaqueGroupIds.map((id) => decodeGroupOpaqueId(id));
const accountIds = opaqueAccountIds.map((id) => (isOpaqueId(id) ? decodeAccountOpaqueId(id) : id));
const groupIds = opaqueGroupIds.map((id) => (isOpaqueId(id) ? decodeGroupOpaqueId(id) : id));

const accounts = await context.mutations.updateGroupsForAccounts(context, {
accountIds,
Expand Down
3 changes: 2 additions & 1 deletion packages/api-plugin-accounts/src/resolvers/Query/account.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js";
import { decodeAccountOpaqueId } from "../../xforms/id.js";

/**
Expand All @@ -12,6 +13,6 @@ import { decodeAccountOpaqueId } from "../../xforms/id.js";
* @returns {Promise<Object>} user account object
*/
export default function account(_, { id }, context) {
const dbAccountId = decodeAccountOpaqueId(id);
const dbAccountId = isOpaqueId(id) ? decodeAccountOpaqueId(id) : id;
return context.queries.userAccount(context, dbAccountId);
}
3 changes: 2 additions & 1 deletion packages/api-plugin-accounts/src/resolvers/Query/accounts.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import getPaginatedResponse from "@reactioncommerce/api-utils/graphql/getPaginatedResponse.js";
import wasFieldRequested from "@reactioncommerce/api-utils/graphql/wasFieldRequested.js";
import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js";
import { decodeGroupOpaqueId } from "../../xforms/id.js";

/**
Expand All @@ -20,7 +21,7 @@ export default async function accounts(_, args, context, info) {

let groupIds;
if (opaqueGroupIds) {
groupIds = opaqueGroupIds.map((opaqueGroupId) => decodeGroupOpaqueId(opaqueGroupId));
groupIds = opaqueGroupIds.map((opaqueGroupId) => (isOpaqueId(opaqueGroupId) ? decodeGroupOpaqueId(opaqueGroupId) : opaqueGroupId));
}

const query = await context.queries.accounts(context, { groupIds, notInAnyGroups });
Expand Down
3 changes: 2 additions & 1 deletion packages/api-plugin-accounts/src/resolvers/Query/group.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js";
import { decodeGroupOpaqueId } from "../../xforms/id.js";

/**
Expand All @@ -12,6 +13,6 @@ import { decodeGroupOpaqueId } from "../../xforms/id.js";
* @returns {Promise<Object>} group object
*/
export default async function group(_, { id }, context) {
const dbGroupId = decodeGroupOpaqueId(id);
const dbGroupId = isOpaqueId(id) ? decodeGroupOpaqueId(id) : id;
return context.queries.group(context, dbGroupId);
}
3 changes: 2 additions & 1 deletion packages/api-plugin-accounts/src/resolvers/Query/groups.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import getPaginatedResponse from "@reactioncommerce/api-utils/graphql/getPaginatedResponse.js";
import wasFieldRequested from "@reactioncommerce/api-utils/graphql/wasFieldRequested.js";
import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js";
import { decodeShopOpaqueId } from "../../xforms/id.js";

/**
Expand All @@ -24,7 +25,7 @@ import { decodeShopOpaqueId } from "../../xforms/id.js";
*/
export default async function groups(_, { shopId, ...connectionArgs }, context, info) {
// Transform ID from base64
const dbShopId = decodeShopOpaqueId(shopId);
const dbShopId = isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId;

const query = await context.queries.groups(context, dbShopId);
return getPaginatedResponse(query, connectionArgs, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import getPaginatedResponse from "@reactioncommerce/api-utils/graphql/getPaginatedResponse.js";
import wasFieldRequested from "@reactioncommerce/api-utils/graphql/wasFieldRequested.js";
import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js";
import { decodeShopOpaqueId } from "../../xforms/id.js";

/**
Expand All @@ -20,7 +21,7 @@ export default async function invitations(_, args, context, info) {
let shopIds;

if (Array.isArray(encodedShopIds) && encodedShopIds.length > 0) {
shopIds = encodedShopIds.map((shopId) => decodeShopOpaqueId(shopId));
shopIds = encodedShopIds.map((shopId) => (isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId));
}

const query = await context.queries.invitations(context, { shopIds });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js";
import { decodeShopOpaqueId } from "../../xforms/id.js";

/**
Expand All @@ -18,7 +19,7 @@ export default async function createAddressValidationRule(parentResult, { input
...otherInput
} = input;

const shopId = decodeShopOpaqueId(opaqueShopId);
const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId;

const addressValidationRule = await context.mutations.createAddressValidationRule(context, {
...otherInput,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js";
import { decodeAddressValidationRuleOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js";

/**
Expand All @@ -18,8 +19,8 @@ export default async function deleteAddressValidationRule(parentResult, { input
shopId: opaqueShopId
} = input;

const _id = decodeAddressValidationRuleOpaqueId(opaqueRuleId);
const shopId = decodeShopOpaqueId(opaqueShopId);
const _id = isOpaqueId(opaqueRuleId) ? decodeAddressValidationRuleOpaqueId(opaqueRuleId) : opaqueRuleId;
const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId;

const addressValidationRule = await context.mutations.deleteAddressValidationRule(context, {
_id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js";
import { decodeAddressValidationRuleOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js";

/**
Expand All @@ -19,8 +20,8 @@ export default async function updateAddressValidationRule(parentResult, { input
...otherInput
} = input;

const _id = decodeAddressValidationRuleOpaqueId(opaqueRuleId);
const shopId = decodeShopOpaqueId(opaqueShopId);
const _id = isOpaqueId(opaqueRuleId) ? decodeAddressValidationRuleOpaqueId(opaqueRuleId) : opaqueRuleId;
const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId;

const addressValidationRule = await context.mutations.updateAddressValidationRule(context, {
...otherInput,
Expand Down
Loading

0 comments on commit 0fb7781

Please sign in to comment.