-
Notifications
You must be signed in to change notification settings - Fork 19
/
get-service-type.ts
79 lines (73 loc) · 2.75 KB
/
get-service-type.ts
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
import {
ApplicationEntity,
ContainerApplicationEntity,
DatabaseEntity,
GitApplicationEntity,
JobApplicationEntity,
} from '@qovery/shared/interfaces'
import { ServiceTypeEnum } from '../service-type.enum'
export const getServiceType = (data: ApplicationEntity | DatabaseEntity) => {
let currentType: ServiceTypeEnum
const isJob = (data as JobApplicationEntity).max_nb_restart !== undefined
if ((data as ContainerApplicationEntity).image_name) {
currentType = ServiceTypeEnum.CONTAINER
} else if (!(data as GitApplicationEntity).build_mode && !(data as ContainerApplicationEntity).image_name && !isJob) {
currentType = ServiceTypeEnum.DATABASE
} else if (isJob && (data as JobApplicationEntity).schedule?.cronjob) {
currentType = ServiceTypeEnum.CRON_JOB
} else if (isJob && !(data as JobApplicationEntity).schedule?.cronjob) {
currentType = ServiceTypeEnum.LIFECYCLE_JOB
} else {
currentType = ServiceTypeEnum.APPLICATION
}
return currentType
}
// Job
export const isJob = (data?: ApplicationEntity | ServiceTypeEnum) => {
if (data && (data as ApplicationEntity).id) {
return (
getServiceType(data as ApplicationEntity) === ServiceTypeEnum.CRON_JOB ||
getServiceType(data as ApplicationEntity) === ServiceTypeEnum.LIFECYCLE_JOB
)
} else {
return data === ServiceTypeEnum.CRON_JOB || data === ServiceTypeEnum.LIFECYCLE_JOB || data === ServiceTypeEnum.JOB
}
}
export const isCronJob = (data?: ApplicationEntity | ServiceTypeEnum) => {
if (data && (data as ApplicationEntity).id) {
return getServiceType(data as ApplicationEntity) === ServiceTypeEnum.CRON_JOB
} else {
return data === ServiceTypeEnum.CRON_JOB
}
}
export const isLifeCycleJob = (data?: ApplicationEntity | ServiceTypeEnum) => {
if (data as ApplicationEntity) {
return getServiceType(data as ApplicationEntity) === ServiceTypeEnum.LIFECYCLE_JOB
} else {
return data === ServiceTypeEnum.LIFECYCLE_JOB
}
}
// Container
export const isContainer = (data?: ApplicationEntity | ServiceTypeEnum) => {
if (data && (data as ApplicationEntity).id) {
return getServiceType(data as ApplicationEntity) === ServiceTypeEnum.CONTAINER
} else {
return data === ServiceTypeEnum.CONTAINER
}
}
// Application
export const isApplication = (data?: ApplicationEntity | ServiceTypeEnum) => {
if (data && (data as ApplicationEntity).id) {
return getServiceType(data as ApplicationEntity) === ServiceTypeEnum.APPLICATION
} else {
return data === ServiceTypeEnum.APPLICATION
}
}
// Database
export const isDatabase = (data?: DatabaseEntity | ServiceTypeEnum) => {
if ((data as DatabaseEntity).id) {
return getServiceType(data as DatabaseEntity) === ServiceTypeEnum.DATABASE
} else {
return data === ServiceTypeEnum.DATABASE
}
}