* added statuses to product + unit test for updating status * add update to product model * added integration tests * added integration test to validate that updating status to null results in invalid_data error * removed comment * update GET /store/products integration test * fixed unit test with IdMap * init plugin * changed dbehaviour on invalid status input on admin list products * mprices * updated migration to add status = published on all existing products + added integration test on GET /admin/products when status null is provided * merged product status * init ShopifyService * made requested changes to migration and GET /store/products * fixed test * made requested changes to migration * push progress on source plugin * add webhook product/create handler * fixed normalization of variant weight * removed weight func * work on events * finished product hooks (error on new variant needs to be fixed) * fixed order status * create fulfillments * update fulfillment on cancel * refactored services, handle returns though medusa, helper methods * order updates * removed dist * update gitignore * emit cahnges to product * added redis ignore check to prevent update loops * fixed product-variant.deleted event * fix more events * fix test * fix: order taxes * added refund with no items * fixes to hooks * fixed handling refunds and returns issued from Shopify * added unit tests to ShopifyProductService and ShopifyCollectionService * linting fix * prepared loader PR * fix: jsDocs * fix: pager * fix: build output and babelrc * chore: linting * fix: address type * fix: migration clean up * fix: update snapshots with ext_ids Co-authored-by: Sebastian Rindom <skrindom@gmail.com>
130 lines
3.2 KiB
JavaScript
130 lines
3.2 KiB
JavaScript
import Joi from "joi"
|
|
|
|
Joi.objectId = require("joi-objectid")(Joi)
|
|
|
|
// if address is a string, we assume that it is an id
|
|
Joi.address = () => {
|
|
return Joi.alternatives().try(
|
|
Joi.string(),
|
|
Joi.object().keys({
|
|
first_name: Joi.string().required(),
|
|
last_name: Joi.string().required(),
|
|
company: Joi.string().optional(),
|
|
address_1: Joi.string().required(),
|
|
address_2: Joi.string()
|
|
.allow(null, "")
|
|
.optional(),
|
|
city: Joi.string().required(),
|
|
country_code: Joi.string().required(),
|
|
province: Joi.string()
|
|
.allow(null, "")
|
|
.optional(),
|
|
postal_code: Joi.string().required(),
|
|
phone: Joi.string().optional(),
|
|
metadata: Joi.object()
|
|
.allow(null, {})
|
|
.optional(),
|
|
})
|
|
)
|
|
}
|
|
|
|
Joi.dateFilter = () => {
|
|
return Joi.object({
|
|
lt: Joi.alternatives(Joi.date().timestamp("unix"), Joi.date()),
|
|
gt: Joi.alternatives(Joi.date().timestamp("unix"), Joi.date()),
|
|
gte: Joi.alternatives(Joi.date().timestamp("unix"), Joi.date()),
|
|
lte: Joi.alternatives(Joi.date().timestamp("unix"), Joi.date()),
|
|
})
|
|
}
|
|
|
|
Joi.orderFilter = () => {
|
|
return Joi.object().keys({
|
|
id: Joi.string(),
|
|
q: Joi.string(),
|
|
status: Joi.array()
|
|
.items(
|
|
Joi.string().valid(
|
|
"pending",
|
|
"completed",
|
|
"archived",
|
|
"canceled",
|
|
"requires_action"
|
|
)
|
|
)
|
|
.single(),
|
|
fulfillment_status: Joi.array()
|
|
.items(
|
|
Joi.string().valid(
|
|
"not_fulfilled",
|
|
"fulfilled",
|
|
"partially_fulfilled",
|
|
"shipped",
|
|
"partially_shipped",
|
|
"canceled",
|
|
"returned",
|
|
"partially_returned",
|
|
"requires_action"
|
|
)
|
|
)
|
|
.single(),
|
|
payment_status: Joi.array()
|
|
.items(
|
|
Joi.string().valid(
|
|
"captured",
|
|
"awaiting",
|
|
"not_paid",
|
|
"refunded",
|
|
"partially_refunded",
|
|
"canceled",
|
|
"requires_action"
|
|
)
|
|
)
|
|
.single(),
|
|
display_id: Joi.string(),
|
|
cart_id: Joi.string(),
|
|
offset: Joi.string(),
|
|
limit: Joi.string(),
|
|
expand: Joi.string(),
|
|
fields: Joi.string(),
|
|
customer_id: Joi.string(),
|
|
email: Joi.string(),
|
|
region_id: Joi.string(),
|
|
currency_code: Joi.string(),
|
|
tax_rate: Joi.string(),
|
|
canceled_at: Joi.dateFilter(),
|
|
created_at: Joi.dateFilter(),
|
|
updated_at: Joi.dateFilter(),
|
|
})
|
|
}
|
|
|
|
Joi.productFilter = () => {
|
|
return Joi.object().keys({
|
|
id: Joi.string(),
|
|
q: Joi.string().allow(null, ""),
|
|
status: Joi.array()
|
|
.items(Joi.string().valid("proposed", "draft", "published", "rejected"))
|
|
.single(),
|
|
collection_id: Joi.array()
|
|
.items(Joi.string())
|
|
.single(),
|
|
tags: Joi.array()
|
|
.items(Joi.string())
|
|
.single(),
|
|
title: Joi.string(),
|
|
description: Joi.string(),
|
|
handle: Joi.string(),
|
|
is_giftcard: Joi.string(),
|
|
type: Joi.string(),
|
|
offset: Joi.string(),
|
|
limit: Joi.string(),
|
|
expand: Joi.string(),
|
|
fields: Joi.string(),
|
|
order: Joi.string().optional(),
|
|
created_at: Joi.dateFilter(),
|
|
updated_at: Joi.dateFilter(),
|
|
deleted_at: Joi.dateFilter(),
|
|
})
|
|
}
|
|
|
|
export default Joi
|