-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvirtuals.js
98 lines (83 loc) · 1.95 KB
/
virtuals.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
module.exports = function VIRTUALS(Schemas) {
const Marketplace = Schemas.marketplace.schema;
const Users = Schemas.users.schema;
const Items = Schemas.items.schema;
const Cosmetics = Schemas.cosmetics.schema;
const Relationships = Schemas.relationships.schema;
Marketplace.virtual("authorData", {
ref: "UserDB",
localField: "author",
foreignField: "id",
justOne: true,
});
Marketplace.virtual("moreFromAuthor", {
ref: "marketplace",
localField: "author",
foreignField: "author",
justOne: false,
});
Marketplace.virtual("moreLikeThis", {
ref: "marketplace",
localField: "item_id",
foreignField: "item_id",
justOne: false,
});
Marketplace.virtual("itemData", {
ref: function () {
return ["background", "medal", "flair", "sticker", "shade"].includes(
this.item_type
)
? "Cosmetic"
: "Item";
},
localField: "item_id",
foreignField: "_id",
justOne: true,
});
// USER
Users.virtual("itemsData", {
ref: "Item",
localField: "modules.inventory.id",
foreignField: "id",
justOne: false,
});
Users.virtual("fanarts", {
ref: "fanart",
localField: "id",
foreignField: "author_ID",
justOne: false,
});
Users.virtual("collections", {
ref: "UserCollection",
localField: "id",
foreignField: "id",
select: "collections",
justOne: true,
});
Users.virtual("marriageData", {
ref: "Relationship",
localField: "featuredMarriage",
foreignField: "_id",
justOne: true,
});
// RELATIONSHIPS
Relationships.virtual("usersData", {
ref: "UserDB",
localField: "users",
foreignField: "id",
justOne: false,
});
// ITEM
Items.virtual("stickers", {
ref: "Cosmetic",
localField: "icon",
foreignField: "id",
justOne: false,
});
Cosmetics.virtual("packData", {
ref: "Item",
localField: "series_id",
foreignField: "icon",
justOne: true,
});
};