Skip to content

Instantly share code, notes, and snippets.

@tarang9211

tarang9211/mongo.js

Created Dec 11, 2018
Embed
What would you like to do?
import { ApolloError } from 'apollo-server';
import jwt from 'jsonwebtoken';
import ConferenceModel from '../models/conference';
import SubeventModel from '../models/subevent';
import uploadImage from '../utils/image-upload';
export default {
Mutation: {
async createConference(roots, args, context) {
const { token } = context;
let decodedObject = {};
jwt.verify(token, process.env.APP_SECRET, (err, decoded) => {
if (err) throw new ApolloError('Hmm, something went wrong');
decodedObject = decoded;
});
/** user id of the person creating the conference */
const { _id: userId } = decodedObject;
const {
name,
description,
location,
dates,
tags,
subevents,
image
} = args;
const subeventsMap = new Map(JSON.parse(subevents));
const subeventIds = [];
// const conference = await ConferenceModel.create({
// createdBy: userId,
// name,
// description,
// location,
// dates,
// tags
// });
for (const values of subeventsMap.values()) {
values.map(async value => {
const subevent = await SubeventModel.create({
title: value.title,
description: value.description,
location: value.location,
startTime: value.startTime,
endTime: value.endTime,
type: value.type,
forDate: value.forDate
});
subeventIds.push(subevent._id);
});
}
console.log(subeventIds);
return '123';
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment