deploy.js
959 Bytes
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
'use strict';
const Model = require('./model');
class Deploy extends Model {
constructor() {
super('deploys');
}
async insertOrUpdate({ projectId, host, env, building, state}) {
let doc = await this.findOne({
projectId: projectId,
host: host,
env
});
let data = {
projectId: projectId,
host: host,
env,
building: building,
state: state
};
if (doc && doc._id) {
await this.update({
_id: doc._id
}, {
$set: data
});
return doc._id;
} else {
let ret = await this.insert(data);
return Array.isArray(ret) ? ret[0]._id : ret._id;
}
}
updateState(id, state){
return this.update({_id: id}, {$set: {
state: state
}});
}
}
module.exports = Deploy;