4.1.6 • Published 1 year ago

larvitorder v4.1.6

Weekly downloads
4
License
MIT
Repository
github
Last release
1 year ago

Build Status

larvitorder

Generic order module for nodejs.

order data structure:

{
	"uuid": "string",
	"fields": {
		"field1": [
			"value1",
			"value2"
		],
		"field2": [
			"value3"
		]
	},
	"rows": [
		{
			"uuid": "string", <-- special field
			"field1": [394],
			"field2": ["nisse", 20]
		}
	]
}

Installation

npm i --save larvitorder

Usage

Initialize

All below instructions require the loading of libraries like something below (db is an instance of larvitdb and log an instance of winston or larvitutils.Log):

const OrderLib = require('larvitorder');
const orderLib = new OrderLib({ db, log })
await orderLib.runDbMigrations();

Add a new order

const order = new orderLib.Order({db});

order.created = '2022-12-01T13:37:00Z'; // Must be ISO-8601
order.fields	= {'firstname': 'Günter', 'lastname': ['Edelweiss', 'Schloffs']};
order.rows	= [{'price': 399, 'name': 'Screw'}, {'price': 34, 'name': 'teh_foo', 'tags': ['foo', 'bar']}];

await order.save();

Load existing order from database

const order = new orderLib.Order({uuid: 'uuid-on-existing-order-in-db', db});

await order.loadFromDb();
// Now order.fields and order.rows is loaded from database

Remove order from database

const order = new orderLib.Order({uuid: 'uuid-on-existing-order-in-db', db});

await order.rm();
// order is now removed from DB

Get orders

const ordersCtx = new orderLib.Orders({db});

const {orders, hits} = await ordersCtx.get();

Filter and limit order list

const ordersCtx = new orderLib.Orders({db});

// Filter and limit order hits
orders.limit = 10;	// Only return 10 orders
orders.offset = 5;	// Skip the 5 first orders
orders.uuids = ['1ebe346e-c05a-11e6-a4a6-cec0c932ce01'];	// Only return orders with these uuids
orders.matchAllFields = {'firstname': 'Abraham', 'lastname': 'Lincoln'};	// Only return orders that have both the fields firstname and lastname that matches
orders.matchAllRowFields = {'productName': 'A4 paper'};	// Only return orders that have rows matching both the row fieldname "productName" and the value "A4 paper"

// Return order fields
orders.returnFields	= ['firstname', 'lastname', 'status'];	// Only return the order fields listed. IMPORTANT! Will return no order fields if not supplied! Because performance.

// Return order row fields
orders.returnRowFields	= ['productName', 'price'];	// Only return the order row fields listed. IMPORTANT! Will return no order row fields if not supplied! Because performance.

const {orders, hits} = await ordersCtx.get();
4.0.25

2 years ago

4.1.4

1 year ago

4.1.3

2 years ago

4.1.6

1 year ago

4.1.2

2 years ago

4.1.1

2 years ago

4.0.24

2 years ago

4.0.21

2 years ago

4.0.23

2 years ago

4.0.22

2 years ago

4.0.19

3 years ago

4.0.20

3 years ago

4.0.18

3 years ago

4.0.5

3 years ago

4.0.7

3 years ago

4.0.6

3 years ago

4.0.9

3 years ago

4.0.8

3 years ago

4.0.10

3 years ago

4.0.15

3 years ago

4.0.17

3 years ago

4.0.12

3 years ago

4.0.11

3 years ago

4.0.14

3 years ago

4.0.13

3 years ago

4.0.1

4 years ago

4.0.0

4 years ago

4.0.3

3 years ago

4.0.2

4 years ago

3.0.24

4 years ago

3.0.27

4 years ago

3.0.26

4 years ago

3.0.31

4 years ago

3.0.29

4 years ago

3.0.23

4 years ago

3.0.21

4 years ago

3.0.22

4 years ago

3.0.20

4 years ago

3.0.18

4 years ago

3.0.12

4 years ago

3.0.13

4 years ago

3.0.10

4 years ago

3.0.11

4 years ago

3.0.16

4 years ago

3.0.8

4 years ago

3.0.17

4 years ago

3.0.7

4 years ago

3.0.14

4 years ago

3.0.6

4 years ago

3.0.15

4 years ago

3.0.9

4 years ago

3.0.4

4 years ago

3.0.3

4 years ago

3.0.5

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

2.2.0

4 years ago

3.0.0

4 years ago

2.1.1

5 years ago

2.1.0

6 years ago

2.0.5

6 years ago

2.0.4

6 years ago

2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.1

7 years ago

0.8.1

8 years ago

0.8.0

8 years ago

0.7.0

8 years ago

0.6.8

8 years ago

0.6.7

8 years ago

0.6.6

8 years ago

0.6.5

8 years ago

0.6.4

9 years ago

0.6.3

9 years ago

0.6.2

9 years ago

0.6.1

9 years ago

0.6.0

9 years ago

0.5.0

9 years ago

0.4.8

9 years ago

0.4.7

9 years ago

0.4.6

9 years ago

0.4.5

9 years ago

0.4.4

9 years ago

0.4.3

9 years ago

0.4.2

9 years ago

0.4.1

9 years ago

0.4.0

9 years ago

0.3.0

9 years ago

0.2.14

9 years ago

0.2.13

9 years ago

0.2.12

9 years ago

0.2.11

9 years ago

0.2.10

9 years ago

0.2.8

10 years ago

0.2.7

10 years ago

0.2.6

10 years ago

0.2.5

10 years ago

0.2.4

10 years ago

0.2.3

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2-alpha

10 years ago