Hi all,
I’m very new to Velo, so apologies if I’m missing something very basic!
Members of my website will be on 1 of 3 paid membership options (multiples allowed), each giving them the right to record 1, 5 or 10 items in a database/collection.
I want to prevent users recording more than the total number of collection entries they’ve paid for.
My code is below. Can you spot where I’m going wrong?
Cheers,
Sam
import { currentMember } from ‘wix-members’ ;
import wixData from ‘wix-data’
import wixPaidPlans from ‘wix-paid-plans’ ;
$w . onReady ( function () {
// Write your JavaScript here
// To select an element by ID use: $w('#elementID')
// Click 'Preview' to run your code
currentMember . getMember ()
. then (( member ) => {
**const** id = member . _id ;
**const** curMemEmail = member . loginEmail ;
**return** member ;
})
. **catch** (( error ) => {
console . error ( error );
})
wixPaidPlans . getCurrentMemberOrders ()
. then (( orders ) => {
**let** PlanCap = 0
**for** ( **let** i = 0 ; i < orders . length ; i ++) {
**let** item = orders [ i ];
**if** ( item . planName === "Plan Value 1" && item . status === "ACTIVE" ) {
PlanCap = PlanCap + 1
} **else** {
**if** ( item . planName === "Plan Value 5" && item . status === "ACTIVE" ) {
PlanCap = PlanCap + 5
} **else** {
**if** ( item . planName === "Plan Value 10" && item . status === "ACTIVE" ) {
PlanCap = PlanCap + 10
}}}}}
$w ( "#EventsData" ). onReady ( () => {
console . log ( "The dataset is ready" );
wixData . query ( "#EventsData" )
. eq ( "Email" , "CurMemEmail" )
. count ()
. then ( ( num ) => {
**let** numberOfItems = num ;
**if** numberOfItems > PlanCap {
$w ( "#newEventButton" ). disable ();
} )
. **catch** ( ( error ) => {
**let** errorMsg = error . message ;
**let** code = error . code ;
} );
}
})