1 | 'use strict'
|
2 |
|
3 | let cli = require('heroku-cli-util')
|
4 |
|
5 | class AppTransfer {
|
6 | |
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | constructor (opts) {
|
14 | this.opts = opts
|
15 | this.heroku = this.opts.heroku
|
16 | this.appName = this.opts.appName
|
17 | this.recipient = this.opts.recipient
|
18 | this.personalToPersonal = this.opts.personalToPersonal
|
19 |
|
20 | if (this.personalToPersonal === undefined) this.personalToPersonal = true
|
21 |
|
22 | if (this.personalToPersonal) {
|
23 | this.body = { app: this.appName, recipient: this.recipient }
|
24 | this.transferMsg = `Initiating transfer of ${cli.color.app(this.appName)}`
|
25 | if (!this.opts.bulk) this.transferMsg += ` to ${cli.color.magenta(this.recipient)}`
|
26 | this.path = '/account/app-transfers'
|
27 | this.method = 'POST'
|
28 | } else {
|
29 | this.body = { owner: this.recipient }
|
30 | this.transferMsg = `Transferring ${cli.color.app(this.appName)}`
|
31 | if (!this.opts.bulk) this.transferMsg += ` to ${cli.color.magenta(this.recipient)}`
|
32 | this.path = `/teams/apps/${this.appName}`
|
33 | this.method = 'PATCH'
|
34 | }
|
35 | }
|
36 |
|
37 | start () {
|
38 | let request = this.init().then(request => {
|
39 | if (request.state === 'pending') cli.action.done('email sent')
|
40 | })
|
41 | return cli.action(this.transferMsg, request)
|
42 | }
|
43 |
|
44 | init () {
|
45 | return this.heroku.request({
|
46 | path: this.path,
|
47 | method: this.method,
|
48 | body: this.body
|
49 | })
|
50 | }
|
51 | }
|
52 |
|
53 | module.exports = AppTransfer
|