Skip to content

Commit

Permalink
Merge pull request #43 from sathirauop/main
Browse files Browse the repository at this point in the history
added delete card end point
  • Loading branch information
sathirauop authored Mar 6, 2021
2 parents cb90fda + 9557b13 commit fadfc46
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
20 changes: 20 additions & 0 deletions Backends/Local Server/src/controllers/card.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,23 @@ exports.scanCard = async(req,res,next) =>{
}
}

exports.deleteCard = async (req,res,next)=>{
try{
const details = {
card_id: req.body.card_id
}

await card.cardDeleteing(details,async (err)=>{
if (!err) {
return res.status(httpStatus.OK).json({msg :"card is succesfully deleted"})
}else{
console.log(err.message)
return res.status(httpStatus.INTERNAL_SERVER_ERROR).json({Error: err.message})
}
});

}catch(err){
console.log(err.message)
return res.status(httpStatus.INTERNAL_SERVER_ERROR).json({Error: err.message})
}
}
38 changes: 37 additions & 1 deletion Backends/Local Server/src/models/rfidCard.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,35 @@ exports.cardScanning2 = async (details,callback)=>{



}

exports.cardDeleteing = async (details,callback)=>{
if(details){
const sql_delete = `DELETE from RFID_Card WHERE CardId = '${details.card_id}';`

await client.sendQuery(sql_delete, (err, result) => {
if(err) {
console.error(`SQLQueryError: ${err.sqlMessage}`)
console.log("test3")
callback(err)
} else {
if (result.affectedRows>0) {

console.log("test1")
callback(null)

}
else {
console.log("test2")
callback(Error("ZERO_ROWS_AFFECTED POSSIBLY BECAUSE WRONG CARD_ID"))
}
}
})

}



}

exports.creatingCurrentBalanace = async (details,callback)=>{
Expand All @@ -253,9 +282,11 @@ exports.creatingCurrentBalanace = async (details,callback)=>{

}





}


exports.findUser = async (email, callback) => {
if (email) {
Expand All @@ -278,4 +309,9 @@ exports.findUser = async (email, callback) => {
}
})
}
}

//DELETE FROM table_name WHERE condition;


}
1 change: 1 addition & 0 deletions Backends/Local Server/src/routes/api/authRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ router.post('/issueCard',cardValidation.validateBody(cardValidation.schemas.card
router.post('/scanCard',cardController.scanCard);
router.post('/returnCard',cardValidation.validateBody(cardValidation.schemas.cardAddorReturnSchema),cardController.returnCard);
router.post('/rechargeCard',cardValidation.validateBody(cardValidation.schemas.cardRechargeSchema),cardController.rechargeCard);
router.post('/deleteCard',cardController.deleteCard);


module.exports = router
4 changes: 2 additions & 2 deletions Backends/Local Server/src/services/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ const sql = {
rfidCard:'CREATE TABLE IF NOT EXISTS RFID_Card(CardId VARCHAR(20) PRIMARY KEY, EmployeeId VARCHAR(12) , CustomerName VARCHAR(25), Date DATE , Time TIME , IsIssued BOOLEAN DEFAULT false, Amount DOUBLE, FOREIGN KEY (EmployeeId) REFERENCES EMPLOYEE (NIC) ON UPDATE CASCADE)',
// The format of Gaming Node Id: S_xx_N_xx (here xx is a hexadecimal value)
gamingNode:'CREATE TABLE IF NOT EXISTS GAMING_NODE(NodeId CHAR(9) PRIMARY KEY, Price DOUBLE NOT NULL, Status BOOLEAN DEFAULT true)',
gamingLog:'CREATE TABLE IF NOT EXISTS GAMING_LOG(LogId INT PRIMARY KEY AUTO_INCREMENT, NodeId CHAR(9),CardId VARCHAR(12), Date DATE, Time TIME, FOREIGN KEY (NodeId) REFERENCES GAMING_NODE (NodeId) ON UPDATE CASCADE, FOREIGN KEY (CardId) REFERENCES RFID_Card (CardId) ON UPDATE CASCADE)',
issueLog:'CREATE TABLE IF NOT EXISTS ISSUE_LOG(LogId INT PRIMARY KEY AUTO_INCREMENT,NIC VARCHAR(12),CardId VARCHAR(10),CustomerName VARCHAR(30),DepositAmount DOUBLE,Date DATE , Time TIME , FOREIGN KEY (CardId) REFERENCES RFID_Card(CardId) ON UPDATE CASCADE, FOREIGN KEY (NIC) REFERENCES EMPLOYEE (NIC) ON UPDATE CASCADE)'
gamingLog:'CREATE TABLE IF NOT EXISTS GAMING_LOG(LogId INT PRIMARY KEY AUTO_INCREMENT, NodeId CHAR(9),CardId VARCHAR(12), Date DATE, Time TIME)',
issueLog:'CREATE TABLE IF NOT EXISTS ISSUE_LOG(LogId INT PRIMARY KEY AUTO_INCREMENT,NIC VARCHAR(12),CardId VARCHAR(10),CustomerName VARCHAR(30),DepositAmount DOUBLE,Date DATE , Time TIME )'
}
}

Expand Down

0 comments on commit fadfc46

Please sign in to comment.