Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(products): add customizations
  • Loading branch information
eljefedelrodeodeljefe committed Aug 25, 2019
1 parent 28fdeb7 commit 2e81dc0
Show file tree
Hide file tree
Showing 7 changed files with 500 additions and 195 deletions.
196 changes: 1 addition & 195 deletions lib/v1/products/base.js
@@ -1,93 +1,5 @@
const { oneOf } = require('../../helpers/payload-or-null')

const price = {
amount: {
description: 'Either net or gross should be set (not null). Tax will be calculated accordingly automatically. We do not validate for either to be set, for data flexibility reasons.',
type: 'object',
properties: {
net: {
oneOf: [
{
example: '27633.02',
type: 'number',
minimum: 0,
maximum: 1000000,
multipleOf: 0.01
},
{
type: 'null'
}
]
},
gross: {
oneOf: [
{
example: '27633.02',
type: 'number',
minimum: 0,
maximum: 1000000,
multipleOf: 0.01
},
{
type: 'null'
}
]
}
}
},
currency: {
type: 'string',
minLength: 3,
maxLength: 3
},
percentage: {
description: 'DEPRECATED',
type: 'number'
},
purchase_price: {
description: 'Define the opportunity cost or calculatory base price of this product and currency.',
oneOf: [
{
example: '27633.02',
type: 'number',
minimum: 0,
maximum: 1000000,
multipleOf: 0.01
},
{
type: 'null'
}
]
},
cost: {
description: 'Define additional cost.',
oneOf: [
{
example: '27633.02',
type: 'number',
minimum: 0,
maximum: 1000000,
multipleOf: 0.01
},
{
type: 'null'
}
]
},
margin: {
description: 'Add a margin to pruchase_price and cost to result in net.',
oneOf: [
{
type: 'number',
multipleOf: 0.0001
},
{
type: 'null'
}
]
}
}

const stockConfigurationLocation = {
type: 'array',
items: {
Expand Down Expand Up @@ -189,113 +101,7 @@ module.exports = {
}
]
},
prices: {
anyOf: [
{
type: 'object',
properties: {
branch_prices: {
type: 'array',
items: {
type: 'object',
properties: {
branch: {
// NOTE: to to legacy regression, we currently need to allow null branches
oneOf: [
{
type: 'string',
format: 'uuid'
},
{
type: 'null'
}
]
},
prices: {
type: 'array',
items: {
type: 'object',
properties: {
...price
}
}
}
}
}
},
scaled_prices: {
type: 'array',
items: {
type: 'object',
properties: {
qty: {
type: 'number'
},
prices: {
type: 'array',
items: {
type: 'object',
properties: {
...price
}
}
}
}
}
},
time_based_prices: {
type: 'array',
items: {
type: 'object',
properties: {
time_range: {
type: 'object',
properties: {
start: {
type: 'string',
format: 'date'
},
end: {
type: 'string',
format: 'date'
}
},
required: [
'start',
'end'
]
},
prices: {
type: 'array',
items: {
type: 'object',
properties: {
...price
}
}
}
}
}
},
default_prices: {
type: 'array',
items: {
type: 'object',
properties: {
...price
}
}
}
},
required: [
'default_prices'
]
},
{
type: 'null'
}
]
},
prices: require('./common/prices'),
barcode: {
anyOf: [
{
Expand Down
87 changes: 87 additions & 0 deletions lib/v1/products/common/price.js
@@ -0,0 +1,87 @@
module.exports = {
amount: {
description: 'Either net or gross should be set (not null). Tax will be calculated accordingly automatically. We do not validate for either to be set, for data flexibility reasons.',
type: 'object',
properties: {
net: {
oneOf: [
{
example: '27633.02',
type: 'number',
minimum: 0,
maximum: 1000000,
multipleOf: 0.01
},
{
type: 'null'
}
]
},
gross: {
oneOf: [
{
example: '27633.02',
type: 'number',
minimum: 0,
maximum: 1000000,
multipleOf: 0.01
},
{
type: 'null'
}
]
}
}
},
currency: {
type: 'string',
minLength: 3,
maxLength: 3
},
percentage: {
description: 'DEPRECATED',
type: 'number'
},
purchase_price: {
description: 'Define the opportunity cost or calculatory base price of this product and currency.',
oneOf: [
{
example: '27633.02',
type: 'number',
minimum: 0,
maximum: 1000000,
multipleOf: 0.01
},
{
type: 'null'
}
]
},
cost: {
description: 'Define additional cost.',
oneOf: [
{
example: '27633.02',
type: 'number',
minimum: 0,
maximum: 1000000,
multipleOf: 0.01
},
{
type: 'null'
}
]
},
margin: {
description: 'Add a margin to pruchase_price and cost to result in net.',
oneOf: [
{
type: 'number',
multipleOf: 0.0001
},
{
type: 'null'
}
]
}
}

0 comments on commit 2e81dc0

Please sign in to comment.