4.0.24 • Published 2 months ago

larvitorder v4.0.24

Weekly downloads
4
License
MIT
Repository
github
Last release
2 months 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.24

2 months ago

4.0.21

7 months ago

4.0.23

6 months ago

4.0.22

7 months ago

4.0.19

1 year ago

4.0.20

1 year ago

4.0.18

1 year ago

4.0.5

2 years ago

4.0.7

2 years ago

4.0.6

2 years ago

4.0.9

2 years ago

4.0.8

2 years ago

4.0.10

2 years ago

4.0.15

2 years ago

4.0.17

2 years ago

4.0.12

2 years ago

4.0.11

2 years ago

4.0.14

2 years ago

4.0.13

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

4.0.3

2 years ago

4.0.2

2 years ago

3.0.24

2 years ago

3.0.27

2 years ago

3.0.26

2 years ago

3.0.31

2 years ago

3.0.29

2 years ago

3.0.23

2 years ago

3.0.21

2 years ago

3.0.22

2 years ago

3.0.20

2 years ago

3.0.18

2 years ago

3.0.12

2 years ago

3.0.13

2 years ago

3.0.10

3 years ago

3.0.11

2 years ago

3.0.16

2 years ago

3.0.8

3 years ago

3.0.17

2 years ago

3.0.7

3 years ago

3.0.14

2 years ago

3.0.6

3 years ago

3.0.15

2 years ago

3.0.9

3 years ago

3.0.4

3 years ago

3.0.3

3 years ago

3.0.5

3 years ago

3.0.2

3 years ago

3.0.1

3 years ago

2.2.0

3 years ago

3.0.0

3 years ago

2.1.1

3 years ago

2.1.0

4 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

6 years ago

1.0.1

6 years ago

0.8.1

6 years ago

0.8.0

7 years ago

0.7.0

7 years ago

0.6.8

7 years ago

0.6.7

7 years ago

0.6.6

7 years ago

0.6.5

7 years ago

0.6.4

7 years ago

0.6.3

7 years ago

0.6.2

7 years ago

0.6.1

7 years ago

0.6.0

7 years ago

0.5.0

7 years ago

0.4.8

7 years ago

0.4.7

8 years ago

0.4.6

8 years ago

0.4.5

8 years ago

0.4.4

8 years ago

0.4.3

8 years ago

0.4.2

8 years ago

0.4.1

8 years ago

0.4.0

8 years ago

0.3.0

8 years ago

0.2.14

8 years ago

0.2.13

8 years ago

0.2.12

8 years ago

0.2.11

8 years ago

0.2.10

8 years ago

0.2.8

8 years ago

0.2.7

8 years ago

0.2.6

8 years ago

0.2.5

8 years ago

0.2.4

8 years ago

0.2.3

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago

0.0.4

8 years ago

0.0.3

9 years ago

0.0.2-alpha

9 years ago