Skip to content

Commit f63cdb4

Browse files
author
Víctor Martínez
committed
hotfix: bookings fetch
2 parents 9e5f7cf + 2db6678 commit f63cdb4

File tree

4 files changed

+8
-14
lines changed

4 files changed

+8
-14
lines changed

src/controllers/bookings-controller.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ async function bookProperty(req, res, next) {
55
const { uid } = req.user;
66
const { propertyId, contactInfo } = req.body;
77
try {
8-
const property = await getPropertyById(propertyId);
9-
8+
const response = await getPropertyById(propertyId);
9+
const property = response.data;
1010
const booking = await db.Bookings.create({
1111
clientId: uid,
1212
employeeId: property.employee_id,

src/controllers/properties-controller.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ async function getProperty(req, res, next) {
44
const { propertyId } = req.params;
55
try {
66
const response = await getPropertyById(propertyId);
7-
res.status(200).send({
8-
data: response,
9-
error: null
10-
});
7+
res.status(200).send(response);
118
} catch (err) {
129
next(err);
1310
}
@@ -16,10 +13,7 @@ async function getProperty(req, res, next) {
1613
async function searchProperties(req, res, next) {
1714
try {
1815
const response = await searchAdminProperties(req.query);
19-
res.status(200).send({
20-
data: response,
21-
error: null
22-
});
16+
res.status(200).send(response);
2317
} catch (err) {
2418
next(err);
2519
}

src/routes/__tests__/bookings-routes.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const setupTestDB = require("../../mock/seedTestDB");
1111
const mockHome = setupTestDB.getHome();
1212

1313
jest.mock("../../utils/properties", () => ({
14-
getPropertyById: () => mockHome
14+
getPropertyById: () => ({ data: mockHome, error: null })
1515
}))
1616

1717
const request = supertest(app);
@@ -42,7 +42,7 @@ describe("Private bookings routes", () => {
4242
expect(booking.status).toBe("pending");
4343
expect(booking.contactInfo).toMatchObject(postData.contactInfo);
4444
});
45-
45+
4646
it("can get my bookings", async () => {
4747
//insert into db test_property with create property
4848
const res = await request.get("/bookings/all");

src/routes/__tests__/properties-routes.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe("Properties routes", () => {
5151
});
5252

5353
const res = await request.get("/properties?kind=Office");
54-
expect(res.body.data).toMatchObject([{ hello: "World" }]);
54+
expect(res.body).toMatchObject([{ hello: "World" }]);
5555
});
5656

5757
it("can get property by Id", async () => {
@@ -63,6 +63,6 @@ describe("Properties routes", () => {
6363
});
6464

6565
const res = await request.get("/properties/sdflksdgkn");
66-
expect(res.body.data).toMatchObject({ hello: "World" });
66+
expect(res.body).toMatchObject({ hello: "World" });
6767
});
6868
});

0 commit comments

Comments
 (0)