Skip to content

Commit 4af36ad

Browse files
authored
feat: revoke recurring grants (#1446)
* display revoke button for recurring payments * remove orders for revoked one-payment grants
1 parent daea8bb commit 4af36ad

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

packages/boutique/backend/src/order/controller.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,11 @@ export class OrderController implements IOrderController {
222222
res: TypedResponse<CreateResponse>,
223223
next: NextFunction
224224
) => {
225+
let order: Order
225226
try {
226227
const args = await validate(instantBuySchema, req.body)
227228

228-
const order = await Order.transaction(async (trx) => {
229+
order = await Order.transaction(async (trx) => {
229230
const newOrder = await this.orderService.create(
230231
{ orderItems: args.products },
231232
trx
@@ -241,11 +242,14 @@ export class OrderController implements IOrderController {
241242
})
242243
)
243244
} catch (err) {
244-
if (err instanceof OpenPaymentsClientError && err.status === 401)
245+
if (err instanceof OpenPaymentsClientError && err.status === 401) {
245246
next(
246247
new Unauthorized('Instant-buy is not valid please initiate it again')
247248
)
248-
else next(err)
249+
await Order.transaction(async (trx) => {
250+
return await this.orderService.delete(order!.id, trx)
251+
})
252+
} else next(err)
249253
}
250254
}
251255
}

packages/boutique/backend/src/order/service.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ interface CreateParams {
1313

1414
export interface IOrderService {
1515
create: (params: CreateParams, trx: TransactionOrKnex) => Promise<Order>
16+
delete: (id: string, trx: TransactionOrKnex) => Promise<Order | undefined>
1617
get: (id: string, userId?: string) => Promise<Order>
1718
ensurePendingState: (id: string) => Promise<Order>
1819
list: (userId: string) => Promise<Order[]>
@@ -35,6 +36,13 @@ export class OrderService implements IOrderService {
3536
.returning('*')
3637
}
3738

39+
public async delete(
40+
id: string,
41+
trx: TransactionOrKnex
42+
): Promise<Order | undefined> {
43+
return Order.query(trx).deleteById(id).returning('*').first()
44+
}
45+
3846
public async get(id: string, userId?: string): Promise<Order> {
3947
const row = Order.query().findById(id).withGraphFetched('orderItems')
4048
if (userId) row.where('userId', '=', userId)

0 commit comments

Comments
 (0)