File tree 2 files changed +13
-2
lines changed
2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -44,3 +44,10 @@ CREATE TABLE IF NOT EXISTS gp_tokens (
44
44
expire DATE ,
45
45
date_last_used DATE
46
46
);
47
+
48
+ CREATE TABLE IF NOT EXISTS gp_credits (
49
+ id INT (10 ) UNSIGNED AUTO_INCREMENT PRIMARY KEY ,
50
+ date_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP ,
51
+ AMOUNT INT NOT NULL ,
52
+ user_id VARCHAR (36 ) NOT NULL
53
+ );
Original file line number Diff line number Diff line change @@ -9,7 +9,11 @@ export class Credits {
9
9
10
10
async consume ( userId : string , credits : number ) {
11
11
try {
12
- await this . sql ( CREDITS_TABLE ) . where ( { user_id : userId } ) . update ( { amount : this . sql . raw ( 'amount - ?' , [ credits ] ) } ) ;
12
+ const result = await this . sql ( CREDITS_TABLE ) . where ( { user_id : userId } ) . update ( { amount : this . sql . raw ( 'amount - ?' , [ credits ] ) } ) ;
13
+
14
+ if ( result === 1 ) {
15
+ return true ;
16
+ }
13
17
} catch ( error ) {
14
18
if ( error && ( error as Error & { errno ?: number } ) . errno === ER_CONSTRAINT_FAILED_CODE ) {
15
19
return false ;
@@ -18,7 +22,7 @@ export class Credits {
18
22
throw error ;
19
23
}
20
24
21
- return true ;
25
+ return false ;
22
26
}
23
27
}
24
28
You can’t perform that action at this time.
0 commit comments