Skip to content

Commit 1007f17

Browse files
committed
Update state on backend instead
1 parent d96b81f commit 1007f17

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

admin/src/Membership/MemberBoxSpans.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useJson } from "Hooks/useJson";
22
import useModel from "Hooks/useModel";
33
import Member from "Models/Member";
4-
import TransactionAction, { Status } from "Models/TransactionAction";
4+
import TransactionAction from "Models/TransactionAction";
55
import React, { useMemo } from "react";
66
import "react-day-picker/style.css";
77
import { Link, useParams } from "react-router-dom";
@@ -54,10 +54,9 @@ function PendingAction({ id, member_id }: { id: number; member_id: string }) {
5454
</ol>
5555
</>,
5656
).then(
57-
() => {
58-
action.status = Status.cancelled;
59-
action.completed_at = new Date();
60-
action.save();
57+
async () => {
58+
await action.del();
59+
action.refresh();
6160
},
6261
() => {},
6362
);

api/src/shop/entities.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
from datetime import datetime, timezone
2+
13
from membership.models import Member
4+
from service.db import db_session
25
from service.entity import ASC, DESC, Entity, ExpandField
6+
from service.error import BadRequest, NotFound
37

48
from shop.models import (
59
GiftCard,
@@ -43,6 +47,23 @@
4347
)
4448

4549

50+
class TransactionActionEntity(Entity):
51+
def delete(self, entity_id, commit=True):
52+
entity = db_session.get(self.model, entity_id)
53+
if not entity:
54+
raise NotFound("Could not find any entity with specified parameters.")
55+
56+
if entity.status is not TransactionAction.Status.pending:
57+
raise BadRequest("Cannot delete a transaction action that is not pending.")
58+
59+
entity.status = TransactionAction.Status.cancelled
60+
entity.completed_at = datetime.now(timezone.utc).replace(tzinfo=None)
61+
62+
db_session.commit()
63+
64+
return self.to_obj(entity)
65+
66+
4667
product_action_entity = Entity(ProductAction)
4768

4869

@@ -68,7 +89,7 @@
6889
)
6990

7091

71-
transaction_action_entity = Entity(
92+
transaction_action_entity = TransactionActionEntity(
7293
TransactionAction,
7394
default_sort_column=None,
7495
)

api/src/shop/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
path="/transaction_action",
103103
entity=transaction_action_entity,
104104
permission_read=WEBSHOP,
105-
permission_update=WEBSHOP_EDIT,
105+
permission_delete=WEBSHOP_EDIT,
106106
)
107107

108108
service.related_entity_routes(

0 commit comments

Comments
 (0)