Guest User

Untitled

a guest
Dec 11th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. import { ApolloError } from 'apollo-server';
  2. import jwt from 'jsonwebtoken';
  3. import ConferenceModel from '../models/conference';
  4. import SubeventModel from '../models/subevent';
  5. import uploadImage from '../utils/image-upload';
  6.  
  7. export default {
  8. Mutation: {
  9. async createConference(roots, args, context) {
  10. const { token } = context;
  11. let decodedObject = {};
  12.  
  13. jwt.verify(token, process.env.APP_SECRET, (err, decoded) => {
  14. if (err) throw new ApolloError('Hmm, something went wrong');
  15. decodedObject = decoded;
  16. });
  17.  
  18. /** user id of the person creating the conference */
  19. const { _id: userId } = decodedObject;
  20. const {
  21. name,
  22. description,
  23. location,
  24. dates,
  25. tags,
  26. subevents,
  27. image
  28. } = args;
  29.  
  30. const subeventsMap = new Map(JSON.parse(subevents));
  31. const subeventIds = [];
  32.  
  33. // const conference = await ConferenceModel.create({
  34. // createdBy: userId,
  35. // name,
  36. // description,
  37. // location,
  38. // dates,
  39. // tags
  40. // });
  41.  
  42. for (const values of subeventsMap.values()) {
  43. values.map(async value => {
  44. const subevent = await SubeventModel.create({
  45. title: value.title,
  46. description: value.description,
  47. location: value.location,
  48. startTime: value.startTime,
  49. endTime: value.endTime,
  50. type: value.type,
  51. forDate: value.forDate
  52. });
  53. subeventIds.push(subevent._id);
  54. });
  55. }
  56.  
  57. console.log(subeventIds);
  58.  
  59. return '123';
  60. }
  61. }
  62. };
Add Comment
Please, Sign In to add comment