-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathCompanySetup.ts
More file actions
87 lines (86 loc) · 2.93 KB
/
Copy pathCompanySetup.ts
File metadata and controls
87 lines (86 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import Spinner from '../helper/spinner';
import CompanySetupService from './api/services/company_setup.service';
import { getCompanyId } from '../helper/extension_utils';
import { successBox } from '../helper/formatter';
import CommandError, { ErrorCodes } from '../lib/CommandError';
import Logger from './Logger';
import urljoin from 'url-join';
import { getPlatformUrls } from './api/services/url';
import Debug from './Debug';
export default class CompanySetup {
constructor() {}
public static async setupDevelopmentCompany(options) {
const spinner = new Spinner();
try {
let request_id, next_step;
let prompt_message = 'Creating Brand';
let companyID = options.companyId;
if(!companyID){
companyID = await getCompanyId("Select the development company you'd like to populate data: ?");
}
await CompanySetup.setupComponent(
companyID,
request_id,
prompt_message,
spinner,
);
spinner.stop();
} catch (error) {
Debug(error)
if (error.code != ErrorCodes.API_ERROR) {
spinner.fail(
'Failed during populating development company, please retry!',
);
throw new Error('Failed during populating development company');
}
throw new CommandError(error.message, error.code);
}
}
private static async setupComponent(
company_id,
request_id,
prompt_message,
spinner,
) {
const { data, headers } = await CompanySetupService.setupCompany(
company_id,
request_id,
);
spinner.start(data.message);
if (data.next_step) {
setTimeout(async () => {
try{
return await CompanySetup.setupComponent(
company_id,
data.request_id,
data.prompt_message,
spinner,
);
}
catch(error){
Debug(error);
throw error;
}
}, data.cli_wait_time || 100);
} else {
spinner.succeed(
'Development company is now populated with sample data.',
);
const createDevelopmentCompanyFormURL = company_id
? urljoin(
getPlatformUrls().platform,
'company',
`${company_id}`,
'products',
'list',
)
: getPlatformUrls().platform;
Logger.info(
successBox({
text: `Check sample products: ${createDevelopmentCompanyFormURL}`,
}),
);
}
return data;
}
}