I’m working on a GraphQl-Appolo project, I have two documents ( Laptop, LaptopState)
LaptopState will contain a collection with only an _id, so i user can have many laptop, at the moment i can get all user’s laptop i need to go through the _id of the laptop and see if they exist on the document LaptopState or not and return true or false.
Laptate: {
type: GraphQLBoolean,
resolve: async (_,{ lapId},{ userId}) => {
if (!userId) {
throw new Meteor.Error(401, 'Unauthorized');
}
const laptops = await Laptops.find({ superUser: userId }).fetch()
for (let lap of laptops) {
for (let lapId of lap._id) {
const checkLapState = LaptopState.findOne({ "_id": lapId}).fetch()
console.log(box._id)
if (!checkLapState) {
console.log('false')
return false
} else {
console.log('true')
return true
}
}}
}
}
}
}
LaptopState Document.json look like this:
{
"_id": "88baC2AOT1f1nIvyk7",
"creationDate": {
"$date": "2018-06-21T07:57:24.085Z"
}
}
I want to display a result like this :
{
"data": {
"LaptopState": [
{
"name": "Laptop1",
"_id": "HEDGz2aafs2UdSvT3S"
"state":True
},
{
"name": "Laptop2",
"_id": "88baC2AOT1f1nIvyk7",
"state":False
}
]
},