aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/runner/runner.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/runner/runner.ts')
-rw-r--r--server/models/runner/runner.ts124
1 files changed, 0 insertions, 124 deletions
diff --git a/server/models/runner/runner.ts b/server/models/runner/runner.ts
deleted file mode 100644
index 4d07707d8..000000000
--- a/server/models/runner/runner.ts
+++ /dev/null
@@ -1,124 +0,0 @@
1import { FindOptions } from 'sequelize'
2import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript'
3import { MRunner } from '@server/types/models/runners'
4import { Runner } from '@shared/models'
5import { AttributesOnly } from '@shared/typescript-utils'
6import { getSort } from '../shared'
7import { RunnerRegistrationTokenModel } from './runner-registration-token'
8import { CONSTRAINTS_FIELDS } from '@server/initializers/constants'
9
10@Table({
11 tableName: 'runner',
12 indexes: [
13 {
14 fields: [ 'runnerToken' ],
15 unique: true
16 },
17 {
18 fields: [ 'runnerRegistrationTokenId' ]
19 },
20 {
21 fields: [ 'name' ],
22 unique: true
23 }
24 ]
25})
26export class RunnerModel extends Model<Partial<AttributesOnly<RunnerModel>>> {
27
28 // Used to identify the appropriate runner when it uses the runner REST API
29 @AllowNull(false)
30 @Column
31 runnerToken: string
32
33 @AllowNull(false)
34 @Column
35 name: string
36
37 @AllowNull(true)
38 @Column(DataType.STRING(CONSTRAINTS_FIELDS.RUNNERS.DESCRIPTION.max))
39 description: string
40
41 @AllowNull(false)
42 @Column
43 lastContact: Date
44
45 @AllowNull(false)
46 @Column
47 ip: string
48
49 @CreatedAt
50 createdAt: Date
51
52 @UpdatedAt
53 updatedAt: Date
54
55 @ForeignKey(() => RunnerRegistrationTokenModel)
56 @Column
57 runnerRegistrationTokenId: number
58
59 @BelongsTo(() => RunnerRegistrationTokenModel, {
60 foreignKey: {
61 allowNull: false
62 },
63 onDelete: 'cascade'
64 })
65 RunnerRegistrationToken: RunnerRegistrationTokenModel
66
67 // ---------------------------------------------------------------------------
68
69 static load (id: number) {
70 return RunnerModel.findByPk(id)
71 }
72
73 static loadByToken (runnerToken: string) {
74 const query = {
75 where: { runnerToken }
76 }
77
78 return RunnerModel.findOne(query)
79 }
80
81 static loadByName (name: string) {
82 const query = {
83 where: { name }
84 }
85
86 return RunnerModel.findOne(query)
87 }
88
89 static listForApi (options: {
90 start: number
91 count: number
92 sort: string
93 }) {
94 const { start, count, sort } = options
95
96 const query: FindOptions = {
97 offset: start,
98 limit: count,
99 order: getSort(sort)
100 }
101
102 return Promise.all([
103 RunnerModel.count(query),
104 RunnerModel.findAll<MRunner>(query)
105 ]).then(([ total, data ]) => ({ total, data }))
106 }
107
108 // ---------------------------------------------------------------------------
109
110 toFormattedJSON (this: MRunner): Runner {
111 return {
112 id: this.id,
113
114 name: this.name,
115 description: this.description,
116
117 ip: this.ip,
118 lastContact: this.lastContact,
119
120 createdAt: this.createdAt,
121 updatedAt: this.updatedAt
122 }
123 }
124}