Hail, Ionites!
I am trying to make an app that will allow IT staff at my university to scan barcodes and then use that as a primary key in a MySQL database. I have designed and built the database, but the app is no more than a not-so-glorified barcode scanner that has no real functionality for the intended purpose.
I had watched a tutorial on youtube by Alex of CodeCast on how to do this using node.js and MySQL, linked here.
I tried to paste my edited version of the tutorial code into the typescript file of a new page designed for one of my database actions, but I got errors up the wazoo, presumably because there is a bigger difference between a *.js file and a *.ts file than I had originally thought.
My question is:
- Can I use the *.js files as they are, and not be required to convert them into *.ts files?
I am just learning how to develop for mobile platforms, and I hadnât done any javascript coding until about a week ago, so I appreciate any constructive criticism or friendly advice.
home.ts
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { BarcodeScanner } from '@ionic-native/barcode-scanner';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController,
private barcodeScanner: BarcodeScanner) {
}
barcodeData: any;
scanResult: any;
goToFetch() {
this.navCtrl.push('page-fetch');
}
goToUpdate() {
this.navCtrl.push('page-update');
}
ScanBarcode() {
this.barcodeScanner.scan().then((barcodeData) => {
console.log("Scan Successful: " + barcodeData.text);
this.scanResult = barcodeData.text;
//alert("Scan Successful: " + this.scanResult);
}, (err) => {
console.error("Scan Failure: " + err);
alert("Scan Failure: " + err);
return;
});
}
}
insert.js
var mysql = require('mysql');
var connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '',
database: 'assetdb'
});
connection.connect();
var asset = {
asset_tag: scanResult,
asset_type: ,
deployment_cycle: ,
year_issued: ,
manufacturer: ,
model: ,
asset_location: ,
asset_department:
}
var query = connection.query('insert into assets set ?', asset, function (err, result) {
if (err) {
console.error(err);
return;
}
console.error(result);
console.log(query.sql);
});
select.js
var mysql = require('mysql');
var connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '',
database: 'assetdb'
});
connection.connect();
var asset = {
asset_tag = scanResult,
}
var query = connection.query('select a.*, c.* from assets a join computers c on a.asset_tag = c.asset_tag where a.asset_tag = ?', asset_tag, function (err, result) {
if (err) {
console.error(err);
return;
}
console.error(result);
console.log(query.sql);
});
Thank you in advance! I hope to get this sorted out soon!
PS- If you have need of any further information that is relevant to answering my question, please donât hesitate to ask!