|
| 1 | +import _ from 'lodash' |
| 2 | +import util from '../../util' |
| 3 | +import topicService from '../../services/topicService' |
| 4 | + |
| 5 | +/* |
| 6 | + NOTE: Use this code segment if you wish to create direct projects async |
| 7 | +import directService from '../../services/directProject' |
| 8 | +const createDirectProject = (project, logger) => { |
| 9 | + return util.getSystemUserToken(logger) |
| 10 | + .then(token => { |
| 11 | + const req = { |
| 12 | + id: 1, |
| 13 | + log: logger, |
| 14 | + headers: { authorization: `Bearer ${token}` } |
| 15 | + } |
| 16 | + // create direct project with name and description |
| 17 | + var body = { |
| 18 | + projectName: project.name, |
| 19 | + projectDescription: project.description |
| 20 | + } |
| 21 | + // billingAccountId is optional field |
| 22 | + if(project.billingAccountId){ |
| 23 | + body.billingAccountId = project.billingAccountId |
| 24 | + } |
| 25 | + return directService.createDirectProject(req, body) |
| 26 | + }) |
| 27 | + .catch((err) => { |
| 28 | + console.log(err) |
| 29 | + return Promise.reject(err) |
| 30 | + }) |
| 31 | +
|
| 32 | + // // create project in direct |
| 33 | + // if (!project.directProectId) { |
| 34 | + // logger.debug('creating direct project') |
| 35 | + // createDirectProject(project, logger) |
| 36 | + // .then(resp => { |
| 37 | + // return models.Project.update( |
| 38 | + // { directProjectId: resp.data.result.content.projectId }, |
| 39 | + // { where: { id: project.id } } |
| 40 | + // ) |
| 41 | + // .then(() => next() ) |
| 42 | + // .catch(err => next(err)) |
| 43 | + // }) |
| 44 | + // } else { |
| 45 | + // console.log(project.directProjectId) |
| 46 | + // next() |
| 47 | + // } |
| 48 | +
|
| 49 | +} |
| 50 | +*/ |
| 51 | +const addProjectStatus = (req, logger, project) => { |
| 52 | + const topics = [ |
| 53 | + { |
| 54 | + title: 'Hello, Coder here! Your project has been created successfully', |
| 55 | + body: 'It took almost 245ms for me to create it, but all is good now.\ |
| 56 | + That\'s a lot of hard for a robot, you know!' |
| 57 | + }, |
| 58 | + { |
| 59 | + title: 'Hey there, I\'m ready with the next steps for your project!', |
| 60 | + body: `<p>I went over the project and I see we still need to collect more\ |
| 61 | + details before I can use my super computational powers and create your quote.</p>\ |
| 62 | + <p>Head over to the <a href="/projects/${project.id}/specification/">Specification</a>\ |
| 63 | + section and answer all of the required questions. If you already have a document\ |
| 64 | + with specification, verify it against our checklist and upload it.</p>` |
| 65 | + } |
| 66 | + ] |
| 67 | + let postPromises = [] |
| 68 | + _.forEach(topics, t => { |
| 69 | + console.log(t) |
| 70 | + postPromises.push(topicService.createTopic(req, project.id, t.title, t.body)) |
| 71 | + }) |
| 72 | + |
| 73 | + return Promise.all(postPromises) |
| 74 | + .then(val => console.log(val)) |
| 75 | +} |
| 76 | + |
| 77 | + |
| 78 | +const createEventHandler = (logger, project) => { |
| 79 | + return util.getSystemUserToken(logger) |
| 80 | + .then(token => { |
| 81 | + const req = { |
| 82 | + id: 1, |
| 83 | + log: logger, |
| 84 | + headers: { authorization: `Bearer ${token}` } |
| 85 | + } |
| 86 | + return addProjectStatus(req, logger, project) |
| 87 | + }) |
| 88 | +} |
| 89 | + |
| 90 | +export default createEventHandler |
0 commit comments