Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Addresses and Cards by ID #3

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion api/v1/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,14 @@ account.recoverEmail = (schema, req) => {
email: req.body.email
}).then(result => {
if (!result) {
return;
return {
errors: {
email: {
code: 'REQUIRED',
message: 'Invalid email address entered'
}
}
};
}

return schema.put('/accounts/{id}', {
Expand Down Expand Up @@ -360,6 +367,16 @@ account.getAddresses = (schema, req) => {
});
};

//Get account address by ID
account.getAddressById = (schema, req) => {
const query = req.query || {};
return schema.get('/accounts/{id}/addresses/{address_id}', {
id: req.session.account_id,
address_id: req.params.id,
fields: query.fields
});
};

// Remove an account address
account.removeAddress = (schema, req) => {
return schema.put('/accounts/{id}/addresses/{address_id}', {
Expand All @@ -386,6 +403,16 @@ account.getCards = (schema, req) => {
});
};

//Get account card by ID
account.getCardById = (schema, req) => {
const query = req.query || {};
return schema.get('/accounts/{id}/cards/{card_id}', {
id: req.session.account_id,
card_id: req.params.id,
fields: query.fields
});
};

// Remove an account card
account.removeCard = (schema, req) => {
return schema.put('/accounts/{id}/cards/{card_id}', {
Expand Down
8 changes: 4 additions & 4 deletions api/v1/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,10 @@ cart.validateProduct = (schema, data) => {
var productId = product.id;
var variantId = product.variant && product.variant.id;
if (!product.id) {
throw new util.error(400, 'Product not found');
throw util.error(400, 'Product not found');
}
if (product.delivery === 'subscription') {
throw new util.error(400, 'Subscription products cannot be added to a cart');
throw util.error(400, 'Subscription products cannot be added to a cart');
}
if (product.variable && !data.variant_id) {
// Return first variant
Expand All @@ -386,10 +386,10 @@ cart.validateProduct = (schema, data) => {
});
}
if (data.variant_id && !product.variant) {
throw new util.error(400, 'Variant not found for this product (' + product.name + ')');
throw util.error(400, 'Variant not found for this product (' + product.name + ')');
}
if (data.variant_id && !product.variable) {
throw new util.error(400, 'Product is not variable (' + product.name + ')');
throw util.error(400, 'Product is not variable (' + product.name + ')');
}
// Valid
data.product_id = productId;
Expand Down