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