Commit 32670d9a authored by chaiwat's avatar chaiwat

add

parent f2a2757e
......@@ -19,6 +19,8 @@
"homepage": "https://github.com/fuseSavage/RepaiCenter-api#readme",
"dependencies": {
"axios": "^0.24.0",
"bcrypt": "^5.0.1",
"bcryptjs": "^2.4.3",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"date": "^1.0.2",
......
......@@ -9,6 +9,10 @@ dotenv.config({
module.exports = {
JWT_SECRET: 'secretRepairJWT',
EXPIRE_TOKEN: 604800,
EXPIRE_TOKEN_MEMBER: 604800,
HOST: "localhost",
USER: "root",
PASSWORD: "",
......
const express = require("express");
const moment = require("moment");
const jwt = require("jsonwebtoken");
const constants = require("../configs/constants");
const responseCode = require("../configs/responseCode");
const router = express.Router();
const {
callRegisterGarage,
callLoginUser,
} = require("../services/funcCallback");
// router.post('/accesstoken', Validate(createAccesstokenSchema), async (request, response, next) => {
router.post("/accesstoken", async (request, response, next) => {
try {
const data = request.body;
// console.log("data 00000000 ", data);
callRegisterGarage(data, function (err, datas, status) {
// console.log("status ", status);
if (status == responseCode.SUCCESS) {
const expireAt = moment().add(constants.EXPIRE_TOKEN, "seconds");
const tokenData = {
userId: data.garageID,
userName: data.user_name,
garageName: data.garage_name,
email: data.email,
status: status,
};
const token = jwt.sign(tokenData, constants.JWT_SECRET, {
expiresIn: constants.EXPIRE_TOKEN,
});
response.json({
code: 200,
message: "insert garage success",
data: {
token,
expired_at: expireAt,
},
userData: tokenData,
});
} else {
response.json({
code: 204,
message: "มี UserID นี้แล้ว",
});
}
});
} catch (error) {
console.log(error);
}
});
//User Login
router.post("/login", async (request, response, next) => {
try {
//get user input
const data = request.body;
callLoginUser(data, function (err, datas, status) {
// console.log(status);
if (status == responseCode.SUCCESS) {
const expireAt = moment().add(constants.EXPIRE_TOKEN, "seconds");
const tokenData = {
userId: datas.garageID,
userName: datas.user_name,
garageName: datas.garage_name,
email: datas.email,
status: status,
};
const token = jwt.sign(tokenData, constants.JWT_SECRET, {
expiresIn: constants.EXPIRE_TOKEN,
});
response.json({
code: 200,
message: "login success",
data: {
token,
expired_at: expireAt,
},
userData: tokenData,
});
//seve user token
// user.token = token
} else if (status == responseCode.SUCCESS_NO_CONTENT) {
response.json({
code: 204,
message: "Incorrect Email and/or Password!"
});
}
else {
response.json({
code: 204,
message: "login is not success"
});
}
});
// response.status(400).send("Invalid Credentials")
} catch (error) {
console.log(error);
}
});
router.delete("/accesstoken", async (request, response) => {
response.json({
code: 200,
message: "Destroy accesstoken success",
data: response.session,
});
});
module.exports = router;
const express = require("express");
const { registerGarage } = require("../services/database");
const {
callRegisterGarage,
callGetallGarage,
callGetGarage,
callUpdateGarage,
callDeleteGarage,
} = require("../services/funcCallback");
const responseCode = require("../configs/responseCode");
......@@ -14,6 +15,7 @@ const router = express.Router();
router.post("/insert", async (request, response, next) => {
try {
let data = request.body;
// console.log(request.body)
callRegisterGarage(data, function (err, datas, status) {
if (status == responseCode.SUCCESS) {
......@@ -53,7 +55,7 @@ router.get("/all", (request, response, next) => {
}
});
// Get All Garage
// Get One Garage
router.get("/getgarage", (request, response, next) => {
let data = request.body;
// console.log(data)
......@@ -78,4 +80,56 @@ router.get("/getgarage", (request, response, next) => {
}
});
// Update Garage
router.post("/update", (request, response, next) => {
let data = request.body;
// console.log(data)
try {
callUpdateGarage(data, function (err, datas, status) {
// console.log(status)
if (status == responseCode.SUCCESS) {
response.json({
code: 200,
message: "Update garage success",
total: datas.length,
data: datas,
});
} else {
response.json({
code: 400,
message: "Update garage not success",
});
}
});
} catch (err) {
console.log(err);
}
});
// Delete Garage
router.delete("/delete", (request, response, next) => {
let data = request.body;
try {
callDeleteGarage(data, function (err, datas, status) {
// console.log(status)
if (status == responseCode.SUCCESS) {
response.json({
code: 200,
message: "Delete garage success",
total: datas.length,
data: datas,
});
} else {
response.json({
code: 400,
message:
"Delete garage not success มี garageID นี้ อยู่ในประวัติการซ่อมอยู่",
});
}
});
} catch (err) {
console.log(err);
}
});
module.exports = router;
const express = require('express')
const express = require("express");
const {
getallMember,
} = require('../services/database')
const responseCode = require('../configs/responseCode')
callGetallMember,
callRegisterMember,
callGetMember,
callDeleteMember,
} = require("../services/funcCallback");
const responseCode = require("../configs/responseCode");
const router = express.Router()
const router = express.Router();
// Get All Member
router.get("/all", (request, response, next) => {
try {
callGetallMember(function (err, datas, status) {
// console.log(status);
if (status == responseCode.SUCCESS) {
response.json({
code: 200,
message: "get all success",
total: datas.length,
data: datas,
});
} else {
response.json({
code: 400,
message: "nodata",
});
}
});
} catch (err) {
console.log(err);
}
});
// Insert Member
router.post("/insert", async (request, response, next) => {
try {
let data = request.body;
router.get('/all', (request, response, next) => {
console.log(['hello'])
callRegisterMember(data, function (err, datas, status) {
if (status == responseCode.SUCCESS) {
response.json({
code: 200,
message: "insert member success",
data: datas,
});
} else {
response.json({
code: 204,
message: "มี member นี้แล้ว",
});
}
});
} catch (err) {
console.log(err);
}
});
// Get One Member
router.get("/getmember", (request, response, next) => {
let data = request.body;
// console.log(data)
try {
callGetMember(data, function (err, datas, status) {
if (status == responseCode.SUCCESS) {
response.json({
code: 200,
message: "get data success",
total: datas.length,
data: datas,
});
} else {
response.json({
code: 500,
message: "ไม่มี UsesID นี้อยู่ในตาราง",
});
}
});
} catch (err) {
console.log(err);
}
});
// Delete Member
router.delete("/delete", (request, response, next) => {
let data = request.body;
try {
getallMember().then(res => {
if (res.status == responseCode.SUCCESS) {
callDeleteMember(data, function (err, datas, status) {
// console.log(status)
if (status == responseCode.SUCCESS) {
response.json({
code: 200,
message: 'get all success',
})
message: "Delete success",
total: datas.length,
data: datas,
});
} else {
response.json({
code: 400,
message: "ลบไม่ได้ เนื่องจากมี member นี้ในประวัติการซ่อม",
});
}
})
});
} catch (err) {
console.log(err)
console.log(err);
}
})
});
module.exports = router
\ No newline at end of file
module.exports = router;
const express = require("express");
const {
callRepairDetail,
callGetallDetail,
callGetByMember,
callGetByGarage,
} = require("../services/funcCallback");
const responseCode = require("../configs/responseCode");
const router = express.Router();
// Insert Member
router.post("/insert", async (request, response, next) => {
try {
let data = request.body;
callRepairDetail(data, function (err, datas, status) {
if (status == responseCode.SUCCESS) {
response.json({
code: 200,
message: "insert success",
data: datas,
});
} else {
response.json({
code: 204,
message: "sql is not working!!",
});
}
});
} catch (err) {
console.log(err);
}
});
// Get All Detail
router.get("/all", (request, response, next) => {
try {
callGetallDetail( function (err, datas, status) {
// console.log(status);
if (status == responseCode.SUCCESS) {
response.json({
code: 200,
message: "get all success",
total: datas.length,
data: datas,
});
}
});
} catch (err) {
console.log(err);
}
});
// Get By Member
router.get("/getbymember", (request, response, next) => {
let data = request.body;
// console.log(data)
try {
callGetByMember(data, function (err, datas, status) {
if (status == responseCode.SUCCESS) {
response.json({
code: 200,
message: "get data success",
total: datas.length,
data: datas,
});
} else {
response.json({
code: 500,
message: "ไม่มี member นี้อยู่ในตาราง",
});
}
});
} catch (err) {
console.log(err);
}
});
// Get By Member
router.get("/getbygarage", (request, response, next) => {
let data = request.body;
// console.log(data)
try {
callGetByGarage(data, function (err, datas, status) {
if (status == responseCode.SUCCESS) {
response.json({
code: 200,
message: "get data success",
total: datas.length,
data: datas,
});
} else {
response.json({
code: 500,
message: "ไม่มี garage นี้อยู่ในตาราง",
});
}
});
} catch (err) {
console.log(err);
}
});
module.exports = router;
const express = require("express");
const { callInsertReport, callGetReport } = require("../services/funcCallback");
const responseCode = require("../configs/responseCode");
const router = express.Router();
// Insert Member
router.post("/insert", async (request, response, next) => {
try {
let data = request.body;
callInsertReport(data, function (err, datas, status) {
if (status == responseCode.SUCCESS) {
response.json({
code: 200,
message: "insert success",
data: datas,
});
} else {
response.json({
code: 204,
message: "sql is not working!!",
});
}
});
} catch (err) {
console.log(err);
}
});
// Get All Report
router.get("/all", (request, response, next) => {
try {
callGetReport(function (err, datas, status) {
// console.log(status);
if (status == responseCode.SUCCESS) {
response.json({
code: 200,
message: "get all success",
total: datas.length,
data: datas,
});
}
});
} catch (err) {
console.log(err);
}
});
module.exports = router;
const jwt = require("jsonwebtoken");
const constants = require("../configs/constants");
const responseCode = require("../configs/responseCode");
const { ERROR_UNAUTHORIZED } = responseCode;
const auth = (req, res, next) => {
try {
if (!req.headers)
return res.status(ERROR_UNAUTHORIZED).send({
code: ERROR_UNAUTHORIZED,
message: "No headers provided.",
});
const token = req.body.token || req.query.token || req.headers['x-access-token'] || req.headers.authorization;
jwt.verify(token, constants.JWT_SECRET, (err, decoded) => {
if (err) {
return res.status(ERROR_UNAUTHORIZED).send({
code: ERROR_UNAUTHORIZED,
message: "Failed to authenticate token.",
});
}
const { userId, userName, garageName, email, status } = decoded;
console.log(
"userId, status, imageUrl, userName => ",
userId,
userName,
garageName,
email,
status
);
req.session = {
userId,
userName,
garageName,
email,
status,
};
console.log("correct!!!!!!! token");
next();
});
} catch (err) {
return res.status(ERROR_UNAUTHORIZED).send({
code: ERROR_UNAUTHORIZED,
message: 'Failed to authenticate token.'
})
}
};
module.exports = auth;
const express = require('express')
const router = express.Router()
const AuthenticationController = require('../controller/AuthenticationController')
router.use('/authentication', AuthenticationController)
module.exports = router
......@@ -2,8 +2,13 @@ const express = require('express')
const responseCode = require('../configs/responseCode');
const router = express.Router()
const authentication = require('./authentication')
const member = require('./member');
const garage = require('./garage');
const repairdetail = require('./repairdetail')
const report = require('./report')
const middleware = require('../middlewares/authentication')
router.get('/test',(req,res)=>{
......@@ -14,7 +19,10 @@ router.get('/test',(req,res)=>{
console.log('test')
})
router.use(member)
router.use(garage)
router.use(authentication)
router.use(middleware, member)
router.use(middleware, garage)
router.use(middleware, repairdetail)
router.use(middleware, report)
module.exports = router
\ No newline at end of file
// import express from 'express'
const express = require("express");
const router = express.Router();
const RepairDetailController = require("../controller/RepairDetailController");
router.use("/repairdetail", RepairDetailController);
module.exports = router;
// import express from 'express'
const express = require('express')
const router = express.Router()
// import UserController from '../controllers/users/UserController'
const ReportController = require('../controller/ReportController')
router.use('/report', ReportController)
module.exports = router
\ No newline at end of file
const { query } = require("express");
const mysql = require("mysql");
const bcrypt = require("bcrypt");
const constants = require("../configs/constants");
const responseCode = require("../configs/responseCode");
......@@ -19,6 +21,7 @@ const db = mysql.createConnection({
// Import SQL Commmand
const createTable = require("../sql/createTable");
const insertInto = require("../sql/insertInto");
const { exit } = require("yargs");
// DataBase Connected
db.connect((err) => {
......@@ -84,10 +87,10 @@ db.connect((err) => {
});
// insert garage in RepairCenterDB
function registerGarage(data, callback) {
async function registerGarage(data, callback) {
values = [
data.garageID,
data.party,
data.userID,
data.password,
data.user_name,
data.garage_name,
......@@ -107,29 +110,65 @@ function registerGarage(data, callback) {
data.off_time,
data.tel,
];
encryptedPassword = await bcrypt.hash(data.password, 10);
// console.log("test", encryptedPassword);
let garageType = JSON.stringify(data.garage_type);
let adsMap = JSON.stringify(data.address_map);
let timeElapsed = Date.now();
let today = new Date(timeElapsed);
let dateNow = today.toLocaleDateString();
try {
let sql = `SELECT userID FROM garage`;
let sql = `SELECT garageID FROM garage`;
db.query(sql, (error, result) => {
if (error) {
console.log("===>>> Error", err);
console.log("===>>> Error", error);
``;
} else {
// console.log(result)
let listUID = [];
let listGID = [];
result.forEach((doc) => {
listUID.push(doc.userID);
listGID.push(doc.garageID);
});
const checkUID = listUID.includes(data.userID);
if (checkUID === false) {
db.query(insertInto.insert_garage, [values], (err, result) => {
const checkGID = listGID.includes(data.garageID);
if (checkGID === false) {
db.query(
insertInto.insert_garage,
[
data.garageID,
data.party,
encryptedPassword,
data.user_name,
data.garage_name,
data.email,
garageType,
data.address_number,
data.moo,
data.alley,
data.road,
data.sub_district,
data.district,
data.province,
data.pos_code,
adsMap,
dateNow,
data.on_time,
data.off_time,
data.tel,
],
(err, result) => {
if (err) {
return callback(err);
// console.log(err);
} else {
callback(null, values, responseCode.SUCCESS);
// console.log("5555555");
// console.log("insert success");
}
});
}
);
} else {
// console.log("มี userID นี้แล้ว");
callback(null, result, responseCode.SUCCESS_NO_CONTENT);
......@@ -141,6 +180,61 @@ function registerGarage(data, callback) {
}
}
// Login user
async function loginUser(data, callback) {
// console.log(data);
try {
if (data.garageID && data.password) {
db.query(
"SELECT * FROM garage WHERE garageID = ?",
[data.garageID],
(error, results, fields) => {
if (error) {
console.log("error =>", error);
}
if (results.length != 0) {
// console.log(results[0].password);
if (bcrypt.compareSync(data.password, results[0].password)) {
console.log("Successful");
callback(null, results[0], responseCode.SUCCESS);
} else {
// console.log("Incorrect Email and/or Password!");
callback(null, null, responseCode.SUCCESS_NO_CONTENT);
}
} else {
callback(null, null, responseCode.ERROR_BAD_REQUEST);
}
}
);
} else {
console.log("Please enter Username and Password!");
}
// console.log(sql);
// db.query(sql, async (err, rows) => {
// // console.log(rows);
// if (err) {
// callback(err);
// } else {
// if (
// data.garageID = rows.garageID &&
// data.password == (await bcrypt.compare(data.password, rows.password))
// ) {
// console.log(rows.password);
// callback(null, rows, responseCode.SUCCESS);
// } else {
// console.log("rows", rows.password);
// callback(null, null, responseCode.SUCCESS_NO_CONTENT);
// }
// }
// });
} catch (err) {
console.log(err);
}
}
// get All Garage
function getAllGarage(data, callback) {
try {
......@@ -156,7 +250,7 @@ function getAllGarage(data, callback) {
// get one Garage
function getGarage(data, callback) {
// console.log(data.userID);
let sql = `SELECT * FROM garage WHERE userID = "${data.userID}"`;
let sql = `SELECT * FROM garage WHERE garageID = "${data.garageID}"`;
try {
db.query(sql, function (err, rows) {
if (err) return callback(err);
......@@ -167,36 +261,293 @@ function getGarage(data, callback) {
}
}
// insert Product
async function insertProduct(data) {
console.log("register ", data);
// Update garage
function updateGarage(data, callback) {
let sql = `UPDATE garage SET
garageID = "${data.garageID}",
user_name = "${data.user_name}",
garage_name = "${data.garage_name}",
email = "${data.email}",
garage_type = "${data.garage_type}",
address_number = "${data.address_number}",
moo = "${data.moo}",
alley = "${data.alley}",
road = "${data.road}",
sub_district = "${data.sub_district}",
district = "${data.district}",
province = "${data.province}",
pos_code = "${data.pos_code}",
address_map = "${data.address_map}",
on_time = "${data.on_time}",
off_time = "${data.off_time}",
tel = "${data.tel}" WHERE garageID = "${data.garageID}"
`;
try {
db.query("SELECT * FROM repairapi", (err, result) => {
if (err) {
console.log("===>>> Error");
// console.log(sql, data.garageID)
db.query(sql, (error, result) => {
if (error) {
// console.log("error",error);
callback(null, result, responseCode.ERROR_BAD_REQUEST);
} else {
console.log("===>> suss", result);
// console.log("good");
callback(null, data, responseCode.SUCCESS);
}
});
} catch (err) {
console.log(err);
}
}
return { status: responseCode.SUCCESS };
// Delete Garage
function deleteGarage(data, callback) {
// console.log(data)
let sql = `DELETE FROM garage WHERE garageID = "${data.garageID}"`;
try {
// console.log(sql, data.garageID)
db.query(sql, (error, result) => {
if (error) {
// console.log("error", error);
callback(null, result, responseCode.ERROR_BAD_REQUEST);
} else {
// console.log("good");
callback(null, data, responseCode.SUCCESS);
}
});
} catch (err) {
console.log(err);
}
}
// Get All Member
async function getallMember() {
function getAllMember(data, callback) {
try {
db.query("SELECT * FROM member", function (err, rows) {
if (err) return callback(err);
callback(null, rows, responseCode.SUCCESS);
});
} catch (err) {
console.log(err);
}
}
// insert Member register
function registerMember(data, callback) {
let timeElapsed = Date.now();
let today = new Date(timeElapsed);
let dateNow = today.toLocaleDateString();
values = [
data.party,
data.member_tel,
data.member_name,
data.member_ads,
data.shop_register,
dateNow,
];
try {
let sql = `SELECT member_tel FROM member`;
db.query(sql, (error, result) => {
if (error) {
console.log("===>>> Error", error);
``;
} else {
// console.log(result)
let listUID = [];
result.forEach((doc) => {
listUID.push(doc.member_tel);
});
const check = listUID.includes(data.member_tel);
if (check === false) {
db.query(insertInto.insert_member, [values], (err, result) => {
if (err) {
return callback(err);
} else {
callback(null, values, responseCode.SUCCESS);
console.log("insert success");
}
});
} else {
console.log("มี userID นี้แล้ว");
callback(null, result, responseCode.SUCCESS_NO_CONTENT);
}
}
});
} catch (err) {
console.log(err);
}
}
// get one Member
function getMember(data, callback) {
// console.log(data.userID);
let sql = `SELECT * FROM member WHERE member_tel = "${data.member_tel}"`;
try {
db.query(sql, function (err, rows, status) {
if (err) return callback(err);
// console.log(rows)
callback(null, rows, responseCode.SUCCESS);
});
} catch (err) {
console.log(err);
}
}
// Delete Member
function deleteMember(data, callback) {
// console.log(data)
let sql = `DELETE FROM member WHERE member_tel = "${data.member_tel}"`;
try {
// console.log(sql, data.garageID)
db.query(sql, (error, result) => {
if (error) {
// console.log("err", error);
callback(null, result, responseCode.ERROR_BAD_REQUEST);
} else {
// console.log("good");
callback(null, data, responseCode.SUCCESS);
}
});
} catch (err) {
console.log(err);
}
}
// insert RepairDetail
function repairDetail(data, callback) {
let timeElapsed = Date.now();
let today = new Date(timeElapsed);
let dateNow = today.toLocaleDateString();
let details = JSON.stringify(data.detail);
// console.log(details);
try {
db.query(
insertInto.insert_detail,
[
data.garageID,
data.member_tel,
data.device_type,
data.device,
details,
dateNow,
data.status,
data.price,
],
(err, result) => {
if (err) {
callback(null, null, responseCode.SUCCESS_NO_CONTENT);
console.log("err", err);
} else {
callback(null, null, responseCode.SUCCESS);
// console.log("insert success");
}
}
);
} catch (err) {
console.log(err);
}
}
// Get All Datail
function getAllDetail(data, callback) {
try {
let sql = `SELECT * FROM repairdetails AS a
INNER JOIN member AS b ON a.member_tel = b.member_tel
INNER JOIN garage AS c ON a.garageID = c.garageID`;
db.query(sql, function (err, rows) {
// if (err) return callback(err);
if (err) console.log(err);
callback(null, rows, responseCode.SUCCESS);
});
} catch (err) {
console.log(err);
}
}
// Get By Member
function getByMember(data, callback) {
try {
let memberTel = data.member_tel;
// console.log(memberTel)
let sql = `SELECT * FROM repairdetails AS a
INNER JOIN member AS b ON a.member_tel = b.member_tel
INNER JOIN garage AS c ON a.garageID = c.garageID
WHERE a.member_tel = ${memberTel}`;
db.query(sql, function (err, rows) {
if (err) return callback(err);
// if (err) console.log(err);
callback(null, rows, responseCode.SUCCESS);
});
} catch (err) {
console.log(err);
}
}
// Get By Garage
function getByGarage(data, callback) {
try {
db.query("SELECT * FROM repairapi", (err, result) => {
let garage = data.garageID;
// console.log(garage)
let sql = `SELECT * FROM repairdetails AS a
INNER JOIN member AS b ON a.member_tel = b.member_tel
INNER JOIN garage AS c ON a.garageID = c.garageID
WHERE a.garageID = "${garage}"`;
db.query(sql, function (err, rows) {
if (err) return callback(err);
// if (err) console.log(err);
callback(null, rows, responseCode.SUCCESS);
});
} catch (err) {
console.log(err);
}
}
// insert Report
function insertReport(data, callback) {
let timeElapsed = Date.now();
let today = new Date(timeElapsed);
let dateNow = today.toLocaleDateString();
let values = [
data.party,
data.user_report,
data.name,
data.report_detail,
data.report_tel,
dateNow,
];
// console.log(data)
try {
db.query(insertInto.insert_reported, [values], (err, result) => {
if (err) {
console.log("===>>> Error");
callback(null, null, responseCode.SUCCESS_NO_CONTENT);
console.log("err", err);
} else {
console.log("===>> suss", result);
callback(null, null, responseCode.SUCCESS);
// console.log("insert success");
}
});
} catch (err) {
console.log(err);
}
}
return { status: responseCode.SUCCESS };
// Get All Report
function getReport(data, callback) {
try {
db.query("SELECT * FROM reported", function (err, rows) {
if (err) return callback(err);
callback(null, rows, responseCode.SUCCESS);
});
} catch (err) {
console.log(err);
}
......@@ -206,6 +557,17 @@ module.exports = {
registerGarage,
getAllGarage,
getGarage,
insertProduct,
getallMember,
updateGarage,
deleteGarage,
getAllMember,
registerMember,
getMember,
deleteMember,
repairDetail,
getAllDetail,
getByMember,
getByGarage,
insertReport,
getReport,
loginUser,
};
const responseCode = require("../configs/responseCode");
const { getAllGarage, getGarage, registerGarage } = require("./database");
const {
getAllGarage,
getGarage,
registerGarage,
updateGarage,
deleteGarage,
getAllMember,
registerMember,
getMember,
deleteMember,
repairDetail,
getAllDetail,
getByMember,
getByGarage,
insertReport,
getReport,
loginUser
} = require("./database");
//fucntion callback Insert Garage
async function callRegisterGarage(data, callback) {
try {
// console.log(data)
registerGarage(data, function (err, result, status) {
if (err || !result.length) return callback("error or no results");
if (err || !result.length) {
// callback("error or no results");
console.log('55555')
}
result = result.map((obj) => obj);
// console.log(result)
callback(null, result, status);
});
} catch (err) {
console.log(err);
}
}
//fucntion callback Login User Garage
async function callLoginUser(data, callback) {
try {
// console.log(data)
loginUser(data, function (err, result, status) {
callback(null, result, status);
});
} catch (err) {
console.log(err);
}
}
//fucntion callback get all garage
async function callGetallGarage(callback) {
......@@ -35,7 +62,6 @@ async function callGetallGarage(callback) {
callback(null, result, responseCode.SUCCESS);
});
} catch (err) {
console.log(err);
}
......@@ -57,9 +83,202 @@ async function callGetGarage(data, callback) {
}
}
//fucntion callback Update Garage
async function callUpdateGarage(data, callback) {
// console.log(data)
try {
updateGarage(data, function (err, result, status) {
// console.log('test', result)
callback(null, result, status);
});
} catch (err) {
console.log(err);
}
}
//fucntion callback Delete Garage
async function callDeleteGarage(data, callback) {
// console.log(data)
try {
deleteGarage(data, function (err, result, status) {
// console.log('test', result)
callback(null, result, status);
});
} catch (err) {
console.log(err);
}
}
//fucntion callback get all member
async function callGetallMember(callback) {
try {
getAllMember("result", function (err, result, status) {
if (err || !result.length) return callback("error or no results");
result = result.map((obj) => obj);
// console.log(result);
callback(null, result, status);
});
} catch (err) {
console.log(err);
}
}
//fucntion callback Insert Member
async function callRegisterMember(data, callback) {
try {
registerMember(data, function (err, result, status) {
if (err || !result.length) return callback("error or no results");
result = result.map((obj) => obj);
callback(null, result, status);
});
} catch (err) {
console.log(err);
}
}
//fucntion callback get one Member
async function callGetMember(data, callback) {
// console.log(data)
try {
getMember(data, function (err, result, status) {
if (err || !result.length) return callback("error or no results");
result = result.map((obj) => obj);
callback(null, result, status);
});
} catch (err) {
console.log(err);
}
}
//fucntion callback Delete Member
async function callDeleteMember(data, callback) {
// console.log(data)
try {
deleteMember(data, function (err, result, status) {
// console.log('test', result)
callback(null, result, status);
});
} catch (err) {
console.log(err);
}
}
//fucntion callback Insert Member
async function callRepairDetail(data, callback) {
try {
repairDetail(data, function (err, result, status) {
// if (err || !result.length) return callback("error or no results");
// result = result.map((obj) => obj);
callback(null, result, status);
});
} catch (err) {
console.log(err);
}
}
//fucntion callback get all member
async function callGetallDetail(callback) {
try {
getAllDetail("result", function (err, result, status) {
if (err || !result.length) return callback("error or no results");
result = result.map((obj) => obj);
callback(null, result, status);
});
} catch (err) {
console.log(err);
}
}
//fucntion callback get by member
async function callGetByMember(data, callback) {
try {
getByMember(data , function (err, result, status) {
if (err || !result.length) return callback("error or no results");
result = result.map((obj) => obj);
callback(null, result, status);
});
} catch (err) {
console.log(err);
}
}
//fucntion callback get by garage
async function callGetByGarage(data, callback) {
try {
getByGarage(data , function (err, result, status) {
if (err || !result.length) return callback("error or no results");
result = result.map((obj) => obj);
// console.log(result)
callback(null, result, status);
});
} catch (err) {
console.log(err);
}
}
//fucntion callback Insert report
async function callInsertReport(data, callback) {
try {
insertReport(data, function (err, result, status) {
// if (err || !result.length) return callback("error or no results");
// result = result.map((obj) => obj);
callback(null, result, status);
});
} catch (err) {
console.log(err);
}
}
//fucntion callback get all member
async function callGetReport(callback) {
try {
getReport("result", function (err, result, status) {
if (err || !result.length) return callback("error or no results");
result = result.map((obj) => obj);
// console.log(result);
callback(null, result, status);
});
} catch (err) {
console.log(err);
}
}
module.exports = {
callRegisterGarage,
callGetallGarage,
callGetGarage,
callUpdateGarage,
callDeleteGarage,
callGetallMember,
callRegisterMember,
callGetMember,
callDeleteMember,
callRepairDetail,
callGetallDetail,
callGetByMember,
callGetByGarage,
callInsertReport,
callGetReport,
callLoginUser
};
module.exports = {
garage: `CREATE TABLE garage(
garageID int NOT NULL AUTO_INCREMENT,
garageID varchar(255),
party varchar(100),
userID varchar(255),
password int NOT NULL,
password varchar(100),
user_name varchar(255),
garage_name varchar(255),
email varchar(255),
......@@ -17,7 +16,7 @@ module.exports = {
province varchar(100),
pos_code varchar(100),
address_map varchar(255),
registration_date DATETIME,
registration_date varchar(100),
on_time varchar(100),
off_time varchar(100),
tel varchar(30),
......@@ -26,36 +25,40 @@ module.exports = {
)`,
member: `CREATE TABLE member(
memberID int NOT NULL AUTO_INCREMENT,
party varchar(100),
member_tel varchar(100),
party varchar(100),
member_name varchar(255),
member_ads varchar(255),
shop_register varchar(255),
registration_date DATETIME,
registration_date varchar(100),
PRIMARY KEY (memberID)
PRIMARY KEY (member_tel)
)`,
repairDetails: `CREATE TABLE repairdetails(
detailsID int NOT NULL AUTO_INCREMENT,
shop_repair varchar(255),
garageID varchar(255),
member_tel varchar(100),
device_type varchar(255),
device varchar(255),
details varchar(255),
repair_date DATETIME,
repair_date varchar(255),
status varchar(100),
price int(10),
PRIMARY KEY (detailsID)
PRIMARY KEY (detailsID),
FOREIGN KEY (member_tel) REFERENCES member(member_tel),
FOREIGN KEY (garageID) REFERENCES garage(garageID)
)`,
reported: `CREATE TABLE reported(
reportID int NOT NULL AUTO_INCREMENT,
party varchar(100),
user_report varchar(255),
name varchar(255),
report_detail varchar(255),
report_date DATETIME,
report_tel varchar(50),
report_date varchar(100),
PRIMARY KEY (reportID)
)`,
......
module.exports = {
insert_garage: `INSERT INTO garage
(
garageID,
party,
userID,
password,
user_name,
garage_name,
......@@ -21,5 +21,37 @@ module.exports = {
on_time,
off_time,
tel
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`,
insert_member: `INSERT INTO member
(
party,
member_tel,
member_name,
member_ads,
shop_register,
registration_date
) VALUES (?)`,
insert_detail: `INSERT INTO repairdetails
(
garageID,
member_tel,
device_type,
device,
details,
repair_date,
status,
price
) VALUES (?,?,?,?,?,?,?,?)`,
insert_reported: `INSERT INTO reported
(
party,
user_report,
name,
report_detail,
report_tel,
report_date
) VALUES (?)`
}
\ No newline at end of file
};
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment