-
Notifications
You must be signed in to change notification settings - Fork 0
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
18 changed files
with
902 additions
and
118 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
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,31 @@ | ||
This should be abstracted, perhaps as part of the QueryProvider config? | ||
|
||
We have two formats for querying data: | ||
|
||
- one for the local rxdb database (mongo like syntax) | ||
- one for the WC REST API which has it's own quirks | ||
|
||
For example: | ||
|
||
Query products by category 19 in rxdb, ordered by name. | ||
|
||
``` | ||
{ | ||
selector: { | ||
categories: { | ||
$elemMatch: 19 | ||
} | ||
}, | ||
sortBy: 'name' | ||
} | ||
``` | ||
|
||
Query products by category 19 in WC REST API, ordered by name. | ||
|
||
``` | ||
queryParams = { | ||
category: 19, | ||
orderby: 'title' | ||
} | ||
``` |
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,36 @@ | ||
import isEmpty from 'lodash/isEmpty'; | ||
|
||
type ProductCategoryDocument = import('@wcpos/database/src').ProductCategoryDocument; | ||
|
||
interface APIQueryParams { | ||
context?: 'view' | 'edit'; | ||
page?: number; | ||
per_page?: number; | ||
search?: string; | ||
exclude?: number[]; | ||
include?: number[]; | ||
order?: 'asc' | 'desc'; | ||
orderby?: 'id' | 'include' | 'name' | 'slug' | 'term_group' | 'description' | 'count'; | ||
hide_empty?: boolean; | ||
parent?: number; | ||
product?: number; | ||
slug?: string; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
const filterApiQueryParams = (params, checkpoint, batchSize) => { | ||
const { include } = checkpoint; | ||
|
||
/** | ||
* Categories don't have a date field, so if localIDs = remoteIDs, then we can skip the API call | ||
*/ | ||
if (isEmpty(include)) { | ||
return false; | ||
} | ||
|
||
return params; | ||
}; | ||
|
||
export { filterApiQueryParams }; |
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,48 @@ | ||
type CustomerDocument = import('@wcpos/database/src').CustomerDocument; | ||
|
||
interface APIQueryParams { | ||
context?: 'view' | 'edit'; | ||
page?: number; | ||
per_page?: number; | ||
search?: string; | ||
exclude?: number[]; | ||
include?: number[]; | ||
offset?: number; | ||
order?: 'asc' | 'desc'; | ||
orderby?: 'id' | 'include' | 'name' | 'registered_date'; | ||
email?: string; | ||
role?: | ||
| 'all' | ||
| 'administrator' | ||
| 'editor' | ||
| 'author' | ||
| 'contributor' | ||
| 'subscriber' | ||
| 'customer' | ||
| 'shop_manager'; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
const filterApiQueryParams = (params, checkpoint, batchSize) => { | ||
let orderby = params.orderby; | ||
|
||
if (orderby === 'date_created') { | ||
orderby = 'registered_date'; | ||
} | ||
|
||
// HACK: get the deafult_customer, probably a better way to do this | ||
// if (params.id) { | ||
// params.include = params.id; | ||
// params.id = undefined; | ||
// } | ||
|
||
return { | ||
...params, | ||
role: 'all', | ||
orderby, | ||
}; | ||
}; | ||
|
||
export { filterApiQueryParams }; |
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,55 @@ | ||
type OrderDocument = import('@wcpos/database/src').OrderDocument; | ||
|
||
interface APIQueryParams { | ||
context?: 'view' | 'edit'; | ||
page?: number; | ||
per_page?: number; | ||
search?: string; | ||
after?: string; | ||
before?: string; | ||
modified_after?: string; | ||
modified_before?: string; | ||
dates_are_gmt?: boolean; | ||
exclude?: number[]; | ||
include?: number[]; | ||
offset?: number; | ||
order?: 'asc' | 'desc'; | ||
orderby?: 'date' | 'id' | 'include' | 'title' | 'slug'; | ||
parent?: number[]; | ||
parent_exclude?: number[]; | ||
status?: | ||
| 'any' | ||
| 'pending' | ||
| 'processing' | ||
| 'on-hold' | ||
| 'completed' | ||
| 'cancelled' | ||
| 'refunded' | ||
| 'failed' | ||
| 'trash'; | ||
customer?: number; | ||
product?: number; | ||
dp?: number; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
const filterApiQueryParams = (params, checkpoint, batchSize) => { | ||
let orderby = params.orderby; | ||
|
||
if (orderby === 'date_created' || orderby === 'date_created_gmt') { | ||
orderby = 'date'; | ||
} | ||
|
||
if (orderby === 'number') { | ||
orderby = 'id'; | ||
} | ||
|
||
return { | ||
...params, | ||
orderby, | ||
}; | ||
}; | ||
|
||
export { filterApiQueryParams }; |
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,71 @@ | ||
import get from 'lodash/get'; | ||
|
||
type ProductDocument = import('@wcpos/database/src').ProductDocument; | ||
|
||
interface APIQueryParams { | ||
context?: 'view' | 'edit'; | ||
page?: number; | ||
per_page?: number; | ||
search?: string; | ||
after?: string; | ||
before?: string; | ||
modified_after?: string; | ||
modified_before?: string; | ||
dates_are_gmt?: boolean; | ||
exclude?: number[]; | ||
include?: number[]; | ||
offset?: number; | ||
order?: 'asc' | 'desc'; | ||
orderby?: 'date' | 'id' | 'include' | 'title' | 'slug' | 'price' | 'popularity' | 'rating'; | ||
parent?: number[]; | ||
parent_exclude?: number[]; | ||
slug?: string; | ||
status?: 'any' | 'draft' | 'pending' | 'private' | 'publish'; | ||
type?: 'simple' | 'grouped' | 'external' | 'variable'; | ||
sku?: string; | ||
featured?: boolean; | ||
category?: string; | ||
tag?: string; | ||
shipping_class?: string; | ||
attribute?: string; | ||
attribute_term?: string; | ||
tax_class?: 'standard' | 'reduced-rate' | 'zero-rate'; | ||
on_sale?: boolean; | ||
min_price?: string; | ||
max_price?: string; | ||
stock_status?: 'instock' | 'outofstock' | 'onbackorder'; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
const filterApiQueryParams = (params, checkpoint, batchSize) => { | ||
let orderby = params.orderby; | ||
|
||
if (orderby === 'name') { | ||
orderby = 'title'; | ||
} | ||
|
||
if (orderby === 'date_created') { | ||
orderby = 'date'; | ||
} | ||
|
||
if (params.categories) { | ||
params.category = get(params, ['categories', '$elemMatch', 'id']); | ||
delete params.categories; | ||
} | ||
|
||
if (params.tags) { | ||
params.tag = get(params, ['tags', '$elemMatch', 'id']); | ||
delete params.categories; | ||
} | ||
|
||
return { | ||
...params, | ||
id: undefined, // remove id: { $in: [] } from query, eg: grouped products | ||
orderby, | ||
status: 'publish', | ||
}; | ||
}; | ||
|
||
export { filterApiQueryParams }; |
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,36 @@ | ||
import isEmpty from 'lodash/isEmpty'; | ||
|
||
type ProductTagDocument = import('@wcpos/database/src').ProductTagDocument; | ||
|
||
interface APIQueryParams { | ||
context?: 'view' | 'edit'; | ||
page?: number; | ||
per_page?: number; | ||
search?: string; | ||
exclude?: number[]; | ||
include?: number[]; | ||
offset?: number; | ||
order?: 'asc' | 'desc'; | ||
orderby?: 'id' | 'include' | 'name' | 'slug' | 'term_group' | 'description' | 'count'; | ||
hide_empty?: boolean; | ||
product?: number; | ||
slug?: string; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
const filterApiQueryParams = (params, checkpoint, batchSize) => { | ||
const { include } = checkpoint; | ||
|
||
/** | ||
* Tags don't have a date field, so if localIDs = remoteIDs, then we can skip the API call | ||
*/ | ||
if (isEmpty(include)) { | ||
return false; | ||
} | ||
|
||
return params; | ||
}; | ||
|
||
export { filterApiQueryParams }; |
Oops, something went wrong.