I am seeking to create a database with preuploaded values where only specific registered users will be allowed to create new values for the database. On an input page, I am then trying to have general users input information into one value field which will firstly confirm that the value is already in the pre-uploaded database. All the pre-uploaded information will be set to a specific value beforehand in a second value field. When the user inputs the information into the first value field and presses a button, automatically I am trying to have the second value field updated (the options in this second value field are dichotomous). I am creating two separate pages registered to different users so that each user is only allowed to make a specific change in the second value field. Ie. user 1 can only change from the dichotomous values in one direction for eg (a-b and not b-a). Then I would create a second page which does the same for user 2 but only allows this user to change the second value field in the reverse direction (ie. from b-a and not a-b).To do this final restriction i believe i can just copy the code to the other page and reverse the update aspect of the code.
I've been reading other forums and adapting codes provided as guides and this is as far as I have been able to get. Assistance would be greatly appreciated.
import wixData from 'wix-data';
//all log messages will show when we run this code.
//they will help us debug and see all is working well.
//they have no impact other than that and can be safely removed
//once we see the code is working well
console.log("in before insert hook");
console.log("number is " + item.ticketNumber);
//create a new promise object.
//in the promise's body we'll look for dups.
//if we find any, we will reject the promise and abort the insert.
let p = new Promise(function(resolve, reject)
console.log("in promise body");
//create a query to look for items with the same number as the item we're tring to insert
let number_q = wixData.query("Tickets").eq("ticketNumber", item.ticketNumber);
let admit_q = wixData.query("Tickets").eq("Admittance", item.admittance)
//run the query to confirm that the item is registered
console.log("after big_q returns");
if (count === 1)
console.log("Ticket found, resolving the promise to the original 'item' so the insert can proceed");
console.log("count is zero, rejecting the promise with an error message");
reject("Ticket not found!");
//return the promise from the hook