Skip to content

Commit f08b006

Browse files
chore: wip
1 parent 1e648ad commit f08b006

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

storage/framework/core/payments/src/billable/subscription.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import type Stripe from 'stripe'
2-
import type { SubscriptionModel } from '../../../../orm/src/models/Subscription'
2+
import type { SubscriptionModel, SubscriptionsTable } from '../../../../orm/src/models/Subscription'
33
import type { UserModel } from '../../../../orm/src/models/User'
44
import { manageCustomer, managePrice, stripe } from '..'
55

66
import { Subscription } from '../../../../orm/src/models/Subscription'
7+
import { db } from '@stacksjs/database'
78

89
export interface SubscriptionManager {
910
create: (user: UserModel, type: string, lookupKey: string, params: Partial<Stripe.SubscriptionCreateParams>) => Promise<Stripe.Response<Stripe.Subscription>>
@@ -184,14 +185,17 @@ export const manageSubscription: SubscriptionManager = (() => {
184185
return subscriptionModel
185186
}
186187

187-
async function updateSubscription(activeSubId: number, type: string, options: Stripe.Subscription): Promise<SubscriptionModel> {
188-
const subscription = await Subscription.find(activeSubId) as SubscriptionModel
189-
190-
subscription?.update({
191-
type,
192-
provider_price_id: options.items.data[0].price.id,
193-
unit_price: Number(options.items.data[0].price.unit_amount),
194-
})
188+
async function updateSubscription(activeSubId: number, type: string, options: Stripe.Subscription): Promise<SubscriptionsTable | undefined> {
189+
const subscription = await db.selectFrom('subscriptions').where('id', '=', activeSubId).selectAll().executeTakeFirst()
190+
191+
await db?.updateTable('subscriptions')
192+
.set({
193+
type,
194+
provider_price_id: options.items.data[0].price.id,
195+
unit_price: Number(options.items.data[0].price.unit_amount),
196+
})
197+
.where('id', '=', activeSubId)
198+
.executeTakeFirst()
195199

196200
return subscription
197201
}

storage/framework/core/payments/src/billable/transaction.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
import type { PaymentTransactionModel } from '../../../../orm/src/models/PaymentTransaction'
1+
import type { PaymentTransactionModel, PaymentTransactionsTable } from '../../../../orm/src/models/PaymentTransaction'
22
import type { UserModel } from '../../../../orm/src/models/User'
3-
import PaymentProduct from '../../../../orm/src/models/PaymentProduct'
4-
import { PaymentTransaction } from '../../../../orm/src/models/PaymentTransaction'
3+
import { db } from '@stacksjs/database'
54

65
export interface ManageTransaction {
7-
store: (user: UserModel, productId: number) => Promise<PaymentTransactionModel>
8-
list: (user: UserModel) => Promise<PaymentTransactionModel[]>
6+
store: (user: UserModel, productId: number) => Promise<PaymentTransactionsTable>
7+
list: (user: UserModel) => Promise<PaymentTransactionsTable[]>
98
}
109

1110
export const manageTransaction: ManageTransaction = (() => {
12-
async function store(user: UserModel, productId: number): Promise<PaymentTransactionModel> {
13-
const product = await PaymentProduct.find(productId)
11+
async function store(user: UserModel, productId: number): Promise<PaymentTransactionsTable> {
12+
const product = await db.selectFrom('payment_products').where('id', '=', productId).selectAll().executeTakeFirst()
1413

1514
const data = {
1615
name: product?.name,
@@ -22,13 +21,15 @@ export const manageTransaction: ManageTransaction = (() => {
2221
user_id: user.id,
2322
}
2423

25-
const transaction = await PaymentTransaction.create(data)
24+
const createdTransaction = await db.insertInto('payment_transactions').values(data).executeTakeFirst()
25+
26+
const transaction = await db.selectFrom('payment_transactions').where('id', '=', Number(createdTransaction.insertId)).selectAll().executeTakeFirst()
2627

2728
return transaction
2829
}
2930

30-
async function list(user: UserModel): Promise<PaymentTransactionModel[]> {
31-
const transaction = await PaymentTransaction.where('user_id', user.id).get()
31+
async function list(user: UserModel): Promise<PaymentTransactionsTable[]> {
32+
const transaction = await db.selectFrom('payment_transactions').where('user_id', '=', user.id).selectAll().execute()
3233

3334
return transaction
3435
}

storage/framework/orm/src/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ export interface Database {
5454
personal_access_tokens: PersonalAccessTokensTable
5555
team_users: TeamUsersTable
5656
teams: TeamsTable
57-
requests: RequestsTable
5857
activities: ActivitiesTable
5958
subscribers: SubscribersTable
6059
deployments: DeploymentsTable

0 commit comments

Comments
 (0)