(userId, data, options = {})
| 59 | } |
| 60 | |
| 61 | create(userId, data, options = {}) { |
| 62 | let newProject = {}; |
| 63 | const { transaction } = options; |
| 64 | |
| 65 | return db.Project.create(data, { transaction }) |
| 66 | .then((project) => { |
| 67 | newProject = project; |
| 68 | return this.updateProjectRole(project.id, userId, "teamOwner", options); |
| 69 | }) |
| 70 | .then(() => { |
| 71 | const brewName = `${newProject.name.replace(/[\W_]+/g, "_")}_${newProject.id}`; |
| 72 | if (transaction) { |
| 73 | return db.Project.update({ brewName }, { where: { id: newProject.id }, transaction }); |
| 74 | } |
| 75 | |
| 76 | return this.update(newProject.id, { brewName }); |
| 77 | }) |
| 78 | .then(() => { |
| 79 | // now update the projects access in TeamRole |
| 80 | return this.teamController.addProjectAccess(data.team_id, userId, newProject.id, options); |
| 81 | }) |
| 82 | .then(() => { |
| 83 | return this.teamController.addProjectAccessToOwner(data.team_id, newProject.id, options); |
| 84 | }) |
| 85 | .then(() => { |
| 86 | if (transaction) { |
| 87 | return db.Project.findOne({ |
| 88 | where: { id: newProject.id }, |
| 89 | transaction, |
| 90 | }); |
| 91 | } |
| 92 | |
| 93 | return this.findById(newProject.id); |
| 94 | }) |
| 95 | .catch((error) => { |
| 96 | return new Promise((resolve, reject) => reject(error)); |
| 97 | }); |
| 98 | } |
| 99 | |
| 100 | update(id, data) { |
| 101 | const newFields = normalizeProjectScheduleTimezones(data); |
no test coverage detected