changed field from availability to isAvailable
This commit is contained in:
@@ -86,7 +86,7 @@ const Item = sequelize.define("Item", {
|
|||||||
type: DataTypes.ARRAY(DataTypes.STRING),
|
type: DataTypes.ARRAY(DataTypes.STRING),
|
||||||
defaultValue: [],
|
defaultValue: [],
|
||||||
},
|
},
|
||||||
availability: {
|
isAvailable: {
|
||||||
type: DataTypes.BOOLEAN,
|
type: DataTypes.BOOLEAN,
|
||||||
defaultValue: true,
|
defaultValue: true,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ router.get("/recommendations", authenticateToken, async (req, res) => {
|
|||||||
// For now, just return random available items as recommendations
|
// For now, just return random available items as recommendations
|
||||||
const recommendations = await Item.findAll({
|
const recommendations = await Item.findAll({
|
||||||
where: {
|
where: {
|
||||||
availability: true,
|
isAvailable: true,
|
||||||
isDeleted: false,
|
isDeleted: false,
|
||||||
},
|
},
|
||||||
limit: 10,
|
limit: 10,
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ router.post("/", authenticateToken, requireVerifiedEmail, async (req, res) => {
|
|||||||
return res.status(404).json({ error: "Item not found" });
|
return res.status(404).json({ error: "Item not found" });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!item.availability) {
|
if (!item.isAvailable) {
|
||||||
return res.status(400).json({ error: "Item is not available" });
|
return res.status(400).json({ error: "Item is not available" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -422,8 +422,8 @@ describe('Items Routes', () => {
|
|||||||
|
|
||||||
describe('GET /recommendations', () => {
|
describe('GET /recommendations', () => {
|
||||||
const mockRecommendations = [
|
const mockRecommendations = [
|
||||||
{ id: 1, name: 'Item 1', availability: true },
|
{ id: 1, name: 'Item 1', isAvailable: true },
|
||||||
{ id: 2, name: 'Item 2', availability: true }
|
{ id: 2, name: 'Item 2', isAvailable: true }
|
||||||
];
|
];
|
||||||
|
|
||||||
it('should get recommendations for authenticated user', async () => {
|
it('should get recommendations for authenticated user', async () => {
|
||||||
@@ -443,7 +443,7 @@ describe('Items Routes', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(mockItemFindAll).toHaveBeenCalledWith({
|
expect(mockItemFindAll).toHaveBeenCalledWith({
|
||||||
where: { availability: true },
|
where: { isAvailable: true, isDeleted: false },
|
||||||
limit: 10,
|
limit: 10,
|
||||||
order: [['createdAt', 'DESC']]
|
order: [['createdAt', 'DESC']]
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -260,7 +260,7 @@ describe('Rentals Routes', () => {
|
|||||||
id: 1,
|
id: 1,
|
||||||
name: 'Test Item',
|
name: 'Test Item',
|
||||||
ownerId: 2,
|
ownerId: 2,
|
||||||
availability: true,
|
isAvailable: true,
|
||||||
pricePerHour: 10,
|
pricePerHour: 10,
|
||||||
pricePerDay: 50,
|
pricePerDay: 50,
|
||||||
};
|
};
|
||||||
@@ -340,7 +340,7 @@ describe('Rentals Routes', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return 400 for unavailable item', async () => {
|
it('should return 400 for unavailable item', async () => {
|
||||||
Item.findByPk.mockResolvedValue({ ...mockItem, availability: false });
|
Item.findByPk.mockResolvedValue({ ...mockItem, isAvailable: false });
|
||||||
|
|
||||||
const response = await request(app)
|
const response = await request(app)
|
||||||
.post('/rentals')
|
.post('/rentals')
|
||||||
@@ -382,7 +382,7 @@ describe('Rentals Routes', () => {
|
|||||||
Item.findByPk.mockResolvedValue({
|
Item.findByPk.mockResolvedValue({
|
||||||
id: 1,
|
id: 1,
|
||||||
ownerId: 2,
|
ownerId: 2,
|
||||||
availability: true,
|
isAvailable: true,
|
||||||
pricePerHour: 0,
|
pricePerHour: 0,
|
||||||
pricePerDay: 0
|
pricePerDay: 0
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -633,7 +633,7 @@ const ItemDetail: React.FC = () => {
|
|||||||
})()}
|
})()}
|
||||||
|
|
||||||
{/* Rental Period Selection - Only show for non-owners */}
|
{/* Rental Period Selection - Only show for non-owners */}
|
||||||
{!isOwner && item.availability && !isAlreadyRenting && (
|
{!isOwner && item.isAvailable && !isAlreadyRenting && (
|
||||||
<>
|
<>
|
||||||
<hr />
|
<hr />
|
||||||
<div className="text-start">
|
<div className="text-start">
|
||||||
@@ -758,7 +758,7 @@ const ItemDetail: React.FC = () => {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Action Buttons */}
|
{/* Action Buttons */}
|
||||||
{!isOwner && item.availability && !isAlreadyRenting && (
|
{!isOwner && item.isAvailable && !isAlreadyRenting && (
|
||||||
<div className="d-grid">
|
<div className="d-grid">
|
||||||
<button
|
<button
|
||||||
className="btn btn-primary"
|
className="btn btn-primary"
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ const ItemList: React.FC = () => {
|
|||||||
// Access the items array from response.data.items
|
// Access the items array from response.data.items
|
||||||
const allItems = response.data.items || response.data || [];
|
const allItems = response.data.items || response.data || [];
|
||||||
// Filter only available items
|
// Filter only available items
|
||||||
const availableItems = allItems.filter((item: Item) => item.availability);
|
const availableItems = allItems.filter((item: Item) => item.isAvailable);
|
||||||
setItems(availableItems);
|
setItems(availableItems);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
console.error("Error fetching items:", err);
|
console.error("Error fetching items:", err);
|
||||||
|
|||||||
@@ -110,11 +110,11 @@ const Owning: React.FC = () => {
|
|||||||
try {
|
try {
|
||||||
await api.put(`/items/${item.id}`, {
|
await api.put(`/items/${item.id}`, {
|
||||||
...item,
|
...item,
|
||||||
availability: !item.availability,
|
isAvailable: !item.isAvailable,
|
||||||
});
|
});
|
||||||
setListings(
|
setListings(
|
||||||
listings.map((i) =>
|
listings.map((i) =>
|
||||||
i.id === item.id ? { ...i, availability: !i.availability } : i
|
i.id === item.id ? { ...i, isAvailable: !i.isAvailable } : i
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
@@ -536,10 +536,10 @@ const Owning: React.FC = () => {
|
|||||||
<div className="mb-2 d-flex gap-2 flex-wrap">
|
<div className="mb-2 d-flex gap-2 flex-wrap">
|
||||||
<span
|
<span
|
||||||
className={`badge ${
|
className={`badge ${
|
||||||
item.availability ? "bg-success" : "bg-secondary"
|
item.isAvailable ? "bg-success" : "bg-secondary"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{item.availability ? "Available" : "Not Available"}
|
{item.isAvailable ? "Available" : "Not Available"}
|
||||||
</span>
|
</span>
|
||||||
{item.isDeleted && (
|
{item.isDeleted && (
|
||||||
<span className="badge bg-danger">
|
<span className="badge bg-danger">
|
||||||
@@ -620,7 +620,7 @@ const Owning: React.FC = () => {
|
|||||||
onClick={() => toggleAvailability(item)}
|
onClick={() => toggleAvailability(item)}
|
||||||
className="btn btn-sm btn-outline-info"
|
className="btn btn-sm btn-outline-info"
|
||||||
>
|
>
|
||||||
{item.availability
|
{item.isAvailable
|
||||||
? "Mark Unavailable"
|
? "Mark Unavailable"
|
||||||
: "Mark Available"}
|
: "Mark Available"}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ const RentItem: React.FC = () => {
|
|||||||
setItem(response.data);
|
setItem(response.data);
|
||||||
|
|
||||||
// Check if item is available
|
// Check if item is available
|
||||||
if (!response.data.availability) {
|
if (!response.data.isAvailable) {
|
||||||
setError("This item is not available for rent");
|
setError("This item is not available for rent");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ export interface Item {
|
|||||||
longitude?: number;
|
longitude?: number;
|
||||||
images: string[];
|
images: string[];
|
||||||
condition: "excellent" | "good" | "fair" | "poor";
|
condition: "excellent" | "good" | "fair" | "poor";
|
||||||
availability: boolean;
|
isAvailable: boolean;
|
||||||
rules?: string;
|
rules?: string;
|
||||||
availableAfter?: string;
|
availableAfter?: string;
|
||||||
availableBefore?: string;
|
availableBefore?: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user