|
| 1 | +import app from "../../snipe_it.app.mjs"; |
| 2 | +import utils from "../../common/utils.mjs"; |
| 3 | + |
| 4 | +export default { |
| 5 | + key: "snipe_it-create-hardware", |
| 6 | + name: "Create Hardware Asset", |
| 7 | + description: "Creates a new hardware asset in Snipe-IT. [See the documentation](https://snipe-it.readme.io/reference/hardware-create)", |
| 8 | + version: "0.0.1", |
| 9 | + type: "action", |
| 10 | + props: { |
| 11 | + app, |
| 12 | + modelId: { |
| 13 | + propDefinition: [ |
| 14 | + app, |
| 15 | + "modelId", |
| 16 | + ], |
| 17 | + }, |
| 18 | + statusId: { |
| 19 | + propDefinition: [ |
| 20 | + app, |
| 21 | + "statusId", |
| 22 | + ], |
| 23 | + }, |
| 24 | + assetTag: { |
| 25 | + propDefinition: [ |
| 26 | + app, |
| 27 | + "assetTag", |
| 28 | + ], |
| 29 | + }, |
| 30 | + name: { |
| 31 | + propDefinition: [ |
| 32 | + app, |
| 33 | + "name", |
| 34 | + ], |
| 35 | + }, |
| 36 | + image: { |
| 37 | + propDefinition: [ |
| 38 | + app, |
| 39 | + "image", |
| 40 | + ], |
| 41 | + }, |
| 42 | + serial: { |
| 43 | + propDefinition: [ |
| 44 | + app, |
| 45 | + "serial", |
| 46 | + ], |
| 47 | + }, |
| 48 | + purchaseDate: { |
| 49 | + propDefinition: [ |
| 50 | + app, |
| 51 | + "purchaseDate", |
| 52 | + ], |
| 53 | + }, |
| 54 | + purchaseCost: { |
| 55 | + propDefinition: [ |
| 56 | + app, |
| 57 | + "purchaseCost", |
| 58 | + ], |
| 59 | + }, |
| 60 | + orderNumber: { |
| 61 | + propDefinition: [ |
| 62 | + app, |
| 63 | + "orderNumber", |
| 64 | + ], |
| 65 | + }, |
| 66 | + notes: { |
| 67 | + propDefinition: [ |
| 68 | + app, |
| 69 | + "notes", |
| 70 | + ], |
| 71 | + }, |
| 72 | + archived: { |
| 73 | + propDefinition: [ |
| 74 | + app, |
| 75 | + "archived", |
| 76 | + ], |
| 77 | + }, |
| 78 | + warrantyMonths: { |
| 79 | + propDefinition: [ |
| 80 | + app, |
| 81 | + "warrantyMonths", |
| 82 | + ], |
| 83 | + }, |
| 84 | + depreciate: { |
| 85 | + propDefinition: [ |
| 86 | + app, |
| 87 | + "depreciate", |
| 88 | + ], |
| 89 | + }, |
| 90 | + supplierId: { |
| 91 | + propDefinition: [ |
| 92 | + app, |
| 93 | + "supplierId", |
| 94 | + ], |
| 95 | + }, |
| 96 | + requestable: { |
| 97 | + propDefinition: [ |
| 98 | + app, |
| 99 | + "requestable", |
| 100 | + ], |
| 101 | + }, |
| 102 | + rtdLocationId: { |
| 103 | + label: "RTD Location", |
| 104 | + description: "Select the default location for this asset", |
| 105 | + propDefinition: [ |
| 106 | + app, |
| 107 | + "locationId", |
| 108 | + ], |
| 109 | + }, |
| 110 | + lastAuditDate: { |
| 111 | + propDefinition: [ |
| 112 | + app, |
| 113 | + "lastAuditDate", |
| 114 | + ], |
| 115 | + }, |
| 116 | + locationId: { |
| 117 | + propDefinition: [ |
| 118 | + app, |
| 119 | + "locationId", |
| 120 | + ], |
| 121 | + }, |
| 122 | + byod: { |
| 123 | + propDefinition: [ |
| 124 | + app, |
| 125 | + "byod", |
| 126 | + ], |
| 127 | + }, |
| 128 | + customFields: { |
| 129 | + propDefinition: [ |
| 130 | + app, |
| 131 | + "customFields", |
| 132 | + ], |
| 133 | + }, |
| 134 | + }, |
| 135 | + async run({ $ }) { |
| 136 | + const { |
| 137 | + app, |
| 138 | + modelId, |
| 139 | + statusId, |
| 140 | + assetTag, |
| 141 | + name, |
| 142 | + image, |
| 143 | + serial, |
| 144 | + purchaseDate, |
| 145 | + purchaseCost, |
| 146 | + orderNumber, |
| 147 | + notes, |
| 148 | + archived, |
| 149 | + warrantyMonths, |
| 150 | + depreciate, |
| 151 | + supplierId, |
| 152 | + requestable, |
| 153 | + rtdLocationId, |
| 154 | + lastAuditDate, |
| 155 | + locationId, |
| 156 | + byod, |
| 157 | + customFields, |
| 158 | + } = this; |
| 159 | + |
| 160 | + const parsedCustomFields = utils.parseJson(customFields); |
| 161 | + |
| 162 | + const response = await app.createHardware({ |
| 163 | + $, |
| 164 | + data: { |
| 165 | + model_id: modelId, |
| 166 | + status_id: statusId, |
| 167 | + ...(name && { |
| 168 | + name, |
| 169 | + }), |
| 170 | + ...(assetTag && { |
| 171 | + asset_tag: assetTag, |
| 172 | + }), |
| 173 | + ...(image && { |
| 174 | + image, |
| 175 | + }), |
| 176 | + ...(serial && { |
| 177 | + serial, |
| 178 | + }), |
| 179 | + ...(purchaseDate && { |
| 180 | + purchase_date: purchaseDate, |
| 181 | + }), |
| 182 | + ...(purchaseCost && { |
| 183 | + purchase_cost: purchaseCost, |
| 184 | + }), |
| 185 | + ...(orderNumber && { |
| 186 | + order_number: orderNumber, |
| 187 | + }), |
| 188 | + ...(notes && { |
| 189 | + notes, |
| 190 | + }), |
| 191 | + ...(archived !== undefined && { |
| 192 | + archived, |
| 193 | + }), |
| 194 | + ...(warrantyMonths && { |
| 195 | + warranty_months: warrantyMonths, |
| 196 | + }), |
| 197 | + ...(depreciate !== undefined && { |
| 198 | + depreciate, |
| 199 | + }), |
| 200 | + ...(supplierId && { |
| 201 | + supplier_id: supplierId, |
| 202 | + }), |
| 203 | + ...(requestable !== undefined && { |
| 204 | + requestable, |
| 205 | + }), |
| 206 | + ...(rtdLocationId && { |
| 207 | + rtd_location_id: rtdLocationId, |
| 208 | + }), |
| 209 | + ...(lastAuditDate && { |
| 210 | + last_audit_date: lastAuditDate, |
| 211 | + }), |
| 212 | + ...(locationId && { |
| 213 | + location_id: locationId, |
| 214 | + }), |
| 215 | + ...(byod !== undefined && { |
| 216 | + byod, |
| 217 | + }), |
| 218 | + ...(typeof(parsedCustomFields) === "object" |
| 219 | + ? parsedCustomFields |
| 220 | + : {} |
| 221 | + ), |
| 222 | + }, |
| 223 | + }); |
| 224 | + |
| 225 | + $.export("$summary", `Successfully created hardware asset with ID \`${response.payload.id}\``); |
| 226 | + return response; |
| 227 | + }, |
| 228 | +}; |
0 commit comments