@@ -3,7 +3,7 @@ import * as farmosUtil from "../library/farmosUtil/farmosUtil.js";
33
44import { basename , dirname } from "path" ;
55import { fileURLToPath } from "url" ;
6- import { LocalStorage } from ' node-localstorage' ;
6+ import { LocalStorage } from " node-localstorage" ;
77
88/*
99 * Set the name of the CSV file to be processed and the
@@ -28,7 +28,7 @@ const pass = "admin";
2828 * Get a local storage object that we'll use to simulate the
2929 * browser's localStorage and sessionStorage when running in node.
3030 */
31- let ls = new LocalStorage ( ' scratch' ) ;
31+ let ls = new LocalStorage ( " scratch" ) ;
3232
3333/*
3434 * Get a fully initialized and logged in instance of the farmOS.js
@@ -61,27 +61,56 @@ let categoryName = null;
6161 */
6262async function processRow ( row ) {
6363 if ( row [ 0 ] != "" ) {
64- console . log ( " Adding " + row [ 0 ] + "..." ) ;
65- const categoryParent = farm . asset . create ( {
66- type : "asset--equipment" ,
67- attributes : {
68- name : row [ 0 ] ,
69- notes : row [ 1 ] ,
70- } ,
71- } ) ;
64+ let equipment = null ;
65+ if ( row . length == 1 ) {
66+ console . log ( " Adding equipment " + row [ 0 ] + ", which has no parents..." ) ;
67+ equipment = farm . asset . create ( {
68+ type : "asset--equipment" ,
69+ attributes : {
70+ name : row [ 0 ] ,
71+ } ,
72+ } ) ;
73+ } else if ( row . length == 4 ) {
74+ console . log ( " Adding equipment " + row [ 0 ] + ", which has no parents..." ) ;
75+ equipment = farm . asset . create ( {
76+ type : "asset--equipment" ,
77+ attributes : {
78+ name : row [ 0 ] ,
79+ manufacturer : row [ 1 ] ,
80+ model : row [ 2 ] ,
81+ notes : row [ 3 ] ,
82+ } ,
83+ } ) ;
84+ } else {
85+ console . log ( " Adding " + row [ 0 ] + "..." ) ;
86+ equipment = farm . asset . create ( {
87+ type : "asset--equipment" ,
88+ attributes : {
89+ name : row [ 0 ] ,
90+ notes : row [ 1 ] ,
91+ } ,
92+ } ) ;
93+ categoryParentId = equipment . id ;
94+ categoryParentName = row [ 0 ] ;
95+ }
7296
7397 try {
74- const result = await farm . asset . send ( categoryParent ) ;
75- categoryParentId = result . id ;
76- categoryParentName = row [ 0 ] ;
98+ const result = await farm . asset . send ( equipment ) ;
7799 } catch ( e ) {
78100 console . log ( "API error sending " + row [ 0 ] ) ;
79101 console . log ( e ) ;
80102 process . exit ( 1 ) ;
81103 }
82104 console . log ( " Added." ) ;
105+
83106 } else if ( row [ 1 ] != "" ) {
84- console . log ( " Adding equipment category " + row [ 1 ] + " to category " + categoryParentName + "..." ) ;
107+ console . log (
108+ " Adding equipment category " +
109+ row [ 1 ] +
110+ " to category " +
111+ categoryParentName +
112+ "..."
113+ ) ;
85114 const category = farm . asset . create ( {
86115 type : "asset--equipment" ,
87116 attributes : {
0 commit comments