|
1 | 1 | import { connectionQuery } from "../../../helpers/connection.helpers.js"; |
2 | 2 |
|
| 3 | +export const extractForeignKeysInventoryModel = async ( |
| 4 | + condition, |
| 5 | + location, |
| 6 | + status, |
| 7 | +) => { |
| 8 | + const query = `SELECT |
| 9 | + (SELECT |
| 10 | + condition_id |
| 11 | + FROM |
| 12 | + asset_conditions |
| 13 | + WHERE |
| 14 | + name = ?) AS 'condition', |
| 15 | + (SELECT |
| 16 | + location_id |
| 17 | + FROM |
| 18 | + cat_classrooms |
| 19 | + WHERE |
| 20 | + name = ?) AS location, |
| 21 | + (SELECT |
| 22 | + status_id |
| 23 | + FROM |
| 24 | + cat_status |
| 25 | + WHERE |
| 26 | + name = ?) AS status;`; |
| 27 | + const result = await connectionQuery(query, [condition, location, status]); |
| 28 | + return result; |
| 29 | +}; |
| 30 | + |
3 | 31 | export const insertInventoryModel = async ({ |
4 | | - itemCode, |
| 32 | + condition, |
| 33 | + location, |
| 34 | + item_code, |
| 35 | + serial_number, |
5 | 36 | name, |
6 | 37 | description, |
7 | 38 | quantity, |
8 | 39 | weight, |
9 | 40 | width, |
10 | 41 | height, |
11 | | - location, |
12 | | - condition, |
13 | | - purchaseDate, |
| 42 | + purchase_date, |
| 43 | + cost, |
| 44 | + last_maintenance_date, |
| 45 | + warranty_end_date, |
| 46 | + status, |
14 | 47 | }) => { |
15 | | - const query = `INSERT INTO catinventory (ID, ItemCode, Name, Description, Quantity, Weight, Width, Height, Location, \`Condition\`, PurchaseDate) |
16 | | - VALUES (UUID(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`; |
| 48 | + const query = `INSERT INTO cat_inventory ( |
| 49 | + inventory_id, condition_id, location_id, item_code, |
| 50 | + serial_number, name, description, |
| 51 | + quantity, weight, width, height, purchase_date, |
| 52 | + cost, last_maintenance_date, warranty_end_date, |
| 53 | + status_id |
| 54 | +) |
| 55 | +VALUES |
| 56 | + ( |
| 57 | + UUID(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? |
| 58 | + ); |
| 59 | +`; |
17 | 60 |
|
18 | 61 | const params = [ |
19 | | - itemCode, |
| 62 | + condition, |
| 63 | + location, |
| 64 | + item_code, |
| 65 | + serial_number, |
20 | 66 | name, |
21 | 67 | description, |
22 | 68 | quantity, |
23 | 69 | weight, |
24 | 70 | width, |
25 | 71 | height, |
26 | | - location, |
27 | | - condition, |
28 | | - purchaseDate, |
| 72 | + purchase_date, |
| 73 | + cost, |
| 74 | + last_maintenance_date, |
| 75 | + warranty_end_date, |
| 76 | + status, |
29 | 77 | ]; |
30 | 78 |
|
31 | 79 | return await connectionQuery(query, params); |
|
0 commit comments