-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueries.js
33 lines (29 loc) · 852 Bytes
/
queries.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Test queries
const Barbershop = require("./models").barbershop;
const Review = require("./models").review;
const Location = require("./models").location;
const User = require("./models").user;
const oneBarbershop = async (id) => {
try {
const barbershop = await Barbershop.findByPk(id, {
include: [
{ model: Location, include: { model: Review, include: [User] } },
],
});
console.log(barbershop.get({ plain: true }).locations[0].reviews);
} catch (e) {
console.log("error", e.message);
}
};
const oneUser = async (id) => {
try {
const user = await User.findByPk(id, {
include: [{ model: Review, include: [Location] }],
});
console.log(user.get({ plain: true }).reviews[0].location.address);
} catch (e) {
console.log("error", e.message);
}
};
oneBarbershop(5);
//oneUser(2);