Skip to content

Instantly share code, notes, and snippets.

@roylee0704
Created March 22, 2020 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roylee0704/2707461d1089b36a83cacc6898033b87 to your computer and use it in GitHub Desktop.
Save roylee0704/2707461d1089b36a83cacc6898033b87 to your computer and use it in GitHub Desktop.
proposal: data-structure of carrier providers
export const carriers = [
{
name: 'Ninja Van',
code: 'ninja_van',
services: [
{
name: 'Standard Delivery',
code: 'ninja_standard_delivery',
zones: [
{
name: 'WM_KV',
code: 'WM_KV',
state_codes: ['KualaLumpur', 'Putrajaya', 'Selangor'],
rates: [
{
// can scale-out to support multiple conditions
condition: {
min: 0,
max: 1.01,
variable: 'WEIGHT',
uom: 'KG',
},
priceFn: () => 4,
currency: 'RM',
},
{
condition: {
min: 1.01,
max: 3.01,
variable: 'WEIGHT',
uom: 'KG',
},
priceFn: () => 4.5,
currency: 'RM',
},
{
condition: {
min: 3.01,
max: -1, // infinity
variable: 'WEIGHT',
uom: 'KG',
},
priceFn: (variable, min) => 18 + ((variable - min) * 0.7),
currency: 'RM',
},
],
},
{
name: 'WM_NKV',
code: 'WM_NKV',
state_codes: ['Johor', 'Kedah', 'Kelantan', 'Melaka', 'NegeriSembilan', 'Pahang', 'Perak', 'Perlis', 'Penang', 'Terengganu'],
rates: [
{
// can scale-out to support multiple conditions
condition: {
min: 0,
max: 1.01,
variable: 'WEIGHT',
uom: 'KG',
},
priceFn: () => 4.8,
currency: 'RM',
},
{
condition: {
min: 1.01,
max: 3.01,
variable: 'WEIGHT',
uom: 'KG',
},
priceFn: () => 4.8,
currency: 'RM',
},
{
condition: {
min: 3.01,
max: -1, // infinity
variable: 'WEIGHT',
uom: 'KG',
},
priceFn: (variable, min) => 20 + ((variable - min) * 1),
currency: 'RM',
},
],
},
{
name: 'EM',
code: 'EM',
state_codes: ['Labuan', 'Sabah', 'Sarawak'],
rates: [
{
// can scale-out to support multiple conditions
condition: {
min: 0,
max: 1.01,
variable: 'WEIGHT',
uom: 'KG',
},
priceFn: () => 10,
currency: 'RM',
},
{
condition: {
min: 1.01,
max: 3.01,
variable: 'WEIGHT',
uom: 'KG',
},
priceFn: () => 20,
currency: 'RM',
},
{
condition: {
min: 3.01,
max: -1, // infinity
variable: 'WEIGHT',
uom: 'KG',
},
priceFn: (variable, min) => 250 + ((variable - min) * 5),
currency: 'RM',
},
],
},
],
},
{
name: 'Express Delivery',
code: 'ninja_express_delivery',
zones: [
{
name: 'WM_KV',
code: 'WM_KV',
state_codes: ['KualaLumpur', 'Putrajaya', 'Selangor'],
rates: [
{
// can scale-out to support multiple conditions
condition: {
min: 0,
max: 1.01,
variable: 'WEIGHT',
uom: 'KG',
},
priceFn: () => 12,
currency: 'RM',
},
{
condition: {
min: 1.01,
max: 3.01,
variable: 'WEIGHT',
uom: 'KG',
},
priceFn: () => 12,
currency: 'RM',
},
{
condition: {
min: 3.01,
max: -1, // infinity
variable: 'WEIGHT',
uom: 'KG',
},
priceFn: (variable, min) => 36 + ((variable - min) * 1.5),
currency: 'RM',
},
],
},
],
},
],
},
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment