added login , update scan, added user
This commit is contained in:
6
.env
Executable file
6
.env
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
URL = http://192.168.20.45
|
||||||
|
PORT = 3000
|
||||||
|
DB_HOST = localhost
|
||||||
|
DB_USER = kicap
|
||||||
|
DB_PASS = '12345'
|
||||||
|
DB_NAME = db_rfid
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
|
|
||||||
|
27
index.js
27
index.js
@ -3,9 +3,10 @@ const http = require('http');
|
|||||||
const cors = require('cors');
|
const cors = require('cors');
|
||||||
const dotenv = require('dotenv');
|
const dotenv = require('dotenv');
|
||||||
const fileUpload = require('express-fileupload');
|
const fileUpload = require('express-fileupload');
|
||||||
|
const socket = require('./socket');
|
||||||
const app = express();
|
const app = express();
|
||||||
const server = http.createServer(app);
|
const server = http.createServer(app);
|
||||||
|
const io = socket.init(server);
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
@ -18,10 +19,11 @@ app.use(cors());
|
|||||||
app.get('/', (req, res) => {
|
app.get('/', (req, res) => {
|
||||||
console.log("Hello World!");
|
console.log("Hello World!");
|
||||||
res.send('Hello World!');
|
res.send('Hello World!');
|
||||||
})
|
});
|
||||||
|
|
||||||
app.use('/scan', require('./routes/scan_routes'));
|
app.use('/scan', require('./routes/scan_routes'));
|
||||||
|
app.use('/login', require('./routes/login_routes'));
|
||||||
|
app.use('/user', require('./routes/user_routes'));
|
||||||
|
|
||||||
// app error handler
|
// app error handler
|
||||||
app.use((err, req, res, next) => {
|
app.use((err, req, res, next) => {
|
||||||
@ -29,11 +31,26 @@ app.use((err, req, res, next) => {
|
|||||||
res.status(500).send('Something broke!');
|
res.status(500).send('Something broke!');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
io.on('connection', (socket) => {
|
||||||
|
let userID = socket.id;
|
||||||
|
console.log('A user connected: ' + userID);
|
||||||
|
|
||||||
module.exports = { app, server };
|
socket.on('scan_dia', (data) => {
|
||||||
|
console.log('Received scan_dia event: ' + data);
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('disconnect', () => {
|
||||||
|
console.log('User disconnected: ' + userID);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
app,
|
||||||
|
server,
|
||||||
|
io
|
||||||
|
};
|
||||||
const port = process.env.PORT || 3000;
|
const port = process.env.PORT || 3000;
|
||||||
|
|
||||||
server.listen(port, () => {
|
server.listen(port, () => {
|
||||||
console.log(`Server running on port ${port}`);
|
console.log(`Server running on port ${port}`);
|
||||||
})
|
});
|
||||||
|
329
package-lock.json
generated
329
package-lock.json
generated
@ -15,8 +15,37 @@
|
|||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"express-fileupload": "^1.4.3",
|
"express-fileupload": "^1.4.3",
|
||||||
"express-form-data": "^2.0.23",
|
"express-form-data": "^2.0.23",
|
||||||
|
"md5": "^2.3.0",
|
||||||
"mysql": "^2.18.1",
|
"mysql": "^2.18.1",
|
||||||
"nodemon": "^3.1.0"
|
"nodemon": "^3.1.0",
|
||||||
|
"socket.io": "^4.7.5",
|
||||||
|
"socket.io-client": "^4.7.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@socket.io/component-emitter": {
|
||||||
|
"version": "3.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@socket.io/component-emitter/-/component-emitter-3.1.0.tgz",
|
||||||
|
"integrity": "sha512-+9jVqKhRSpsc591z5vX+X5Yyw+he/HCB4iQ/RYxw35CEPaY1gnsNE43nf9n9AaYjAQrTiI/mOwKUKdUs9vf7Xg=="
|
||||||
|
},
|
||||||
|
"node_modules/@types/cookie": {
|
||||||
|
"version": "0.4.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.4.1.tgz",
|
||||||
|
"integrity": "sha512-XW/Aa8APYr6jSVVA1y/DEIZX0/GMKLEVekNG727R8cs56ahETkRAy/3DR7+fJyh7oUgGwNQaRfXCun0+KbWY7Q=="
|
||||||
|
},
|
||||||
|
"node_modules/@types/cors": {
|
||||||
|
"version": "2.8.17",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.17.tgz",
|
||||||
|
"integrity": "sha512-8CGDvrBj1zgo2qE+oS3pOCyYNqCPryMWY2bGfwA0dcfopWGgxs+78df0Rs3rc9THP4JkOhLsAa+15VdpAqkcUA==",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@types/node": {
|
||||||
|
"version": "20.11.30",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.30.tgz",
|
||||||
|
"integrity": "sha512-dHM6ZxwlmuZaRmUPfv1p+KrdD1Dci04FbdEm/9wEMouFqxYoFl5aMkt0VMAUtYRQDyYvD41WJLukhq/ha3YuTw==",
|
||||||
|
"dependencies": {
|
||||||
|
"undici-types": "~5.26.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/abbrev": {
|
"node_modules/abbrev": {
|
||||||
@ -66,6 +95,14 @@
|
|||||||
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
|
||||||
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw=="
|
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw=="
|
||||||
},
|
},
|
||||||
|
"node_modules/base64id": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/base64id/-/base64id-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-lGe34o6EHj9y3Kts9R4ZYs/Gr+6N7MCaMlIFA3F1R2O5/m7K06AxfSeO5530PEERE6/WyEg3lsuyw4GHlPZHog==",
|
||||||
|
"engines": {
|
||||||
|
"node": "^4.5.0 || >= 5.9"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/bignumber.js": {
|
"node_modules/bignumber.js": {
|
||||||
"version": "9.0.0",
|
"version": "9.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.0.tgz",
|
||||||
@ -162,6 +199,14 @@
|
|||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/charenc": {
|
||||||
|
"version": "0.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/charenc/-/charenc-0.0.2.tgz",
|
||||||
|
"integrity": "sha512-yrLQ/yVUFXkzg7EDQsPieE/53+0RlaWTs+wBrvW36cyilJ2SaDWfl4Yj7MtLTXleV9uEKefbAGUPv2/iWSooRA==",
|
||||||
|
"engines": {
|
||||||
|
"node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/chokidar": {
|
"node_modules/chokidar": {
|
||||||
"version": "3.6.0",
|
"version": "3.6.0",
|
||||||
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz",
|
||||||
@ -317,6 +362,14 @@
|
|||||||
"node": ">= 0.10"
|
"node": ">= 0.10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/crypt": {
|
||||||
|
"version": "0.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/crypt/-/crypt-0.0.2.tgz",
|
||||||
|
"integrity": "sha512-mCxBlsHFYh9C+HVpiEacem8FEBnMXgU9gy4zmNC+SXAZNB/1idgp/aulFJ4FgCi7GPEVbfyng092GqL2k2rmow==",
|
||||||
|
"engines": {
|
||||||
|
"node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/debug": {
|
"node_modules/debug": {
|
||||||
"version": "2.6.9",
|
"version": "2.6.9",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||||
@ -382,6 +435,96 @@
|
|||||||
"node": ">= 0.8"
|
"node": ">= 0.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/engine.io": {
|
||||||
|
"version": "6.5.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.5.4.tgz",
|
||||||
|
"integrity": "sha512-KdVSDKhVKyOi+r5uEabrDLZw2qXStVvCsEB/LN3mw4WFi6Gx50jTyuxYVCwAAC0U46FdnzP/ScKRBTXb/NiEOg==",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/cookie": "^0.4.1",
|
||||||
|
"@types/cors": "^2.8.12",
|
||||||
|
"@types/node": ">=10.0.0",
|
||||||
|
"accepts": "~1.3.4",
|
||||||
|
"base64id": "2.0.0",
|
||||||
|
"cookie": "~0.4.1",
|
||||||
|
"cors": "~2.8.5",
|
||||||
|
"debug": "~4.3.1",
|
||||||
|
"engine.io-parser": "~5.2.1",
|
||||||
|
"ws": "~8.11.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10.2.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/engine.io-client": {
|
||||||
|
"version": "6.5.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/engine.io-client/-/engine.io-client-6.5.3.tgz",
|
||||||
|
"integrity": "sha512-9Z0qLB0NIisTRt1DZ/8U2k12RJn8yls/nXMZLn+/N8hANT3TcYjKFKcwbw5zFQiN4NTde3TSY9zb79e1ij6j9Q==",
|
||||||
|
"dependencies": {
|
||||||
|
"@socket.io/component-emitter": "~3.1.0",
|
||||||
|
"debug": "~4.3.1",
|
||||||
|
"engine.io-parser": "~5.2.1",
|
||||||
|
"ws": "~8.11.0",
|
||||||
|
"xmlhttprequest-ssl": "~2.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/engine.io-client/node_modules/debug": {
|
||||||
|
"version": "4.3.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
||||||
|
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"ms": "2.1.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"supports-color": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/engine.io-client/node_modules/ms": {
|
||||||
|
"version": "2.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||||
|
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||||
|
},
|
||||||
|
"node_modules/engine.io-parser": {
|
||||||
|
"version": "5.2.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-5.2.2.tgz",
|
||||||
|
"integrity": "sha512-RcyUFKA93/CXH20l4SoVvzZfrSDMOTUS3bWVpTt2FuFP+XYrL8i8oonHP7WInRyVHXh0n/ORtoeiE1os+8qkSw==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/engine.io/node_modules/cookie": {
|
||||||
|
"version": "0.4.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz",
|
||||||
|
"integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/engine.io/node_modules/debug": {
|
||||||
|
"version": "4.3.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
||||||
|
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"ms": "2.1.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"supports-color": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/engine.io/node_modules/ms": {
|
||||||
|
"version": "2.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||||
|
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||||
|
},
|
||||||
"node_modules/es-define-property": {
|
"node_modules/es-define-property": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz",
|
||||||
@ -747,6 +890,11 @@
|
|||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/is-buffer": {
|
||||||
|
"version": "1.1.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
|
||||||
|
"integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w=="
|
||||||
|
},
|
||||||
"node_modules/is-extglob": {
|
"node_modules/is-extglob": {
|
||||||
"version": "2.1.1",
|
"version": "2.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz",
|
||||||
@ -801,6 +949,16 @@
|
|||||||
"node": ">=10"
|
"node": ">=10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/md5": {
|
||||||
|
"version": "2.3.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/md5/-/md5-2.3.0.tgz",
|
||||||
|
"integrity": "sha512-T1GITYmFaKuO91vxyoQMFETst+O71VUPEU3ze5GNzDm0OWdP8v1ziTaAEPUr/3kLsY3Sftgz242A1SetQiDL7g==",
|
||||||
|
"dependencies": {
|
||||||
|
"charenc": "0.0.2",
|
||||||
|
"crypt": "0.0.2",
|
||||||
|
"is-buffer": "~1.1.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/media-typer": {
|
"node_modules/media-typer": {
|
||||||
"version": "0.3.0",
|
"version": "0.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
|
||||||
@ -1290,6 +1448,142 @@
|
|||||||
"node": ">=10"
|
"node": ">=10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/socket.io": {
|
||||||
|
"version": "4.7.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.7.5.tgz",
|
||||||
|
"integrity": "sha512-DmeAkF6cwM9jSfmp6Dr/5/mfMwb5Z5qRrSXLpo3Fq5SqyU8CMF15jIN4ZhfSwu35ksM1qmHZDQ/DK5XTccSTvA==",
|
||||||
|
"dependencies": {
|
||||||
|
"accepts": "~1.3.4",
|
||||||
|
"base64id": "~2.0.0",
|
||||||
|
"cors": "~2.8.5",
|
||||||
|
"debug": "~4.3.2",
|
||||||
|
"engine.io": "~6.5.2",
|
||||||
|
"socket.io-adapter": "~2.5.2",
|
||||||
|
"socket.io-parser": "~4.2.4"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10.2.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/socket.io-adapter": {
|
||||||
|
"version": "2.5.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-2.5.4.tgz",
|
||||||
|
"integrity": "sha512-wDNHGXGewWAjQPt3pyeYBtpWSq9cLE5UW1ZUPL/2eGK9jtse/FpXib7epSTsz0Q0m+6sg6Y4KtcFTlah1bdOVg==",
|
||||||
|
"dependencies": {
|
||||||
|
"debug": "~4.3.4",
|
||||||
|
"ws": "~8.11.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/socket.io-adapter/node_modules/debug": {
|
||||||
|
"version": "4.3.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
||||||
|
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"ms": "2.1.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"supports-color": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/socket.io-adapter/node_modules/ms": {
|
||||||
|
"version": "2.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||||
|
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||||
|
},
|
||||||
|
"node_modules/socket.io-client": {
|
||||||
|
"version": "4.7.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/socket.io-client/-/socket.io-client-4.7.5.tgz",
|
||||||
|
"integrity": "sha512-sJ/tqHOCe7Z50JCBCXrsY3I2k03iOiUe+tj1OmKeD2lXPiGH/RUCdTZFoqVyN7l1MnpIzPrGtLcijffmeouNlQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"@socket.io/component-emitter": "~3.1.0",
|
||||||
|
"debug": "~4.3.2",
|
||||||
|
"engine.io-client": "~6.5.2",
|
||||||
|
"socket.io-parser": "~4.2.4"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/socket.io-client/node_modules/debug": {
|
||||||
|
"version": "4.3.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
||||||
|
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"ms": "2.1.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"supports-color": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/socket.io-client/node_modules/ms": {
|
||||||
|
"version": "2.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||||
|
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||||
|
},
|
||||||
|
"node_modules/socket.io-parser": {
|
||||||
|
"version": "4.2.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.2.4.tgz",
|
||||||
|
"integrity": "sha512-/GbIKmo8ioc+NIWIhwdecY0ge+qVBSMdgxGygevmdHj24bsfgtCmcUUcQ5ZzcylGFHsN3k4HB4Cgkl96KVnuew==",
|
||||||
|
"dependencies": {
|
||||||
|
"@socket.io/component-emitter": "~3.1.0",
|
||||||
|
"debug": "~4.3.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/socket.io-parser/node_modules/debug": {
|
||||||
|
"version": "4.3.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
||||||
|
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"ms": "2.1.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"supports-color": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/socket.io-parser/node_modules/ms": {
|
||||||
|
"version": "2.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||||
|
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||||
|
},
|
||||||
|
"node_modules/socket.io/node_modules/debug": {
|
||||||
|
"version": "4.3.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
||||||
|
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"ms": "2.1.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"supports-color": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/socket.io/node_modules/ms": {
|
||||||
|
"version": "2.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||||
|
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||||
|
},
|
||||||
"node_modules/sqlstring": {
|
"node_modules/sqlstring": {
|
||||||
"version": "2.3.1",
|
"version": "2.3.1",
|
||||||
"resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.1.tgz",
|
||||||
@ -1396,6 +1690,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz",
|
||||||
"integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA=="
|
"integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA=="
|
||||||
},
|
},
|
||||||
|
"node_modules/undici-types": {
|
||||||
|
"version": "5.26.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",
|
||||||
|
"integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA=="
|
||||||
|
},
|
||||||
"node_modules/universalify": {
|
"node_modules/universalify": {
|
||||||
"version": "2.0.1",
|
"version": "2.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz",
|
||||||
@ -1433,6 +1732,34 @@
|
|||||||
"node": ">= 0.8"
|
"node": ">= 0.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/ws": {
|
||||||
|
"version": "8.11.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/ws/-/ws-8.11.0.tgz",
|
||||||
|
"integrity": "sha512-HPG3wQd9sNQoT9xHyNCXoDUa+Xw/VevmY9FoHyQ+g+rrMn4j6FB4np7Z0OhdTgjx6MgQLK7jwSy1YecU1+4Asg==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10.0.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"bufferutil": "^4.0.1",
|
||||||
|
"utf-8-validate": "^5.0.2"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"bufferutil": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"utf-8-validate": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/xmlhttprequest-ssl": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/xmlhttprequest-ssl/-/xmlhttprequest-ssl-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-QKxVRxiRACQcVuQEYFsI1hhkrMlrXHPegbbd1yn9UHOmRxY+si12nQYzri3vbzt8VdTTRviqcKxcyllFas5z2A==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.4.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/yallist": {
|
"node_modules/yallist": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
|
||||||
|
@ -17,7 +17,10 @@
|
|||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"express-fileupload": "^1.4.3",
|
"express-fileupload": "^1.4.3",
|
||||||
"express-form-data": "^2.0.23",
|
"express-form-data": "^2.0.23",
|
||||||
|
"md5": "^2.3.0",
|
||||||
"mysql": "^2.18.1",
|
"mysql": "^2.18.1",
|
||||||
"nodemon": "^3.1.0"
|
"nodemon": "^3.1.0",
|
||||||
|
"socket.io": "^4.7.5",
|
||||||
|
"socket.io-client": "^4.7.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
51
routes/login_routes.js
Executable file
51
routes/login_routes.js
Executable file
@ -0,0 +1,51 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
const dotenv = require('dotenv');
|
||||||
|
const mysql = require('mysql');
|
||||||
|
const md5 = require('md5');
|
||||||
|
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
|
||||||
|
// Connect to the MySQL database
|
||||||
|
const connection = mysql.createConnection({
|
||||||
|
host: process.env.DB_HOST,
|
||||||
|
user: process.env.DB_USER,
|
||||||
|
password: process.env.DB_PASS,
|
||||||
|
database: process.env.DB_NAME
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
router.get('/', (req, res) => {
|
||||||
|
console.log("Get test");
|
||||||
|
res.send('Login get test');
|
||||||
|
})
|
||||||
|
|
||||||
|
router.post('/', async (req, res) => {
|
||||||
|
const { username, password } = req.body
|
||||||
|
// change password to string
|
||||||
|
// password = password.toString();
|
||||||
|
const query = 'SELECT * FROM tb_login_penyewa WHERE nik = ? AND password = ?';
|
||||||
|
|
||||||
|
connection.query(query, [username, md5(password)], (error, results) => {
|
||||||
|
if (error) {
|
||||||
|
console.log('error login', error);
|
||||||
|
return res.status(500).json({ error: 'Internal server error' ,status : false});
|
||||||
|
}
|
||||||
|
if (results.length === 0) {
|
||||||
|
return res.status(401).json({ error: 'Invalid username or password' ,status : false});
|
||||||
|
}
|
||||||
|
const query_data = 'SELECT * FROM tb_penyewa where nik = ?';
|
||||||
|
|
||||||
|
connection.query(query_data, [username], (error, results) => {
|
||||||
|
if (error) {
|
||||||
|
console.log('error ambil data penyewa', error);
|
||||||
|
return res.status(500).json({ error: 'Internal server error' ,status : false});
|
||||||
|
}
|
||||||
|
return res.json({ success: true, data: results[0] ,status : true});
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = router
|
@ -1,10 +1,191 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
const dotenv = require('dotenv');
|
||||||
|
const mysql = require('mysql');
|
||||||
|
|
||||||
|
const socket = require('../socket');
|
||||||
|
// const socket_client = socket.socket_client;
|
||||||
|
const io = socket.getIO();
|
||||||
|
|
||||||
|
// const io_sock = require("socket.io-client");
|
||||||
|
|
||||||
|
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
// const socket = io_sock("http://localhost:"+process.env.PORT);
|
||||||
|
|
||||||
|
// Connect to the MySQL database
|
||||||
|
const connection = mysql.createConnection({
|
||||||
|
host: process.env.DB_HOST,
|
||||||
|
user: process.env.DB_USER,
|
||||||
|
password: process.env.DB_PASS,
|
||||||
|
database: process.env.DB_NAME
|
||||||
|
});
|
||||||
|
|
||||||
router.post('/', (req, res) => {
|
router.post('/', (req, res) => {
|
||||||
let { uid } = req.body
|
let { uid } = req.body;
|
||||||
console.log(uid);
|
console.log('Emitting scan_dia event: ' + uid);
|
||||||
return res.json({ success: true , uid: uid})
|
io.emit('scan', uid); // Emitting event using the io instance
|
||||||
|
// socket.emit('scan_dia', uid);
|
||||||
|
// socket_client.emit('scan_dia', uid);
|
||||||
|
return res.json({ success: true, uid: uid });
|
||||||
|
});
|
||||||
|
|
||||||
|
router.get('/tempat_sewa' , (req, res) => {
|
||||||
|
const query = 'SELECT * FROM tb_tempat_sewa a join tb_penyewa b on a.nik=b.nik;';
|
||||||
|
connection.query(query, (error, results) => {
|
||||||
|
if (error) {
|
||||||
|
console.log('error cek tempat sewa', error);
|
||||||
|
return res.status(500).json({message : 'Internal server error' ,status : false});
|
||||||
|
}
|
||||||
|
return res.json({ success: true, data: results ,status : true});
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
module.exports = router;
|
router.get('/id/:id' , (req, res) => {
|
||||||
|
const { id } = req.params;
|
||||||
|
const query = 'SELECT * FROM tb_tempat_sewa a join tb_penyewa b on a.nik=b.nik where b.rfid = ?';
|
||||||
|
connection.query(query, [id], (error, results) => {
|
||||||
|
if (error) {
|
||||||
|
console.log('error cek id rfid', error);
|
||||||
|
return res.status(500).json({message : 'Internal server error' ,status : false});
|
||||||
|
}
|
||||||
|
return res.json({ success: true, data: results ,status : true});
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
router.post('/bayar' , (req, res) => {
|
||||||
|
const { nik, id_tempat_sewa , rfid} = req.body;
|
||||||
|
console.log(nik, id_tempat_sewa, rfid);
|
||||||
|
const query_select = 'SELECT * FROM tb_tempat_sewa a join tb_penyewa b on a.nik=b.nik where b.rfid = ? and a.id_tempat_serwa = ? and b.nik = ?';
|
||||||
|
connection.query(query_select, [rfid , id_tempat_sewa, nik], (error, results) => {
|
||||||
|
if (error) {
|
||||||
|
console.log('error cek id rfid', error);
|
||||||
|
return res.status(500).json({message : 'Internal server error' ,status : false});
|
||||||
|
}
|
||||||
|
if (results.length === 0) {
|
||||||
|
return res.status(401).json({message : 'Data tidak ditemukan' ,status : false});
|
||||||
|
}
|
||||||
|
// console.log(results[0]);
|
||||||
|
const saldo_terdahulu = results[0].saldo;
|
||||||
|
if (results[0].harga_sewa > saldo_terdahulu) {
|
||||||
|
return res.status(401).json({message : 'Saldo tidak mencukupi' ,status : false });
|
||||||
|
}
|
||||||
|
const saldo_terkini = saldo_terdahulu - results[0].harga_sewa;
|
||||||
|
const query_update = 'UPDATE tb_penyewa SET saldo = ? WHERE nik = ?';
|
||||||
|
connection.query(query_update, [saldo_terkini, nik], (error, results_update) => {
|
||||||
|
if (error) {
|
||||||
|
console.log('error bayar', error);
|
||||||
|
return res.status(500).json({message : 'Internal server error' ,status : false});
|
||||||
|
}
|
||||||
|
// console.log(results_update);
|
||||||
|
const ket = 'Pembayaran Retribusi Dilakukan oleh penyewa : ' + results[0].nik+' - '+results[0].nama + ' - '+results[0].rfid + ' dengan tempat sewa : ' + results[0].nama_tempat_sewa+ '\nSaldo sebelumnya : ' + saldo_terdahulu + '\nSaldo setelah bayar : ' + saldo_terkini;
|
||||||
|
const jenis = 'Pembayaran Retribusi';
|
||||||
|
const query_log = 'INSERT INTO tb_log_history (nik, id_tempat_serwa, ket,jenis) VALUES (?, ?, ?, ?)';
|
||||||
|
connection.query(query_log, [nik, id_tempat_sewa, ket, jenis], (error, results) => {
|
||||||
|
if (error) {
|
||||||
|
console.log('error log', error);
|
||||||
|
return res.status(500).json({message : 'Internal server error' ,status : false});
|
||||||
|
}
|
||||||
|
return res.json({ success: true, data: results ,status : true , message : 'Pembayaran retribusi berhasil dilakukan'});
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
router.get('/log' , (req, res) => {
|
||||||
|
const query_log = 'SELECT * FROM tb_log_history a join tb_penyewa b on a.nik = b.nik'
|
||||||
|
connection.query(query_log, (error, results) => {
|
||||||
|
if (error) {
|
||||||
|
console.log('error log', error);
|
||||||
|
return res.status(500).json({message : 'Internal server error' ,status : false});
|
||||||
|
}
|
||||||
|
return res.json({ success: true, data: results ,status : true});
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
router.get('/penyewa' , (req, res) => {
|
||||||
|
const query_penyewa = 'SELECT * FROM tb_penyewa';
|
||||||
|
connection.query(query_penyewa, (error, results) => {
|
||||||
|
if (error) {
|
||||||
|
console.log('error log', error);
|
||||||
|
return res.status(500).json({message : 'Internal server error' ,status : false});
|
||||||
|
}
|
||||||
|
return res.json({ success: true, data: results ,status : true});
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
router.post('/penyewa/:nik' , (req, res) => {
|
||||||
|
const { nik } = req.params;
|
||||||
|
const { topup } = req.body;
|
||||||
|
const query_penyewa = 'SELECT * FROM tb_penyewa where nik = ?';
|
||||||
|
// console.log(nik, topup);
|
||||||
|
connection.query(query_penyewa, [nik], (error, results) => {
|
||||||
|
if (error) {
|
||||||
|
console.log('error log', error);
|
||||||
|
return res.status(500).json({message : 'Internal server error' ,status : false});
|
||||||
|
}
|
||||||
|
if (results.length === 0) {
|
||||||
|
return res.status(401).json({message : 'Data tidak ditemukan' ,status : false});
|
||||||
|
}
|
||||||
|
const saldo_terdahulu = results[0].saldo;
|
||||||
|
// parse integer
|
||||||
|
const saldo_terkini = parseInt(saldo_terdahulu) + parseInt(topup);
|
||||||
|
// console.log(saldo_terkini, saldo_terdahulu);
|
||||||
|
// console.log(results);
|
||||||
|
|
||||||
|
const query_update = 'UPDATE tb_penyewa SET saldo = ? WHERE nik = ?';
|
||||||
|
connection.query(query_update, [saldo_terkini, nik], (error, results_update) => {
|
||||||
|
if (error) {
|
||||||
|
console.log('error bayar', error);
|
||||||
|
return res.status(500).json({message : 'Internal server error' ,status : false});
|
||||||
|
}
|
||||||
|
const query_log = 'INSERT INTO tb_log_history (nik, ket,jenis) VALUES (?, ?, ?)';
|
||||||
|
const jenis = 'Top Up Saldo';
|
||||||
|
const ket = 'Top Up Saldo dilakukan oleh penyewa : ' + results[0].nik+' - '+results[0].nama + ' - '+results[0].rfid + ' dengan nominal : ' + topup + '\nSaldo sebelumnya : ' + saldo_terdahulu + '\nSaldo setelah topup : ' + saldo_terkini;
|
||||||
|
|
||||||
|
console.log(ket);
|
||||||
|
console.log(jenis);
|
||||||
|
|
||||||
|
|
||||||
|
connection.query(query_log, [nik, ket,jenis], (error, results_log) => {
|
||||||
|
if (error) {
|
||||||
|
console.log('error log', error);
|
||||||
|
return res.status(500).json({message : 'Internal server error' ,status : false});
|
||||||
|
}
|
||||||
|
return res.json({ success: true,status : true , message : 'Top Up Saldo berhasil dilakukan'});
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
router.put('/penyewa/:nik' , (req, res) => {
|
||||||
|
const { nik } = req.params;
|
||||||
|
const {nik_baru , nama} = req.body;
|
||||||
|
|
||||||
|
const query_select = 'SELECT * FROM tb_penyewa where nik = ?';
|
||||||
|
|
||||||
|
connection.query(query_select, [nik], (error, results) => {
|
||||||
|
if (error) {
|
||||||
|
console.log('error select', error);
|
||||||
|
return res.status(500).json({message : 'Internal server error' ,status : false});
|
||||||
|
}
|
||||||
|
if (results.length === 0) {
|
||||||
|
return res.status(401).json({message : 'Data tidak ditemukan' ,status : false});
|
||||||
|
}
|
||||||
|
const query_update = 'UPDATE tb_penyewa SET nik = ? , nama = ? WHERE nik = ?';
|
||||||
|
connection.query(query_update, [nik_baru, nama, nik], (error, results_update) => {
|
||||||
|
if (error) {
|
||||||
|
console.log('error update data penyewa', error);
|
||||||
|
return res.status(500).json({message : 'Internal server error' ,status : false});
|
||||||
|
}
|
||||||
|
return res.json({ success: true,status : true , message : 'Perubahan data penyewa berhasil dilakukan'});
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
|
74
routes/user_routes.js
Executable file
74
routes/user_routes.js
Executable file
@ -0,0 +1,74 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
const dotenv = require('dotenv');
|
||||||
|
const mysql = require('mysql');
|
||||||
|
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
const connection = mysql.createConnection({
|
||||||
|
host: process.env.DB_HOST,
|
||||||
|
user: process.env.DB_USER,
|
||||||
|
password: process.env.DB_PASS,
|
||||||
|
database: process.env.DB_NAME
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
router.get('/log_user/:nik', (req, res) => {
|
||||||
|
const { nik } = req.params;
|
||||||
|
const query = 'SELECT * FROM tb_penyewa where nik = ?';
|
||||||
|
connection.query(query, [nik], (error, results) => {
|
||||||
|
if (error) {
|
||||||
|
console.log('error cek log user', error);
|
||||||
|
return res.status(500).json({message : 'Internal server error' ,status : false});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (results.length == 0) {
|
||||||
|
return res.status(404).json({message : 'User not found' ,status : false});
|
||||||
|
}
|
||||||
|
|
||||||
|
const query_log = 'SELECT * FROM tb_log_history a join tb_penyewa b on a.nik = b.nik where b.nik = ?';
|
||||||
|
|
||||||
|
connection.query(query_log, [nik], (error, results_log) => {
|
||||||
|
if (error) {
|
||||||
|
console.log('error cek log user', error);
|
||||||
|
return res.status(500).json({message : 'Internal server error' ,status : false});
|
||||||
|
}
|
||||||
|
return res.json({ success: true, data: results_log ,status : true});
|
||||||
|
})
|
||||||
|
|
||||||
|
// return res.json({ success: true, data: results ,status : true});
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
router.get('/tempat_sewa/:nik', (req, res) => {
|
||||||
|
const { nik } = req.params;
|
||||||
|
const query = 'SELECT * FROM tb_tempat_sewa a join tb_penyewa b on a.nik=b.nik where b.nik = ?';
|
||||||
|
connection.query(query, [nik], (error, results) => {
|
||||||
|
if (error) {
|
||||||
|
console.log('error cek tempat sewa', error);
|
||||||
|
return res.status(500).json({message : 'Internal server error' ,status : false});
|
||||||
|
}
|
||||||
|
return res.json({ success: true, data: results ,status : true});
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
router.get('/user/:nik' , (req, res) => {
|
||||||
|
const { nik } = req.params;
|
||||||
|
const query = 'SELECT * FROM tb_penyewa where nik = ?';
|
||||||
|
connection.query(query, [nik], (error, results) => {
|
||||||
|
if (error) {
|
||||||
|
console.log('error cek user', error);
|
||||||
|
return res.status(500).json({message : 'Internal server error' ,status : false});
|
||||||
|
}
|
||||||
|
if (results.length == 0) {
|
||||||
|
return res.status(404).json({message : 'User not found' ,status : false});
|
||||||
|
}
|
||||||
|
return res.json({ success: true, data: results[0] ,status : true});
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = router
|
||||||
|
|
||||||
|
|
||||||
|
|
29
socket.js
Executable file
29
socket.js
Executable file
@ -0,0 +1,29 @@
|
|||||||
|
const socketio = require('socket.io');
|
||||||
|
const socketio_client = require('socket.io-client');
|
||||||
|
const dotenv = require('dotenv');
|
||||||
|
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
const socket_client = socketio_client("http://localhost:"+process.env.PORT);
|
||||||
|
|
||||||
|
let io;
|
||||||
|
|
||||||
|
function init(server) {
|
||||||
|
io = socketio(server);
|
||||||
|
return io;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getIO() {
|
||||||
|
if (!io) {
|
||||||
|
throw new Error('Socket.io not initialized');
|
||||||
|
}
|
||||||
|
return io;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
init,
|
||||||
|
getIO,
|
||||||
|
socket_client
|
||||||
|
};
|
Reference in New Issue
Block a user