Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
R
RepaiCenter-api
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chaiwat
RepaiCenter-api
Commits
24d53a2a
Commit
24d53a2a
authored
Feb 26, 2022
by
chaiwat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add
parent
32670d9a
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
608 additions
and
71 deletions
+608
-71
constants.js
src/configs/constants.js
+1
-1
responseCode.js
src/configs/responseCode.js
+3
-0
AuthenticationController.js
src/controller/AuthenticationController.js
+34
-8
GarageController.js
src/controller/GarageController.js
+20
-0
MemberController.js
src/controller/MemberController.js
+28
-2
RepairDetailController.js
src/controller/RepairDetailController.js
+141
-8
index.js
src/routes/index.js
+22
-24
database.js
src/services/database.js
+189
-14
funcCallback.js
src/services/funcCallback.js
+123
-4
createTable.js
src/sql/createTable.js
+23
-3
insertInto.js
src/sql/insertInto.js
+24
-7
No files found.
src/configs/constants.js
View file @
24d53a2a
...
...
@@ -10,7 +10,7 @@ dotenv.config({
module
.
exports
=
{
JWT_SECRET
:
'secretRepairJWT'
,
EXPIRE_TOKEN
:
60480
0
,
EXPIRE_TOKEN
:
3
0
,
EXPIRE_TOKEN_MEMBER
:
604800
,
HOST
:
"localhost"
,
...
...
src/configs/responseCode.js
View file @
24d53a2a
module
.
exports
=
{
SUCCESS
:
200
,
SUCCESS_NO_CONTENT
:
204
,
SUCCESS_NO_APPROVE
:
205
,
SUCCESS_ACCEPTED
:
202
,
ERROR_BAD_REQUEST
:
400
,
...
...
src/controller/AuthenticationController.js
View file @
24d53a2a
...
...
@@ -41,6 +41,7 @@ router.post("/accesstoken", async (request, response, next) => {
},
userData
:
tokenData
,
});
}
else
{
response
.
json
({
code
:
204
,
...
...
@@ -76,6 +77,7 @@ router.post("/login", async (request, response, next) => {
});
response
.
json
({
_auth
:
true
,
code
:
200
,
message
:
"login success"
,
data
:
{
...
...
@@ -85,18 +87,32 @@ router.post("/login", async (request, response, next) => {
userData
:
tokenData
,
});
//seve user token
// user.token = token
request
.
session
=
[
token
,
tokenData
];
}
else
if
(
status
==
responseCode
.
SUCCESS_NO_CONTENT
)
{
response
.
json
({
code
:
204
,
message
:
"Incorrect Email and/or Password!"
message
:
"Incorrect Email and/or Password!"
,
});
}
else
{
}
else
if
(
status
==
responseCode
.
SUCCESS_ACCEPTED
)
{
response
.
json
({
code
:
204
,
message
:
"login is not success"
_auth
:
true
,
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) => {
}
});
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
({
code
:
200
,
message
:
"Destroy accesstoken success"
,
...
...
src/controller/GarageController.js
View file @
24d53a2a
...
...
@@ -6,6 +6,7 @@ const {
callGetGarage
,
callUpdateGarage
,
callDeleteGarage
,
callGetGarageAll
,
}
=
require
(
"../services/funcCallback"
);
const
responseCode
=
require
(
"../configs/responseCode"
);
...
...
@@ -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
router
.
get
(
"/getgarage"
,
(
request
,
response
,
next
)
=>
{
let
data
=
request
.
body
;
...
...
src/controller/MemberController.js
View file @
24d53a2a
...
...
@@ -5,6 +5,7 @@ const {
callRegisterMember
,
callGetMember
,
callDeleteMember
,
callGetMemberByGarage
,
}
=
require
(
"../services/funcCallback"
);
const
responseCode
=
require
(
"../configs/responseCode"
);
...
...
@@ -43,13 +44,13 @@ router.post("/insert", async (request, response, next) => {
if
(
status
==
responseCode
.
SUCCESS
)
{
response
.
json
({
code
:
200
,
message
:
"
insert member success
"
,
message
:
"
สมัครสมาชิกให้ลูกค้าเรียบร้อย
"
,
data
:
datas
,
});
}
else
{
response
.
json
({
code
:
204
,
message
:
"มี
member นี้แล้ว
"
,
message
:
"มี
รหัสลูกค้านี้อยู่แล้ว!
"
,
});
}
});
...
...
@@ -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
router
.
delete
(
"/delete"
,
(
request
,
response
,
next
)
=>
{
let
data
=
request
.
body
;
...
...
src/controller/RepairDetailController.js
View file @
24d53a2a
...
...
@@ -5,22 +5,28 @@ const {
callGetallDetail
,
callGetByMember
,
callGetByGarage
,
callGetByDetailID
,
callSpareDetail
,
callGetSpareByDetailID
,
callDeleteSpare
,
callUpdateDetail
,
}
=
require
(
"../services/funcCallback"
);
const
responseCode
=
require
(
"../configs/responseCode"
);
const
router
=
express
.
Router
();
// Insert
Member
// Insert
Details
router
.
post
(
"/insert"
,
async
(
request
,
response
,
next
)
=>
{
try
{
let
data
=
request
.
body
;
// console.log('555',data)
callRepairDetail
(
data
,
function
(
err
,
datas
,
status
)
{
if
(
status
==
responseCode
.
SUCCESS
)
{
response
.
json
({
code
:
200
,
message
:
"insert success"
,
data
:
data
s
,
data
:
data
,
});
}
else
{
response
.
json
({
...
...
@@ -37,7 +43,7 @@ router.post("/insert", async (request, response, next) => {
// Get All Detail
router
.
get
(
"/all"
,
(
request
,
response
,
next
)
=>
{
try
{
callGetallDetail
(
function
(
err
,
datas
,
status
)
{
callGetallDetail
(
function
(
err
,
datas
,
status
)
{
// console.log(status);
if
(
status
==
responseCode
.
SUCCESS
)
{
response
.
json
({
...
...
@@ -55,8 +61,8 @@ router.get("/all", (request, response, next) => {
// Get By Member
router
.
get
(
"/getbymember"
,
(
request
,
response
,
next
)
=>
{
let
data
=
request
.
bod
y
;
//
console.log(data)
let
data
=
request
.
quer
y
;
console
.
log
(
data
)
try
{
callGetByMember
(
data
,
function
(
err
,
datas
,
status
)
{
if
(
status
==
responseCode
.
SUCCESS
)
{
...
...
@@ -78,10 +84,10 @@ router.get("/getbymember", (request, response, next) => {
}
});
// Get By
Member
// Get By
Garage
router
.
get
(
"/getbygarage"
,
(
request
,
response
,
next
)
=>
{
let
data
=
request
.
bod
y
;
// console.log(
data)
let
data
=
request
.
quer
y
;
// console.log(
"data", data);
try
{
callGetByGarage
(
data
,
function
(
err
,
datas
,
status
)
{
if
(
status
==
responseCode
.
SUCCESS
)
{
...
...
@@ -95,6 +101,133 @@ router.get("/getbygarage", (request, response, next) => {
response
.
json
({
code
:
500
,
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"
,
});
}
});
...
...
src/routes/index.js
View file @
24d53a2a
const
express
=
require
(
'express'
)
const
responseCode
=
require
(
'../configs/responseCode'
);
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
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'
)
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
)
=>
{
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
.
use
(
authentication
);
router
.
use
(
member
);
router
.
use
(
garage
);
router
.
use
(
repairdetail
);
router
.
use
(
report
);
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
module
.
exports
=
router
;
src/services/database.js
View file @
24d53a2a
...
...
@@ -80,6 +80,17 @@ db.connect((err) => {
}
else
{
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
)
{
console
.
log
(
err
);
...
...
@@ -109,8 +120,11 @@ async function registerGarage(data, callback) {
data
.
on_time
,
data
.
off_time
,
data
.
tel
,
data
.
confirmation
];
// console.log(data.address_map)
encryptedPassword
=
await
bcrypt
.
hash
(
data
.
password
,
10
);
// console.log("test", encryptedPassword);
...
...
@@ -158,6 +172,7 @@ async function registerGarage(data, callback) {
data
.
on_time
,
data
.
off_time
,
data
.
tel
,
data
.
confirmation
],
(
err
,
result
)
=>
{
if
(
err
)
{
...
...
@@ -196,8 +211,21 @@ async function loginUser(data, callback) {
if
(
results
.
length
!=
0
)
{
// console.log(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
);
}
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
{
// console.log("Incorrect Email and/or Password!");
callback
(
null
,
null
,
responseCode
.
SUCCESS_NO_CONTENT
);
...
...
@@ -238,7 +266,19 @@ async function loginUser(data, callback) {
// get All Garage
function
getAllGarage
(
data
,
callback
)
{
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
);
callback
(
null
,
rows
,
responseCode
.
SUCCESS
);
});
...
...
@@ -339,6 +379,7 @@ function registerMember(data, callback) {
let
dateNow
=
today
.
toLocaleDateString
();
values
=
[
data
.
party
,
data
.
garageID
,
data
.
member_tel
,
data
.
member_name
,
data
.
member_ads
,
...
...
@@ -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
function
deleteMember
(
data
,
callback
)
{
// console.log(data)
...
...
@@ -417,13 +474,13 @@ function deleteMember(data, callback) {
// insert RepairDetail
function
repairDetail
(
data
,
callback
)
{
let
timeElapsed
=
Date
.
now
();
let
today
=
new
Date
(
timeElapsed
);
let
dateNow
=
today
.
toLocaleDateString
();
//
let timeElapsed = Date.now();
//
let today = new Date(timeElapsed);
//
let dateNow = today.toLocaleDateString();
let
details
=
JSON
.
stringify
(
data
.
detail
);
//
let details = JSON.stringify(data.detail);
// console.log(d
etails
);
// console.log(d
ata
);
try
{
db
.
query
(
...
...
@@ -432,11 +489,18 @@ function repairDetail(data, callback) {
data
.
garageID
,
data
.
member_tel
,
data
.
device_type
,
data
.
device
,
details
,
dateNow
,
data
.
car_number
,
data
.
car_province
,
data
.
brand
,
data
.
model
,
data
.
kilo_number
,
data
.
repair_details
,
data
.
repair_date
,
data
.
spare_parts_list
,
data
.
status
,
data
.
price
,
data
.
status_payment
,
data
.
equipment
,
],
(
err
,
result
)
=>
{
if
(
err
)
{
...
...
@@ -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
function
getAllDetail
(
data
,
callback
)
{
try
{
...
...
@@ -477,7 +601,7 @@ function getByMember(data, callback) {
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
}
`
;
WHERE a.member_tel =
${
memberTel
}
ORDER BY a.repair_date ASC
`
;
db
.
query
(
sql
,
function
(
err
,
rows
)
{
if
(
err
)
return
callback
(
err
);
...
...
@@ -492,12 +616,32 @@ function getByMember(data, callback) {
// Get By Garage
function
getByGarage
(
data
,
callback
)
{
try
{
let
garage
=
data
.
garageID
;
let
garage
ID
=
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
}
"`
;
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
)
{
if
(
err
)
return
callback
(
err
);
...
...
@@ -518,7 +662,7 @@ function insertReport(data, callback) {
let
values
=
[
data
.
party
,
data
.
user_report
,
data
.
name
,
data
.
user
name
,
data
.
report_detail
,
data
.
report_tel
,
dateNow
,
...
...
@@ -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
=
{
registerGarage
,
getAllGarage
,
getGarageAll
,
getGarage
,
updateGarage
,
deleteGarage
,
...
...
@@ -570,4 +739,10 @@ module.exports = {
insertReport
,
getReport
,
loginUser
,
getByDetailID
,
spareDetail
,
getSpareByDetailID
,
deleteSpare
,
updateDetail
,
getMemberByGarage
,
};
src/services/funcCallback.js
View file @
24d53a2a
...
...
@@ -16,7 +16,14 @@ const {
getByGarage
,
insertReport
,
getReport
,
loginUser
loginUser
,
getByDetailID
,
spareDetail
,
getSpareByDetailID
,
deleteSpare
,
updateDetail
,
getMemberByGarage
,
getGarageAll
}
=
require
(
"./database"
);
//fucntion callback Insert Garage
...
...
@@ -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
async
function
callGetGarage
(
data
,
callback
)
{
// console.log(data)
...
...
@@ -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
async
function
callDeleteMember
(
data
,
callback
)
{
// console.log(data)
...
...
@@ -172,7 +210,7 @@ async function callDeleteMember(data, callback) {
}
}
//fucntion callback
Insert Member
//fucntion callback
detail
async
function
callRepairDetail
(
data
,
callback
)
{
try
{
repairDetail
(
data
,
function
(
err
,
result
,
status
)
{
...
...
@@ -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
)
{
try
{
getAllDetail
(
"result"
,
function
(
err
,
result
,
status
)
{
...
...
@@ -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
async
function
callInsertReport
(
data
,
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
=
{
callRegisterGarage
,
...
...
@@ -280,5 +392,12 @@ module.exports = {
callGetByGarage
,
callInsertReport
,
callGetReport
,
callLoginUser
callLoginUser
,
callGetByDetailID
,
callSpareDetail
,
callGetSpareByDetailID
,
callDeleteSpare
,
callUpdateDetail
,
callGetMemberByGarage
,
callGetGarageAll
};
src/sql/createTable.js
View file @
24d53a2a
...
...
@@ -20,12 +20,14 @@ module.exports = {
on_time varchar(100),
off_time varchar(100),
tel varchar(30),
confirmation varchar(100),
PRIMARY KEY (garageID)
)`
,
member
:
`CREATE TABLE member(
member_tel varchar(100),
garageID varchar(100),
party varchar(100),
member_name varchar(255),
member_ads varchar(255),
...
...
@@ -40,11 +42,18 @@ module.exports = {
garageID varchar(255),
member_tel varchar(100),
device_type varchar(255),
device varchar(255),
details varchar(255),
repair_date varchar(255),
car_number varchar(10),
car_province 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),
price int(10),
status_payment varchar(100),
equipment varchar(100),
PRIMARY KEY (detailsID),
FOREIGN KEY (member_tel) REFERENCES member(member_tel),
...
...
@@ -62,4 +71,15 @@ module.exports = {
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)
)`
,
};
src/sql/insertInto.js
View file @
24d53a2a
...
...
@@ -20,12 +20,14 @@ module.exports = {
registration_date,
on_time,
off_time,
tel
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`
,
tel,
confirmation
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`
,
insert_member
:
`INSERT INTO member
(
party,
garageID,
member_tel,
member_name,
member_ads,
...
...
@@ -38,12 +40,19 @@ module.exports = {
garageID,
member_tel,
device_type,
device,
details,
car_number,
car_province,
brand,
model,
kilo_number,
repair_details,
repair_date,
spare_parts_list,
status,
price
) VALUES (?,?,?,?,?,?,?,?)`
,
price,
status_payment,
equipment
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`
,
insert_reported
:
`INSERT INTO reported
(
...
...
@@ -53,5 +62,13 @@ module.exports = {
report_detail,
report_tel,
report_date
) VALUES (?)`
) VALUES (?)`
,
insert_spare
:
`INSERT INTO spare
(
detailsID,
spares,
member_tel
) VALUES (?, ?, ?)`
,
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment