Commit 24d53a2a authored by chaiwat's avatar chaiwat

add

parent 32670d9a
...@@ -10,7 +10,7 @@ dotenv.config({ ...@@ -10,7 +10,7 @@ dotenv.config({
module.exports = { module.exports = {
JWT_SECRET: 'secretRepairJWT', JWT_SECRET: 'secretRepairJWT',
EXPIRE_TOKEN: 604800, EXPIRE_TOKEN: 30,
EXPIRE_TOKEN_MEMBER: 604800, EXPIRE_TOKEN_MEMBER: 604800,
HOST: "localhost", HOST: "localhost",
......
module.exports = { module.exports = {
SUCCESS: 200, SUCCESS: 200,
SUCCESS_NO_CONTENT: 204, SUCCESS_NO_CONTENT: 204,
SUCCESS_NO_APPROVE: 205,
SUCCESS_ACCEPTED: 202,
ERROR_BAD_REQUEST: 400, ERROR_BAD_REQUEST: 400,
......
...@@ -41,6 +41,7 @@ router.post("/accesstoken", async (request, response, next) => { ...@@ -41,6 +41,7 @@ router.post("/accesstoken", async (request, response, next) => {
}, },
userData: tokenData, userData: tokenData,
}); });
} else { } else {
response.json({ response.json({
code: 204, code: 204,
...@@ -76,6 +77,7 @@ router.post("/login", async (request, response, next) => { ...@@ -76,6 +77,7 @@ router.post("/login", async (request, response, next) => {
}); });
response.json({ response.json({
_auth: true,
code: 200, code: 200,
message: "login success", message: "login success",
data: { data: {
...@@ -85,18 +87,32 @@ router.post("/login", async (request, response, next) => { ...@@ -85,18 +87,32 @@ router.post("/login", async (request, response, next) => {
userData: tokenData, userData: tokenData,
}); });
//seve user token request.session = [token, tokenData];
// user.token = token
} else if (status == responseCode.SUCCESS_NO_CONTENT) { } else if (status == responseCode.SUCCESS_NO_CONTENT) {
response.json({ response.json({
code: 204, code: 204,
message: "Incorrect Email and/or Password!" message: "Incorrect Email and/or Password!",
}); });
} } else if (status == responseCode.SUCCESS_ACCEPTED) {
else {
response.json({ response.json({
code: 204, _auth: true,
message: "login is not success" code: 202,
message: "Admin Login user",
userData: {
userId: datas.garageID,
email: datas.email,
},
});
} else if (status == responseCode.SUCCESS_NO_APPROVE) {
response.json({
code: 205,
message: "Confirmation is Non-approved!",
});
} else {
response.json({
code: 400,
message: "login is not success",
}); });
} }
}); });
...@@ -106,7 +122,17 @@ router.post("/login", async (request, response, next) => { ...@@ -106,7 +122,17 @@ router.post("/login", async (request, response, next) => {
} }
}); });
router.delete("/accesstoken", async (request, response) => { router.get("/login", async (request, response) => {
const test = request.session;
console.log(test);
response.json({
code: 200,
message: "Destroy accesstoken success",
data: response.session,
});
});
router.delete("/logout", async (request, response) => {
response.json({ response.json({
code: 200, code: 200,
message: "Destroy accesstoken success", message: "Destroy accesstoken success",
......
...@@ -6,6 +6,7 @@ const { ...@@ -6,6 +6,7 @@ const {
callGetGarage, callGetGarage,
callUpdateGarage, callUpdateGarage,
callDeleteGarage, callDeleteGarage,
callGetGarageAll,
} = require("../services/funcCallback"); } = require("../services/funcCallback");
const responseCode = require("../configs/responseCode"); const responseCode = require("../configs/responseCode");
...@@ -55,6 +56,25 @@ router.get("/all", (request, response, next) => { ...@@ -55,6 +56,25 @@ router.get("/all", (request, response, next) => {
} }
}); });
// Get Garage All
router.get("/all-repair", (request, response, next) => {
try {
callGetGarageAll(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 One Garage // Get One Garage
router.get("/getgarage", (request, response, next) => { router.get("/getgarage", (request, response, next) => {
let data = request.body; let data = request.body;
......
...@@ -5,6 +5,7 @@ const { ...@@ -5,6 +5,7 @@ const {
callRegisterMember, callRegisterMember,
callGetMember, callGetMember,
callDeleteMember, callDeleteMember,
callGetMemberByGarage,
} = require("../services/funcCallback"); } = require("../services/funcCallback");
const responseCode = require("../configs/responseCode"); const responseCode = require("../configs/responseCode");
...@@ -43,13 +44,13 @@ router.post("/insert", async (request, response, next) => { ...@@ -43,13 +44,13 @@ router.post("/insert", async (request, response, next) => {
if (status == responseCode.SUCCESS) { if (status == responseCode.SUCCESS) {
response.json({ response.json({
code: 200, code: 200,
message: "insert member success", message: "สมัครสมาชิกให้ลูกค้าเรียบร้อย",
data: datas, data: datas,
}); });
} else { } else {
response.json({ response.json({
code: 204, code: 204,
message: "มี member นี้แล้ว", message: "มีรหัสลูกค้านี้อยู่แล้ว!",
}); });
} }
}); });
...@@ -83,6 +84,31 @@ router.get("/getmember", (request, response, next) => { ...@@ -83,6 +84,31 @@ router.get("/getmember", (request, response, next) => {
} }
}); });
// Get One Member By Garage
router.get("/getmember/member-regis", (request, response, next) => {
let data = request.query;
console.log(data)
try {
callGetMemberByGarage(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 // Delete Member
router.delete("/delete", (request, response, next) => { router.delete("/delete", (request, response, next) => {
let data = request.body; let data = request.body;
......
...@@ -5,22 +5,28 @@ const { ...@@ -5,22 +5,28 @@ const {
callGetallDetail, callGetallDetail,
callGetByMember, callGetByMember,
callGetByGarage, callGetByGarage,
callGetByDetailID,
callSpareDetail,
callGetSpareByDetailID,
callDeleteSpare,
callUpdateDetail,
} = require("../services/funcCallback"); } = require("../services/funcCallback");
const responseCode = require("../configs/responseCode"); const responseCode = require("../configs/responseCode");
const router = express.Router(); const router = express.Router();
// Insert Member // Insert Details
router.post("/insert", async (request, response, next) => { router.post("/insert", async (request, response, next) => {
try { try {
let data = request.body; let data = request.body;
// console.log('555',data)
callRepairDetail(data, function (err, datas, status) { callRepairDetail(data, function (err, datas, status) {
if (status == responseCode.SUCCESS) { if (status == responseCode.SUCCESS) {
response.json({ response.json({
code: 200, code: 200,
message: "insert success", message: "insert success",
data: datas, data: data,
}); });
} else { } else {
response.json({ response.json({
...@@ -37,7 +43,7 @@ router.post("/insert", async (request, response, next) => { ...@@ -37,7 +43,7 @@ router.post("/insert", async (request, response, next) => {
// Get All Detail // Get All Detail
router.get("/all", (request, response, next) => { router.get("/all", (request, response, next) => {
try { try {
callGetallDetail( function (err, datas, status) { callGetallDetail(function (err, datas, status) {
// console.log(status); // console.log(status);
if (status == responseCode.SUCCESS) { if (status == responseCode.SUCCESS) {
response.json({ response.json({
...@@ -55,8 +61,8 @@ router.get("/all", (request, response, next) => { ...@@ -55,8 +61,8 @@ router.get("/all", (request, response, next) => {
// Get By Member // Get By Member
router.get("/getbymember", (request, response, next) => { router.get("/getbymember", (request, response, next) => {
let data = request.body; let data = request.query;
// console.log(data) console.log(data)
try { try {
callGetByMember(data, function (err, datas, status) { callGetByMember(data, function (err, datas, status) {
if (status == responseCode.SUCCESS) { if (status == responseCode.SUCCESS) {
...@@ -78,10 +84,10 @@ router.get("/getbymember", (request, response, next) => { ...@@ -78,10 +84,10 @@ router.get("/getbymember", (request, response, next) => {
} }
}); });
// Get By Member // Get By Garage
router.get("/getbygarage", (request, response, next) => { router.get("/getbygarage", (request, response, next) => {
let data = request.body; let data = request.query;
// console.log(data) // console.log("data", data);
try { try {
callGetByGarage(data, function (err, datas, status) { callGetByGarage(data, function (err, datas, status) {
if (status == responseCode.SUCCESS) { if (status == responseCode.SUCCESS) {
...@@ -95,6 +101,133 @@ router.get("/getbygarage", (request, response, next) => { ...@@ -95,6 +101,133 @@ router.get("/getbygarage", (request, response, next) => {
response.json({ response.json({
code: 500, code: 500,
message: "ไม่มี garage นี้อยู่ในตาราง", message: "ไม่มี garage นี้อยู่ในตาราง",
data: null,
});
}
});
} catch (err) {
console.log(err);
}
});
// Get By GarageID
router.get("/getbydetailID", (request, response, next) => {
let data = request.query;
console.log("data", data);
try {
callGetByDetailID(data, function (err, datas, status) {
if (status == responseCode.SUCCESS) {
response.json({
code: 200,
message: "get data success",
data: datas,
});
} else {
response.json({
code: 500,
message: "ไม่มี garage นี้อยู่ในตาราง",
data: null,
});
}
});
} catch (err) {
console.log(err);
}
});
// Insert Details
router.post("/insert-spare", async (request, response, next) => {
try {
let data = request.body;
// console.log('spare',data)
callSpareDetail(data, function (err, datas, status) {
if (status == responseCode.SUCCESS) {
response.json({
code: 200,
message: "insert spare success",
data: data,
});
} else {
response.json({
code: 204,
message: "sql is not working!!",
});
}
});
} catch (err) {
console.log(err);
}
});
// Get By spare GarageID
router.get("/getspare-detailid", (request, response, next) => {
let data = request.query;
// console.log("data", data);
try {
callGetSpareByDetailID(data, function (err, datas, status) {
if (status == responseCode.SUCCESS) {
response.json({
code: 200,
message: "get data success",
data: datas,
});
} else {
response.json({
code: 500,
message: "ไม่มี garage นี้อยู่ในตาราง",
data: null,
});
}
});
} catch (err) {
console.log(err);
}
});
router.delete("/delete-spare", async (request, response, next) => {
try {
let data = request.body;
console.log('555',data)
callDeleteSpare(data, function (err, datas, status) {
if (status == responseCode.SUCCESS) {
response.json({
code: 200,
message: "ลบสำเร็จ",
data: data,
});
} else {
response.json({
code: 204,
message: "sql is not working!!",
});
}
});
} catch (err) {
console.log(err);
}
});
// Update Garage
router.put("/update-detail", (request, response, next) => {
let data = request.body;
// console.log(data)
try {
callUpdateDetail(data, function (err, datas, status) {
// console.log(status)
if (status == responseCode.SUCCESS) {
response.json({
code: 200,
message: "Update success",
total: datas.length,
data: datas,
});
} else {
response.json({
code: 400,
message: "not success",
}); });
} }
}); });
......
const express = require('express') const express = require("express");
const responseCode = require('../configs/responseCode'); const responseCode = require("../configs/responseCode");
const router = express.Router() const router = express.Router();
const authentication = require('./authentication') const authentication = require("./authentication");
const member = require('./member'); const member = require("./member");
const garage = require('./garage'); const garage = require("./garage");
const repairdetail = require('./repairdetail') const repairdetail = require("./repairdetail");
const report = require('./report') const report = require("./report");
const middleware = require('../middlewares/authentication') const middleware = require("../middlewares/authentication");
router.get("/test", (req, res) => {
const name = req.query.name;
console.log(name);
let timestamp = typeof parseInt(+new Date() / 1000);
res.json({ time: timestamp, code: responseCode.SUCCESS_NO_CONTENT });
console.log("test");
});
router.get('/test',(req,res)=>{ router.use(authentication);
const name = req.query.name router.use(member);
console.log(name) router.use(garage);
let timestamp = typeof parseInt(+new Date()/1000); router.use(repairdetail);
res.json({ time:timestamp,code: responseCode.SUCCESS_NO_CONTENT }) router.use(report);
console.log('test')
})
router.use(authentication) module.exports = router;
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
...@@ -80,6 +80,17 @@ db.connect((err) => { ...@@ -80,6 +80,17 @@ db.connect((err) => {
} else { } else {
console.log("database there is already this table."); console.log("database there is already this table.");
} }
// Check Table reported in DataBase
if (allTable.includes("spare") == false) {
// Create Table
db.query(createTable.spare, (err) => {
if (err) throw err;
console.log("Created table spare successfully.");
});
} else {
console.log("database there is already this table.");
}
}); });
} catch (err) { } catch (err) {
console.log(err); console.log(err);
...@@ -109,8 +120,11 @@ async function registerGarage(data, callback) { ...@@ -109,8 +120,11 @@ async function registerGarage(data, callback) {
data.on_time, data.on_time,
data.off_time, data.off_time,
data.tel, data.tel,
data.confirmation
]; ];
// console.log(data.address_map)
encryptedPassword = await bcrypt.hash(data.password, 10); encryptedPassword = await bcrypt.hash(data.password, 10);
// console.log("test", encryptedPassword); // console.log("test", encryptedPassword);
...@@ -158,6 +172,7 @@ async function registerGarage(data, callback) { ...@@ -158,6 +172,7 @@ async function registerGarage(data, callback) {
data.on_time, data.on_time,
data.off_time, data.off_time,
data.tel, data.tel,
data.confirmation
], ],
(err, result) => { (err, result) => {
if (err) { if (err) {
...@@ -196,8 +211,21 @@ async function loginUser(data, callback) { ...@@ -196,8 +211,21 @@ async function loginUser(data, callback) {
if (results.length != 0) { if (results.length != 0) {
// console.log(results[0].password); // console.log(results[0].password);
if (bcrypt.compareSync(data.password, results[0].password)) { if (bcrypt.compareSync(data.password, results[0].password)) {
console.log("Successful"); // console.log("Successful", results[0].confirmation);
if (results[0].confirmation === 'approve') {
callback(null, results[0], responseCode.SUCCESS); callback(null, results[0], responseCode.SUCCESS);
} else {
if (results[0].garageID === "admin") {
// console.log("Successful", results[0].garageID);
callback(null, results[0], responseCode.SUCCESS_ACCEPTED);
} else {
// console.log("test", results[0].garageID);
callback(null, null, responseCode.SUCCESS_NO_APPROVE);
}
}
} else { } else {
// console.log("Incorrect Email and/or Password!"); // console.log("Incorrect Email and/or Password!");
callback(null, null, responseCode.SUCCESS_NO_CONTENT); callback(null, null, responseCode.SUCCESS_NO_CONTENT);
...@@ -238,7 +266,19 @@ async function loginUser(data, callback) { ...@@ -238,7 +266,19 @@ async function loginUser(data, callback) {
// get All Garage // get All Garage
function getAllGarage(data, callback) { function getAllGarage(data, callback) {
try { try {
db.query("SELECT * FROM garage", function (err, rows) { db.query(`SELECT * FROM garage WHERE confirmation = 'approve' `, function (err, rows) {
if (err) return callback(err);
callback(null, rows, responseCode.SUCCESS);
});
} catch (err) {
console.log(err);
}
}
// get All Garage
function getGarageAll(data, callback) {
try {
db.query(`SELECT * FROM garage `, function (err, rows) {
if (err) return callback(err); if (err) return callback(err);
callback(null, rows, responseCode.SUCCESS); callback(null, rows, responseCode.SUCCESS);
}); });
...@@ -339,6 +379,7 @@ function registerMember(data, callback) { ...@@ -339,6 +379,7 @@ function registerMember(data, callback) {
let dateNow = today.toLocaleDateString(); let dateNow = today.toLocaleDateString();
values = [ values = [
data.party, data.party,
data.garageID,
data.member_tel, data.member_tel,
data.member_name, data.member_name,
data.member_ads, data.member_ads,
...@@ -394,6 +435,22 @@ function getMember(data, callback) { ...@@ -394,6 +435,22 @@ function getMember(data, callback) {
} }
} }
// get one Member By GarageName
function getMemberByGarage(data, callback) {
// console.log(data.userID);
let sql = `SELECT * FROM member WHERE garageID = "${data.userId}"`;
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 // Delete Member
function deleteMember(data, callback) { function deleteMember(data, callback) {
// console.log(data) // console.log(data)
...@@ -417,13 +474,13 @@ function deleteMember(data, callback) { ...@@ -417,13 +474,13 @@ function deleteMember(data, callback) {
// insert RepairDetail // insert RepairDetail
function repairDetail(data, callback) { function repairDetail(data, callback) {
let timeElapsed = Date.now(); // let timeElapsed = Date.now();
let today = new Date(timeElapsed); // let today = new Date(timeElapsed);
let dateNow = today.toLocaleDateString(); // let dateNow = today.toLocaleDateString();
let details = JSON.stringify(data.detail); // let details = JSON.stringify(data.detail);
// console.log(details); // console.log(data);
try { try {
db.query( db.query(
...@@ -432,11 +489,18 @@ function repairDetail(data, callback) { ...@@ -432,11 +489,18 @@ function repairDetail(data, callback) {
data.garageID, data.garageID,
data.member_tel, data.member_tel,
data.device_type, data.device_type,
data.device, data.car_number,
details, data.car_province,
dateNow, data.brand,
data.model,
data.kilo_number,
data.repair_details,
data.repair_date,
data.spare_parts_list,
data.status, data.status,
data.price, data.price,
data.status_payment,
data.equipment,
], ],
(err, result) => { (err, result) => {
if (err) { if (err) {
...@@ -453,6 +517,66 @@ function repairDetail(data, callback) { ...@@ -453,6 +517,66 @@ function repairDetail(data, callback) {
} }
} }
//insert Spare Detail
function spareDetail(data, callback) {
console.log(data);
try {
db.query(
`INSERT INTO spare ( detailsID, spare, member_tel) VALUES (${data.detailsID}, '${data.spare}' , '${data.memberTel}')`,
(err, result) => {
if (err) {
console.log("error", 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 Spare By GarageID
function getSpareByDetailID(data, callback) {
try {
// console.log(detailID)
let sql = `SELECT * FROM spare WHERE detailsID = ${data.detailID}`;
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);
}
}
//Delete Spare
function deleteSpare(data, callback) {
console.log(data);
let sql = `DELETE FROM spare WHERE spareID = '${data.id}'`;
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);
}
}
// Get All Datail // Get All Datail
function getAllDetail(data, callback) { function getAllDetail(data, callback) {
try { try {
...@@ -477,7 +601,7 @@ function getByMember(data, callback) { ...@@ -477,7 +601,7 @@ function getByMember(data, callback) {
let sql = `SELECT * FROM repairdetails AS a let sql = `SELECT * FROM repairdetails AS a
INNER JOIN member AS b ON a.member_tel = b.member_tel INNER JOIN member AS b ON a.member_tel = b.member_tel
INNER JOIN garage AS c ON a.garageID = c.garageID INNER JOIN garage AS c ON a.garageID = c.garageID
WHERE a.member_tel = ${memberTel}`; WHERE a.member_tel = ${memberTel} ORDER BY a.repair_date ASC `;
db.query(sql, function (err, rows) { db.query(sql, function (err, rows) {
if (err) return callback(err); if (err) return callback(err);
...@@ -492,12 +616,32 @@ function getByMember(data, callback) { ...@@ -492,12 +616,32 @@ function getByMember(data, callback) {
// Get By Garage // Get By Garage
function getByGarage(data, callback) { function getByGarage(data, callback) {
try { try {
let garage = data.garageID; let garageID = data.garageID;
// console.log(garage) // console.log(garage)
let sql = `SELECT * FROM repairdetails AS a let sql = `SELECT * FROM repairdetails AS a
INNER JOIN member AS b ON a.member_tel = b.member_tel INNER JOIN member AS b ON a.member_tel = b.member_tel
INNER JOIN garage AS c ON a.garageID = c.garageID INNER JOIN garage AS c ON a.garageID = c.garageID
WHERE a.garageID = "${garage}"`; WHERE a.garageID = "${garageID}" ORDER BY repair_date ASC`;
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 GarageID
function getByDetailID(data, callback) {
try {
let detailID = data.detailID;
// console.log(detailID)
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.detailsID = ${detailID}`;
db.query(sql, function (err, rows) { db.query(sql, function (err, rows) {
if (err) return callback(err); if (err) return callback(err);
...@@ -518,7 +662,7 @@ function insertReport(data, callback) { ...@@ -518,7 +662,7 @@ function insertReport(data, callback) {
let values = [ let values = [
data.party, data.party,
data.user_report, data.user_report,
data.name, data.username,
data.report_detail, data.report_detail,
data.report_tel, data.report_tel,
dateNow, dateNow,
...@@ -553,9 +697,34 @@ function getReport(data, callback) { ...@@ -553,9 +697,34 @@ function getReport(data, callback) {
} }
} }
// Update Detail
function updateDetail(data, callback) {
let sql = `UPDATE repairdetails SET
status = "${data.status}",
price = "${data.sumPrice}",
status_payment = "${data.status_payment}" WHERE detailsID = "${data.detailsID}"
`;
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);
}
}
module.exports = { module.exports = {
registerGarage, registerGarage,
getAllGarage, getAllGarage,
getGarageAll,
getGarage, getGarage,
updateGarage, updateGarage,
deleteGarage, deleteGarage,
...@@ -570,4 +739,10 @@ module.exports = { ...@@ -570,4 +739,10 @@ module.exports = {
insertReport, insertReport,
getReport, getReport,
loginUser, loginUser,
getByDetailID,
spareDetail,
getSpareByDetailID,
deleteSpare,
updateDetail,
getMemberByGarage,
}; };
...@@ -16,7 +16,14 @@ const { ...@@ -16,7 +16,14 @@ const {
getByGarage, getByGarage,
insertReport, insertReport,
getReport, getReport,
loginUser loginUser,
getByDetailID,
spareDetail,
getSpareByDetailID,
deleteSpare,
updateDetail,
getMemberByGarage,
getGarageAll
} = require("./database"); } = require("./database");
//fucntion callback Insert Garage //fucntion callback Insert Garage
...@@ -67,6 +74,21 @@ async function callGetallGarage(callback) { ...@@ -67,6 +74,21 @@ async function callGetallGarage(callback) {
} }
} }
//fucntion callback get all garage
async function callGetGarageAll(callback) {
try {
getGarageAll("result", function (err, result) {
if (err || !result.length) return callback("error or no results");
result = result.map((obj) => obj);
callback(null, result, responseCode.SUCCESS);
});
} catch (err) {
console.log(err);
}
}
//fucntion callback get one garage //fucntion callback get one garage
async function callGetGarage(data, callback) { async function callGetGarage(data, callback) {
// console.log(data) // console.log(data)
...@@ -158,6 +180,22 @@ async function callGetMember(data, callback) { ...@@ -158,6 +180,22 @@ async function callGetMember(data, callback) {
} }
} }
//fucntion callback get one Member
async function callGetMemberByGarage(data, callback) {
// console.log(data)
try {
getMemberByGarage(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 //fucntion callback Delete Member
async function callDeleteMember(data, callback) { async function callDeleteMember(data, callback) {
// console.log(data) // console.log(data)
...@@ -172,7 +210,7 @@ async function callDeleteMember(data, callback) { ...@@ -172,7 +210,7 @@ async function callDeleteMember(data, callback) {
} }
} }
//fucntion callback Insert Member //fucntion callback detail
async function callRepairDetail(data, callback) { async function callRepairDetail(data, callback) {
try { try {
repairDetail(data, function (err, result, status) { repairDetail(data, function (err, result, status) {
...@@ -187,7 +225,22 @@ async function callRepairDetail(data, callback) { ...@@ -187,7 +225,22 @@ async function callRepairDetail(data, callback) {
} }
} }
//fucntion callback get all member //fucntion callback detail
async function callSpareDetail(data, callback) {
try {
spareDetail(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 detail
async function callGetallDetail(callback) { async function callGetallDetail(callback) {
try { try {
getAllDetail("result", function (err, result, status) { getAllDetail("result", function (err, result, status) {
...@@ -231,6 +284,51 @@ async function callGetByGarage(data, callback) { ...@@ -231,6 +284,51 @@ async function callGetByGarage(data, callback) {
} }
} }
//fucntion callback get by garageID
async function callGetByDetailID(data, callback) {
try {
getByDetailID(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 get Spare by detailID
async function callGetSpareByDetailID(data, callback) {
try {
getSpareByDetailID(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 delete spare
async function callDeleteSpare(data, callback) {
// console.log(data)
try {
deleteSpare(data, function (err, result, status) {
// console.log('test', result)
callback(null, result, status);
});
} catch (err) {
console.log(err);
}
}
//fucntion callback Insert report //fucntion callback Insert report
async function callInsertReport(data, callback) { async function callInsertReport(data, callback) {
...@@ -263,6 +361,20 @@ async function callGetReport(callback) { ...@@ -263,6 +361,20 @@ async function callGetReport(callback) {
} }
} }
//fucntion callback update detail
async function callUpdateDetail(data, callback) {
// console.log(data)
try {
updateDetail(data, function (err, result, status) {
// console.log('test', result)
callback(null, result, status);
});
} catch (err) {
console.log(err);
}
}
module.exports = { module.exports = {
callRegisterGarage, callRegisterGarage,
...@@ -280,5 +392,12 @@ module.exports = { ...@@ -280,5 +392,12 @@ module.exports = {
callGetByGarage, callGetByGarage,
callInsertReport, callInsertReport,
callGetReport, callGetReport,
callLoginUser callLoginUser,
callGetByDetailID,
callSpareDetail,
callGetSpareByDetailID,
callDeleteSpare,
callUpdateDetail,
callGetMemberByGarage,
callGetGarageAll
}; };
...@@ -20,12 +20,14 @@ module.exports = { ...@@ -20,12 +20,14 @@ module.exports = {
on_time varchar(100), on_time varchar(100),
off_time varchar(100), off_time varchar(100),
tel varchar(30), tel varchar(30),
confirmation varchar(100),
PRIMARY KEY (garageID) PRIMARY KEY (garageID)
)`, )`,
member: `CREATE TABLE member( member: `CREATE TABLE member(
member_tel varchar(100), member_tel varchar(100),
garageID varchar(100),
party varchar(100), party varchar(100),
member_name varchar(255), member_name varchar(255),
member_ads varchar(255), member_ads varchar(255),
...@@ -40,11 +42,18 @@ module.exports = { ...@@ -40,11 +42,18 @@ module.exports = {
garageID varchar(255), garageID varchar(255),
member_tel varchar(100), member_tel varchar(100),
device_type varchar(255), device_type varchar(255),
device varchar(255), car_number varchar(10),
details varchar(255), car_province varchar(255),
repair_date varchar(255), brand varchar(100),
model varchar(100),
kilo_number varchar(10),
repair_details varchar(255),
repair_date varchar(100),
spare_parts_list varchar(255),
status varchar(100), status varchar(100),
price int(10), price int(10),
status_payment varchar(100),
equipment varchar(100),
PRIMARY KEY (detailsID), PRIMARY KEY (detailsID),
FOREIGN KEY (member_tel) REFERENCES member(member_tel), FOREIGN KEY (member_tel) REFERENCES member(member_tel),
...@@ -62,4 +71,15 @@ module.exports = { ...@@ -62,4 +71,15 @@ module.exports = {
PRIMARY KEY (reportID) PRIMARY KEY (reportID)
)`, )`,
spare: `CREATE TABLE spare(
spareID int(10) NOT NULL AUTO_INCREMENT,
detailsID int(10),
spare varchar(255),
member_tel varchar(100),
PRIMARY KEY (spareID),
FOREIGN KEY (member_tel) REFERENCES member(member_tel),
FOREIGN KEY (detailsID) REFERENCES repairdetails(detailsID)
)`,
}; };
...@@ -20,12 +20,14 @@ module.exports = { ...@@ -20,12 +20,14 @@ module.exports = {
registration_date, registration_date,
on_time, on_time,
off_time, off_time,
tel tel,
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`, confirmation
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`,
insert_member: `INSERT INTO member insert_member: `INSERT INTO member
( (
party, party,
garageID,
member_tel, member_tel,
member_name, member_name,
member_ads, member_ads,
...@@ -38,12 +40,19 @@ module.exports = { ...@@ -38,12 +40,19 @@ module.exports = {
garageID, garageID,
member_tel, member_tel,
device_type, device_type,
device, car_number,
details, car_province,
brand,
model,
kilo_number,
repair_details,
repair_date, repair_date,
spare_parts_list,
status, status,
price price,
) VALUES (?,?,?,?,?,?,?,?)`, status_payment,
equipment
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`,
insert_reported: `INSERT INTO reported insert_reported: `INSERT INTO reported
( (
...@@ -53,5 +62,13 @@ module.exports = { ...@@ -53,5 +62,13 @@ module.exports = {
report_detail, report_detail,
report_tel, report_tel,
report_date report_date
) VALUES (?)` ) VALUES (?)`,
insert_spare: `INSERT INTO spare
(
detailsID,
spares,
member_tel
) VALUES (?, ?, ?)`,
}; };
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