I am in the process of setting up a new server and I want each customer to have a unique UUID identifier. My goal is to allow the customers name, parent company, and internal id to be input through a web interface, while the UUID is generated on the server side. How can I properly insert the UUID into the database so that it is stored in the ID column of the table?
Currently, the setup allows me to include the ID with curl for testing purposes. Previously, the code would retrieve all values from the terminal. Now, I am working on modifying the code so that when a new customer is created, their name, parent company, symID, and a UUID generated ID are inputted into the database.
Additionally, I need to pull the symID from a database of IDs which I do not currently have access to. It is uncertain whether this feature will be implemented, so for now, it must be manually entered or left blank.
I'm utilizing pg-promise to write to a postgres database, along with express and bluebird.
//Database setup
...
CREATE TABLE customer(
customer_name VARCHAR,
ID varchar PRIMARY KEY,
parent VARCHAR,
symID VARCHAR
);
...
//code to create new user
...
function createUser(req, res, next) {
const user_id = uuidv4();
//need to fix id. currently it is user entered and not a uuidv4
db.none('insert into customer values(${customer_name}, ${ID}, ${parent}, ${symID})',
req.body)
.then(function () {
res.status(200)
.json({
status: 'success',
message: 'Inserted one customer'
});
})
.catch(function (err) {
return next(err);
});
}
...