Skip to content

Commit b553214

Browse files
committed
Fixing type check errors
1 parent 8a00698 commit b553214

6 files changed

Lines changed: 48 additions & 18 deletions

File tree

backend/market/management/commands/seed_offers.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def add_arguments(self, parser):
1818
"--listing-id",
1919
type=int,
2020
default=None,
21-
help="Add offers to an existing listing by ID instead of creating a new one",
21+
help="Add offers to an existing listing by ID",
2222
)
2323

2424
def handle(self, *args, **options):
@@ -48,16 +48,24 @@ def handle(self, *args, **options):
4848
bob.set_password("testpassword123")
4949
bob.save()
5050

51-
self.stdout.write(self.style.SUCCESS("Buyers ready: Alice Johnson, Bob Williams"))
51+
self.stdout.write(
52+
self.style.SUCCESS("Buyers ready: Alice Johnson, Bob Williams")
53+
)
5254

5355
listing_id = options["listing_id"]
5456
if listing_id:
5557
try:
5658
listing = Listing.objects.get(pk=listing_id)
5759
except Listing.DoesNotExist:
58-
self.stdout.write(self.style.ERROR(f"Listing with id={listing_id} not found"))
60+
self.stdout.write(
61+
self.style.ERROR(f"Listing with id={listing_id} not found")
62+
)
5963
return
60-
self.stdout.write(self.style.SUCCESS(f"Using existing listing: {listing.title} (id={listing.id})"))
64+
self.stdout.write(
65+
self.style.SUCCESS(
66+
f"Using existing listing: {listing.title} (id={listing.id})"
67+
)
68+
)
6169
else:
6270
seller, _ = User.objects.get_or_create(
6371
username="lautaro",
@@ -69,7 +77,9 @@ def handle(self, *args, **options):
6977
)
7078
seller.set_password("testpassword123")
7179
seller.save()
72-
self.stdout.write(self.style.SUCCESS(f"Seller ready: {seller.get_full_name()}"))
80+
self.stdout.write(
81+
self.style.SUCCESS(f"Seller ready: {seller.get_full_name()}")
82+
)
7383

7484
category, _ = Category.objects.get_or_create(name="Furniture")
7585
listing = Item.objects.create(
@@ -105,5 +115,11 @@ def handle(self, *args, **options):
105115
new_count = sum([created_alice, created_bob])
106116
skipped = 2 - new_count
107117

108-
self.stdout.write(self.style.SUCCESS(f"Created {new_count} offers, skipped {skipped} (already existed)"))
109-
self.stdout.write(self.style.SUCCESS(f"\nDone! Offers added to listing id={listing.id}"))
118+
self.stdout.write(
119+
self.style.SUCCESS(
120+
f"Created {new_count} offers, skipped {skipped} (already existed)"
121+
)
122+
)
123+
self.stdout.write(
124+
self.style.SUCCESS(f"\nDone! Offers added to listing id={listing.id}")
125+
)

backend/market/serializers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class OfferDetailsSerializer(ModelSerializer):
8282
Allows the offer owner to edit the offer's offered_price and message.
8383
Status is intentionally read-only (managed by the listing owner).
8484
"""
85+
8586
class Meta:
8687
model = Offer
8788
fields = ["id", "offered_price", "message", "status"]

backend/market/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
UserFavorites,
1414
change_offer_details,
1515
change_offer_status,
16-
get_my_offer_for_listing,
1716
get_current_user,
17+
get_my_offer_for_listing,
1818
get_phone_status,
1919
send_verification_code,
2020
verify_phone_code,

backend/market/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@
2121
from market.permissions import (
2222
IsSuperUser,
2323
ListingImageOwnerPermission,
24-
ListingOwnerPermission,
2524
ListingOwnerOffersPermission,
25+
ListingOwnerPermission,
2626
)
2727
from market.serializers import (
2828
ListingImageSerializer,
2929
ListingImageURLSerializer,
3030
ListingSerializer,
3131
ListingSerializerList,
3232
ListingSerializerPublic,
33+
OfferDetailsSerializer,
3334
OfferSerializer,
3435
OfferStatusSerializer,
35-
OfferDetailsSerializer,
3636
TagSerializer,
3737
UserSerializer,
3838
)

frontend/components/listings/detail/EditListing.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@ import { Input } from "@/components/ui/input";
1212
import { updateListing } from "@/lib/actions";
1313
import { BEDS_OPTIONS, BATHS_OPTIONS, CATEGORY_OPTIONS, CONDITION_OPTIONS } from "@/lib/constants";
1414
import { parsePriceString } from "@/lib/utils";
15-
import type { Item, Sublet, UpdateItemPayload, UpdateSubletPayload } from "@/lib/types";
15+
import type {
16+
Item,
17+
ItemCategory,
18+
ItemCondition,
19+
Sublet,
20+
UpdateItemPayload,
21+
UpdateSubletPayload,
22+
} from "@/lib/types";
1623
import {
1724
editItemSchema,
1825
editSubletSchema,
@@ -34,8 +41,11 @@ interface Props {
3441
onOpenChange: (open: boolean) => void;
3542
}
3643

37-
const resolveConditionValue = (condition: string) =>
38-
CONDITION_OPTIONS.find((option) => option.label === condition)?.value ?? condition;
44+
const resolveConditionValue = (condition: string | undefined): ItemCondition | undefined => {
45+
if (condition === undefined) return undefined;
46+
const match = CONDITION_OPTIONS.find((option) => option.label === condition);
47+
return match ? match.value : (condition as ItemCondition);
48+
};
3949

4050
const EditItemContent = ({
4151
listing,
@@ -109,7 +119,7 @@ const EditItemContent = ({
109119
<FormSelect
110120
label="Product Category"
111121
value={field.value}
112-
onChange={field.onChange}
122+
onChange={(val) => field.onChange(val as ItemCategory)}
113123
options={CATEGORY_OPTIONS}
114124
placeholder="Select Category"
115125
error={errors.category?.message}
@@ -124,7 +134,7 @@ const EditItemContent = ({
124134
<FormSelect
125135
label="Condition"
126136
value={field.value}
127-
onChange={field.onChange}
137+
onChange={(val) => field.onChange(val as ItemCondition)}
128138
options={CONDITION_OPTIONS}
129139
placeholder="Select Condition"
130140
error={errors.condition?.message}

frontend/lib/actions.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ async function serverFetch<T>(endpoint: string, options: RequestInit = {}): Prom
9797

9898
throw new APIError(errorMessage, response.status);
9999
}
100-
return response.json();
100+
// Some DELETE endpoints return `204 No Content`; attempting `response.json()` would throw.
101+
if (response.status === 204) return null as unknown as T;
102+
103+
return response.json().catch(() => null as unknown as T);
101104
}
102105

103106
// ------------------------------------------------------------
@@ -207,8 +210,8 @@ export async function createOffer({
207210
listingId: number;
208211
offeredPrice: number;
209212
message?: string;
210-
}) {
211-
return await serverFetch(`/market/listings/${listingId}/offers/`, {
213+
}): Promise<Offer> {
214+
return await serverFetch<Offer>(`/market/listings/${listingId}/offers/`, {
212215
method: "POST",
213216
body: JSON.stringify({
214217
offered_price: offeredPrice,

0 commit comments

Comments
 (0)