@outlawdesigns/armorysdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +191 -0
- package/index.js +3 -0
- package/modelFactory.js +61 -0
- package/models/ammopurchase.js +74 -0
- package/models/ammunition.js +21 -0
- package/models/ammunitionType.js +21 -0
- package/models/caliber.js +21 -0
- package/models/firearm.js +21 -0
- package/models/firearmImage.js +31 -0
- package/models/firearmType.js +21 -0
- package/models/manufacturer.js +21 -0
- package/models/optic.js +21 -0
- package/models/opticType.js +21 -0
- package/models/shoot.js +44 -0
- package/models/targetImage.js +31 -0
- package/models/vendor.js +21 -0
- package/package.json +14 -0
package/README.md
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# Armory SDK (Server-Side)
|
|
2
|
+
|
|
3
|
+
A lightweight Node.js SDK for interacting with the **Armory data layer**.
|
|
4
|
+
This package provides ORM-style access to firearms, ammunition, optics, and shooting data through a consistent, class-based interface built on `@outlawdesigns/db-record`.
|
|
5
|
+
|
|
6
|
+
----------
|
|
7
|
+
|
|
8
|
+
## 🚀 Features
|
|
9
|
+
|
|
10
|
+
- 🔫 **Comprehensive armory models** — Manage firearms, ammunition, optics, and related entities.
|
|
11
|
+
|
|
12
|
+
- 🧩 **Dynamic model factory** — Fetch models or classes by name using a centralized interface.
|
|
13
|
+
|
|
14
|
+
- 🗃️ **Database abstraction** — Built on `@outlawdesigns/db-record` for clean MySQL integration.
|
|
15
|
+
|
|
16
|
+
- 📸 **Media support** — Includes models for firearm and target images.
|
|
17
|
+
|
|
18
|
+
- 📊 **Activity tracking** — Record shooting sessions and ammo purchases.
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
----------
|
|
22
|
+
|
|
23
|
+
## 📦 Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @outlawdesigns/armorysdk
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
----------
|
|
31
|
+
|
|
32
|
+
## 🧠 Basic Usage
|
|
33
|
+
|
|
34
|
+
### Require the SDK
|
|
35
|
+
|
|
36
|
+
```js
|
|
37
|
+
import ModelFactory from '@outlawdesigns/armorysdk';
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Create a Model Instance
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
const firearm = await ModelFactory.get('firearm',2).init();
|
|
44
|
+
console.log(firearm.Serial_Number);
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Access Model Classes Directly
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
const Firearm = Armory.getClass('firearm');
|
|
51
|
+
const myFirearm = new Firearm(2);
|
|
52
|
+
await myFirearm.init();
|
|
53
|
+
//particularly useful for calling static methods
|
|
54
|
+
const allArms = await ModelFactory.getClass('firearm').getAll()
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
----------
|
|
59
|
+
|
|
60
|
+
## 🧩 Available Models
|
|
61
|
+
|
|
62
|
+
| Model | Description | Backing Table |
|
|
63
|
+
| :--- | :---: | ---: |
|
|
64
|
+
| `firearm` | Concrete instance of a firearm owned by a user. | `Firearm` |
|
|
65
|
+
| ``firearmImage`` | Images associated with firearms. | `FirearmImage` |
|
|
66
|
+
| `firearmType` | Abstract firearm definition. | `FirearmType` |
|
|
67
|
+
| `manufacturer` | Firearm or component manufacturer. | `Manufacturer` |
|
|
68
|
+
| `ammunition` | Concrete instance of ammunition owned by a user. | `Ammunition` |
|
|
69
|
+
| `ammunitionType` | Abstract ammunition definition. | `AmmunitionType` |
|
|
70
|
+
| `caliber` | Caliber definitions. | `Caliber` |
|
|
71
|
+
| `ammoPurchase` | Records of ammunition purchases. | `AmmoPurchase` |
|
|
72
|
+
| `optic` | Concrete instance of an optic owned by a user. | Optic |
|
|
73
|
+
| `opticType` | Abstract optic definition. | `OpticType` |
|
|
74
|
+
| `shoot` | Shooting session records. | `Shoot` |
|
|
75
|
+
| `targetImage` | Images of shot targets. | `TargetImage` |
|
|
76
|
+
| `vendor` | Vendors or retailers. | `Vendor` |
|
|
77
|
+
|
|
78
|
+
All models extend `@outlawdesigns/db-record.Record` and support standard CRUD operations.
|
|
79
|
+
|
|
80
|
+
----------
|
|
81
|
+
|
|
82
|
+
## 🔧 Example: Recording a Shooting Session
|
|
83
|
+
|
|
84
|
+
```js
|
|
85
|
+
import ModelFactory from '@outlawdesigns/armorysdk';
|
|
86
|
+
|
|
87
|
+
const firearmId = 1;
|
|
88
|
+
const ammoId = 2;
|
|
89
|
+
const rounds = 100;
|
|
90
|
+
const distanceFt = 300;
|
|
91
|
+
const opticId = null;
|
|
92
|
+
const userId = 'example';
|
|
93
|
+
|
|
94
|
+
const newShoot = model = await ModelFactory.getClass('shoot').new(firearmId,ammoId,rounds, distanceFt, opticId, userId);
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
----------
|
|
98
|
+
|
|
99
|
+
## 🔧 Example: Logging an Ammo Purchase
|
|
100
|
+
|
|
101
|
+
```js
|
|
102
|
+
import ModelFactory from '@outlawdesigns/armorysdk';
|
|
103
|
+
|
|
104
|
+
const ammoId = 2;
|
|
105
|
+
const vendorId = 12;
|
|
106
|
+
const rounds = 100;
|
|
107
|
+
const price = 55.90;
|
|
108
|
+
const datePurchased = new Date();
|
|
109
|
+
//pass undefined instead for pending receipt
|
|
110
|
+
const dateReceived = datePurchased;
|
|
111
|
+
const userId = 'example';
|
|
112
|
+
|
|
113
|
+
const purchase = await ModelFactory.getClass('ammoPurchase').new(ammoId, vendorId, rounds, price, datePurchased, dateReceived, userId);
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
----------
|
|
118
|
+
|
|
119
|
+
## ⚙️ Environment Variables
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
| Variable | Description | Default |
|
|
123
|
+
| :--- | :---: | ---: |
|
|
124
|
+
| `MYSQL_ARMORY_DB` | Database name for Armory models. | `Armory` |
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
----------
|
|
128
|
+
|
|
129
|
+
## 🧱 Project Structure
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
.
|
|
133
|
+
├── index.js # SDK entry point
|
|
134
|
+
├── modelFactory.js # Central model registry
|
|
135
|
+
├── models/
|
|
136
|
+
│ ├── ammunition.js
|
|
137
|
+
│ ├── ammunitionType.js
|
|
138
|
+
│ ├── ammoPurchase.js
|
|
139
|
+
│ ├── caliber.js
|
|
140
|
+
│ ├── firearm.js
|
|
141
|
+
│ ├── firearmImage.js
|
|
142
|
+
│ ├── firearmType.js
|
|
143
|
+
│ ├── manufacturer.js
|
|
144
|
+
│ ├── optic.js
|
|
145
|
+
│ ├── opticType.js
|
|
146
|
+
│ ├── shoot.js
|
|
147
|
+
│ ├── targetImage.js
|
|
148
|
+
│ └── vendor.js
|
|
149
|
+
└── package.json
|
|
150
|
+
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
----------
|
|
154
|
+
|
|
155
|
+
## 🧩 Extending the SDK
|
|
156
|
+
|
|
157
|
+
To add a new model:
|
|
158
|
+
|
|
159
|
+
1. Create a file in `models/` extending `@outlawdesigns/db-record.Record`.
|
|
160
|
+
|
|
161
|
+
2. Register it in `modelFactory.js`.
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
Example:
|
|
165
|
+
|
|
166
|
+
```js
|
|
167
|
+
class Range extends Record {
|
|
168
|
+
static table = 'range';
|
|
169
|
+
static primaryKey = 'id';
|
|
170
|
+
static get database() {
|
|
171
|
+
return process.env.MYSQL_ARMORY_DB || 'armory';
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Register it:
|
|
178
|
+
|
|
179
|
+
```js
|
|
180
|
+
const Range = require('./models/range');
|
|
181
|
+
|
|
182
|
+
models.range = (id) => new Range(id);
|
|
183
|
+
modelClasses.range = Range;
|
|
184
|
+
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
## 👤 Author
|
|
189
|
+
|
|
190
|
+
Maintained by **Outlaw Designs**
|
|
191
|
+
[https://github.com/outlawdesigns-io](https://github.com/outlawdesigns-io)
|
package/index.js
ADDED
package/modelFactory.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const AmmoPurchase = require('./models/ammopurchase');
|
|
2
|
+
const Ammunition = require('./models/ammunition');
|
|
3
|
+
const AmmunitionType = require('./models/ammunitionType.js');
|
|
4
|
+
const Caliber = require('./models/caliber.js');
|
|
5
|
+
const FirearmImage = require('./models/firearmImage.js');
|
|
6
|
+
const Firearm = require('./models/firearm.js');
|
|
7
|
+
const FirearmType = require('./models/firearmType.js');
|
|
8
|
+
const Manufacturer = require('./models/manufacturer.js');
|
|
9
|
+
const Optic = require('./models/optic.js');
|
|
10
|
+
const OpticType = require('./models/opticType.js');
|
|
11
|
+
const Shoot = require('./models/shoot.js');
|
|
12
|
+
const TargetImage = require('./models/targetImage.js');
|
|
13
|
+
const Vendor = require('./models/vendor.js');
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
const models = {
|
|
17
|
+
ammopurchase: () => new AmmoPurchase(id),
|
|
18
|
+
ammo: () => new Ammunition(id),
|
|
19
|
+
ammotype: (id) => new AmmunitionType(id),
|
|
20
|
+
caliber: (id) => new Caliber(id),
|
|
21
|
+
firearmimage: (id) => new FirearmImage(id),
|
|
22
|
+
firearm: (id) => new Firearm(id),
|
|
23
|
+
firearmtype: () => new FirearmType(id),
|
|
24
|
+
manufacturer: ()=> new Manufacturer(id),
|
|
25
|
+
optic: ()=> new Optic(id),
|
|
26
|
+
optictype: ()=> new OpticType(id),
|
|
27
|
+
shoot: ()=> new Shoot(id),
|
|
28
|
+
targetimage: ()=> new TargetImage(id),
|
|
29
|
+
vendor: ()=> new Vendor(id),
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const modelClasses = {
|
|
33
|
+
ammopurchase:AmmoPurchase,
|
|
34
|
+
ammo:Ammunition,
|
|
35
|
+
ammotype:AmmunitionType,
|
|
36
|
+
caliber:Caliber,
|
|
37
|
+
firearmimage:FirearmImage,
|
|
38
|
+
firearm:Firearm,
|
|
39
|
+
firearmtype:FirearmType,
|
|
40
|
+
manufacturer:Manufacturer,
|
|
41
|
+
optic:Optic,
|
|
42
|
+
optictype:OpticType,
|
|
43
|
+
shoot:Shoot,
|
|
44
|
+
targetimage:TargetImage,
|
|
45
|
+
vendor:Vendor
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
module.exports = {
|
|
49
|
+
get: (name,id) => {
|
|
50
|
+
if(!models[name]){
|
|
51
|
+
throw new Error(`Model ${name} does not exist`);
|
|
52
|
+
}
|
|
53
|
+
return models[name](id);
|
|
54
|
+
},
|
|
55
|
+
getClass: (name) => {
|
|
56
|
+
if(!modelClasses[name]){
|
|
57
|
+
throw new Error(`Model ${name} does not exist`);
|
|
58
|
+
}
|
|
59
|
+
return modelClasses[name];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const Record = require('@outlawdesigns/db-record');
|
|
4
|
+
const Ammunition = require('./ammunition');
|
|
5
|
+
const Vendor = require('./vendor');
|
|
6
|
+
|
|
7
|
+
class AmmoPurchase extends Record{
|
|
8
|
+
|
|
9
|
+
static table = 'AmmoPurchase';
|
|
10
|
+
static primaryKey = 'Id';
|
|
11
|
+
static get database(){
|
|
12
|
+
return process.env.ARMORY_MYSQL_DB || 'Armory';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
constructor(id){
|
|
16
|
+
super(AmmoPurchase.database,AmmoPurchase.table,AmmoPurchase.primaryKey,id);
|
|
17
|
+
this.publicKeys = [
|
|
18
|
+
'Id','Ammunition','Vendor','Rounds','Price','DatePurchased','DateReceived','User'
|
|
19
|
+
];
|
|
20
|
+
}
|
|
21
|
+
static async new(ammoId,vendorId,rounds,price,datePurchased,dateReceived,user){
|
|
22
|
+
let ammo;
|
|
23
|
+
let vendor;
|
|
24
|
+
let purchase = new AmmoPurchase();
|
|
25
|
+
try{
|
|
26
|
+
ammo = await new Ammunition(ammoId).init();
|
|
27
|
+
vendor = await new Vendor(vendorId).init();
|
|
28
|
+
}catch(err){
|
|
29
|
+
throw err;
|
|
30
|
+
}
|
|
31
|
+
if(dateReceived !== undefined){
|
|
32
|
+
ammo.Rounds += parseInt(rounds);
|
|
33
|
+
await ammo.update();
|
|
34
|
+
purchase.DateReceived = dateReceived;
|
|
35
|
+
}
|
|
36
|
+
purchase.DatePurchased = datePurchased;
|
|
37
|
+
purchase.Price = price;
|
|
38
|
+
purchase.Rounds = rounds;
|
|
39
|
+
purchase.Vendor = vendorId;
|
|
40
|
+
purchase.Ammunition = ammoId;
|
|
41
|
+
purchase.User = user;
|
|
42
|
+
return await purchase.create();
|
|
43
|
+
}
|
|
44
|
+
static async receive(purchaseId){
|
|
45
|
+
//todo: reject if DateReceived is already populated.
|
|
46
|
+
//todo: ammo doesn't exist gets caught, but doesn't seem to bubble all the way up.
|
|
47
|
+
let purchase;
|
|
48
|
+
let ammo;
|
|
49
|
+
try{
|
|
50
|
+
purchase = await new AmmoPurchase(purchaseId).init();
|
|
51
|
+
ammo = await new Ammunition(purchase.Ammunition).init();
|
|
52
|
+
ammo.Rounds += purchase.Rounds;
|
|
53
|
+
await ammo.update();
|
|
54
|
+
purchase.DatePurchased = purchase.db.date(purchase.DatePurchased);
|
|
55
|
+
purchase.DateReceived = purchase.db.date();
|
|
56
|
+
await purchase.update();
|
|
57
|
+
return purchase.getPublicProperties();
|
|
58
|
+
}catch(err){
|
|
59
|
+
throw err;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
static async getAwaitingReceipt(user){
|
|
63
|
+
let records = [];
|
|
64
|
+
let purchase = new AmmoPurchase();
|
|
65
|
+
let ids = await purchase.db.table(purchase.table).select(purchase.primaryKey).where('DateReceived is null').andWhere('User = ' + user).execute();
|
|
66
|
+
for(let id in ids){
|
|
67
|
+
let obj = await new AmmoPurchase(ids[id][purchase.primaryKey]).init();
|
|
68
|
+
records.push(obj.getPublicProperties());
|
|
69
|
+
}
|
|
70
|
+
return records;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
module.exports = AmmoPurchase;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const Record = require('@outlawdesigns/db-record');
|
|
4
|
+
|
|
5
|
+
class Ammunition extends Record{
|
|
6
|
+
|
|
7
|
+
static table = 'Ammunition';
|
|
8
|
+
static primaryKey = 'Id';
|
|
9
|
+
static get database(){
|
|
10
|
+
return process.env.ARMORY_MYSQL_DB || 'Armory';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
constructor(id){
|
|
14
|
+
super(Ammunition.database,Ammunition.table,Ammunition.primaryKey,id);
|
|
15
|
+
this.publicKeys = [
|
|
16
|
+
'Id','AmmunitionType','Rounds','User'
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = Ammunition;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const Record = require('@outlawdesigns/db-record');
|
|
4
|
+
|
|
5
|
+
class AmmunitionType extends Record{
|
|
6
|
+
|
|
7
|
+
static table = 'AmmunitionType';
|
|
8
|
+
static primaryKey = 'Id';
|
|
9
|
+
static get database(){
|
|
10
|
+
return process.env.ARMORY_MYSQL_DB || 'Armory';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
constructor(id){
|
|
14
|
+
super(AmmunitionType.database,AmmunitionType.table,AmmunitionType.primaryKey,id);
|
|
15
|
+
this.publicKeys = [
|
|
16
|
+
'Id','Manufacturer','Caliber','BulletWeight','Casing','BulletType','MuzzleVelocity'
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = AmmunitionType;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const Record = require('@outlawdesigns/db-record');
|
|
4
|
+
|
|
5
|
+
class Caliber extends Record{
|
|
6
|
+
|
|
7
|
+
static table = 'Caliber';
|
|
8
|
+
static primaryKey = 'Id';
|
|
9
|
+
static get database(){
|
|
10
|
+
return process.env.ARMORY_MYSQL_DB || 'Armory';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
constructor(id){
|
|
14
|
+
super(Caliber.database,Caliber.table,Caliber.primaryKey,id);
|
|
15
|
+
this.publicKeys = [
|
|
16
|
+
'Id','Label'
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = Caliber;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const Record = require('@outlawdesigns/db-record');
|
|
4
|
+
|
|
5
|
+
class Firearm extends Record{
|
|
6
|
+
|
|
7
|
+
static table = 'Firearm';
|
|
8
|
+
static primaryKey = 'Id';
|
|
9
|
+
static get database(){
|
|
10
|
+
return process.env.ARMORY_MYSQL_DB || 'Armory';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
constructor(id){
|
|
14
|
+
super(Firearm.database,Firearm.table,Firearm.primaryKey,id);
|
|
15
|
+
this.publicKeys = [
|
|
16
|
+
'Id','FirearmType','NickName','Serial_Number','AcquisitionDate', 'Price', 'CurrentOptic', 'User'
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = Firearm;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const Record = require('@outlawdesigns/db-record');
|
|
4
|
+
|
|
5
|
+
class FirearmImage extends Record{
|
|
6
|
+
|
|
7
|
+
static table = 'FirearmImage';
|
|
8
|
+
static primaryKey = 'Id';
|
|
9
|
+
static get database(){
|
|
10
|
+
return process.env.ARMORY_MYSQL_DB || 'Armory';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
constructor(id){
|
|
14
|
+
super(FirearmImage.database,FirearmImage.table,FirearmImage.primaryKey,id);
|
|
15
|
+
this.publicKeys = [
|
|
16
|
+
'Id','BinaryData','Firearm','Optic', 'User'
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
static async getByFirearmId(firearmId){
|
|
20
|
+
let records = [];
|
|
21
|
+
let model = new FirearmImage();
|
|
22
|
+
let ids = await model.db.table(model.table).select(model.primaryKey).where('Firearm = ' + firearmId).execute();
|
|
23
|
+
for(let id in ids){
|
|
24
|
+
let obj = await new FirearmImage(ids[id][model.primaryKey]).init();
|
|
25
|
+
records.push(obj.getPublicProperties());
|
|
26
|
+
}
|
|
27
|
+
return records;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = FirearmImage;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const Record = require('@outlawdesigns/db-record');
|
|
4
|
+
|
|
5
|
+
class FirearmType extends Record{
|
|
6
|
+
|
|
7
|
+
static table = 'FirearmType';
|
|
8
|
+
static primaryKey = 'Id';
|
|
9
|
+
static get database(){
|
|
10
|
+
return process.env.ARMORY_MYSQL_DB || 'Armory';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
constructor(id){
|
|
14
|
+
super(FirearmType.database,FirearmType.table,FirearmType.primaryKey,id);
|
|
15
|
+
this.publicKeys = [
|
|
16
|
+
'Id','Manufacturer','Caliber','Model', 'LinkToProduct', 'MSRP'
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = FirearmType;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const Record = require('@outlawdesigns/db-record');
|
|
4
|
+
|
|
5
|
+
class Manufacturer extends Record{
|
|
6
|
+
|
|
7
|
+
static table = 'Manufacturer';
|
|
8
|
+
static primaryKey = 'Id';
|
|
9
|
+
static get database(){
|
|
10
|
+
return process.env.ARMORY_MYSQL_DB || 'Armory';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
constructor(id){
|
|
14
|
+
super(Manufacturer.database,Manufacturer.table,Manufacturer.primaryKey,id);
|
|
15
|
+
this.publicKeys = [
|
|
16
|
+
'Id','Name','Website', 'Firearm', 'Ammo', 'Optic'
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = Manufacturer;
|
package/models/optic.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const Record = require('@outlawdesigns/db-record');
|
|
4
|
+
|
|
5
|
+
class Optic extends Record{
|
|
6
|
+
|
|
7
|
+
static table = 'Optic';
|
|
8
|
+
static primaryKey = 'Id';
|
|
9
|
+
static get database(){
|
|
10
|
+
return process.env.ARMORY_MYSQL_DB || 'Armory';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
constructor(id){
|
|
14
|
+
super(Optic.database,Optic.table,Optic.primaryKey,id);
|
|
15
|
+
this.publicKeys = [
|
|
16
|
+
'Id','OpticType', 'AcquisitionDate', 'SerialNumber', 'Price', 'User'
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = Optic;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const Record = require('@outlawdesigns/db-record');
|
|
4
|
+
|
|
5
|
+
class OpticType extends Record{
|
|
6
|
+
|
|
7
|
+
static table = 'OpticType';
|
|
8
|
+
static primaryKey = 'Id';
|
|
9
|
+
static get database(){
|
|
10
|
+
return process.env.ARMORY_MYSQL_DB || 'Armory';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
constructor(id){
|
|
14
|
+
super(OpticType.database,OpticType.table,OpticType.primaryKey,id);
|
|
15
|
+
this.publicKeys = [
|
|
16
|
+
'Id','Manufacturer', 'Name', 'MagnificationTimes', 'LinkToProduct', 'MSRP'
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = OpticType;
|
package/models/shoot.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const Record = require('@outlawdesigns/db-record');
|
|
4
|
+
const Firearm = require('./firearm');
|
|
5
|
+
const Ammo = require('./ammunition');
|
|
6
|
+
|
|
7
|
+
class Shoot extends Record{
|
|
8
|
+
|
|
9
|
+
static table = 'Shoot';
|
|
10
|
+
static primaryKey = 'Id';
|
|
11
|
+
static get database(){
|
|
12
|
+
return process.env.ARMORY_MYSQL_DB || 'Armory';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
constructor(id){
|
|
16
|
+
super(Shoot.database,Shoot.table,Shoot.primaryKey,id);
|
|
17
|
+
this.publicKeys = [
|
|
18
|
+
'Id','Firearm','Ammo','Rounds','Distance_Ft','Created', 'Optic', 'User'
|
|
19
|
+
];
|
|
20
|
+
}
|
|
21
|
+
static async new(firearmId, ammoId, rounds, distance_ft, optic, user){
|
|
22
|
+
let firearm;
|
|
23
|
+
let ammo;
|
|
24
|
+
let shoot = new Shoot();
|
|
25
|
+
try{
|
|
26
|
+
firearm = await new Firearm(firearmId).init(); //validate firarmId
|
|
27
|
+
ammo = await new Ammo(ammoId).init();
|
|
28
|
+
ammo.Rounds -= rounds;
|
|
29
|
+
await ammo.update();
|
|
30
|
+
}catch(err){
|
|
31
|
+
throw err;
|
|
32
|
+
}
|
|
33
|
+
shoot.Firearm = firearmId;
|
|
34
|
+
shoot.Ammo = ammoId;
|
|
35
|
+
shoot.Rounds = rounds;
|
|
36
|
+
shoot.Distance_Ft = distance_ft;
|
|
37
|
+
shoot.Optic = optic;
|
|
38
|
+
shoot.Created = shoot.db.date();
|
|
39
|
+
shoot.User = user;
|
|
40
|
+
return await shoot.create();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
module.exports = Shoot;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const Record = require('@outlawdesigns/db-record');
|
|
4
|
+
|
|
5
|
+
class TargetImage extends Record{
|
|
6
|
+
|
|
7
|
+
static table = 'TargetImage';
|
|
8
|
+
static primaryKey = 'Id';
|
|
9
|
+
static get database(){
|
|
10
|
+
return process.env.ARMORY_MYSQL_DB || 'Armory';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
constructor(id){
|
|
14
|
+
super(TargetImage.database,TargetImage.table,TargetImage.primaryKey,id);
|
|
15
|
+
this.publicKeys = [
|
|
16
|
+
'Id','ShootId','BinaryData', 'User'
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
static async getByShootId(shootId){
|
|
20
|
+
let records = [];
|
|
21
|
+
let model = new TargetImage();
|
|
22
|
+
let ids = await model.db.table(model.table).select(model.primaryKey).where('ShootId = ' + shootId).execute();
|
|
23
|
+
for(let id in ids){
|
|
24
|
+
let obj = await new TargetImage(ids[id][model.primaryKey]).init();
|
|
25
|
+
records.push(obj.getPublicProperties());
|
|
26
|
+
}
|
|
27
|
+
return records;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = TargetImage;
|
package/models/vendor.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const Record = require('@outlawdesigns/db-record');
|
|
4
|
+
|
|
5
|
+
class Vendor extends Record{
|
|
6
|
+
|
|
7
|
+
static table = 'Vendor';
|
|
8
|
+
static primaryKey = 'Id';
|
|
9
|
+
static get database(){
|
|
10
|
+
return process.env.ARMORY_MYSQL_DB || 'Armory';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
constructor(id){
|
|
14
|
+
super(Vendor.database,Vendor.table,Vendor.primaryKey,id);
|
|
15
|
+
this.publicKeys = [
|
|
16
|
+
'Id','Name','Website', 'User'
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = Vendor;
|
package/package.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@outlawdesigns/armorysdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
7
|
+
},
|
|
8
|
+
"author": "",
|
|
9
|
+
"license": "ISC",
|
|
10
|
+
"description": "SDK for Armory Service",
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@outlawdesigns/db-record": "^1.1.0"
|
|
13
|
+
}
|
|
14
|
+
}
|