File tree Expand file tree Collapse file tree
packages/app/control/src/services/db/apps Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -163,21 +163,30 @@ export async function setAppMembershipReferrer(
163163 echoAppId : string ,
164164 code : string
165165) : Promise < boolean > {
166- const appMembership = await db . appMembership . findUnique ( {
166+ // Get or create the app membership
167+ const appMembership = await db . appMembership . upsert ( {
167168 where : {
168169 userId_echoAppId : {
169170 userId,
170171 echoAppId,
171172 } ,
172- referrerId : null ,
173173 } ,
174+ create : {
175+ userId,
176+ echoAppId,
177+ role : AppRole . CUSTOMER ,
178+ status : MembershipStatus . ACTIVE ,
179+ totalSpent : 0 ,
180+ } ,
181+ update : { } ,
174182 } ) ;
175183
176- if ( appMembership ) {
177- // If the user already has a referrer, return false
184+ // Check if user already has a referrer
185+ if ( appMembership . referrerId ) {
178186 return false ;
179187 }
180188
189+ // Validate the referral code exists
181190 const referralCode = await db . referralCode . findUnique ( {
182191 where : {
183192 code,
You can’t perform that action at this time.
0 commit comments