Question: How to setup a function to edit item with reference to same like remove item function below: import mysql from ' mysql ' export const

How to setup a function to edit item with reference to same like remove item function below: import mysql from 'mysql'
export const handler = async (event)=>{
// get credentials from the db_access layer (loaded separately via AWS console)
var pool = mysql.createPool({
host: "replace your api"
east-1.rds.amazonaws.com",
user: "replace user",
password: "replace password",
database: "replace database"
});
let RemoveItem =(itemID)=>{
return new Promise((resolve, reject)=>{
pool.query("DELETE FROM Items WHERE itemID=?",[itemID],(error, rows)=>{
if (error){ return reject(error); }
if ((rows) && (rows.affectedRows ==1)){
return resolve(true);
} else {
return resolve(false);
}
});
});
}
let response
try {
const result = await RemoveItem(event.itemID)
if (result){
response ={ statusCode: 200, result: { "success": true }}
} else {
response ={ statusCode: 400, error: "No such item" }
}
} catch (err){
response ={ statusCode: 400, error: err }
}
pool.end()// close DB connections
return response;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!