1
0
Fork 0
mirror of synced 2024-09-28 23:31:43 +12:00
budibase/packages/server/src/api/controllers/deploy/Deployment.js

89 lines
1.6 KiB
JavaScript
Raw Normal View History

const { getAppQuota } = require("./quota")
const env = require("../../../environment")
const newid = require("../../../db/newid")
/**
* This is used to pass around information about the deployment that is occurring
*/
class Deployment {
constructor(appId, id = null) {
this.appId = appId
this._id = id || newid()
}
// purely so that we can do quota stuff outside the main deployment context
async init() {
if (!env.SELF_HOSTED) {
this.setQuota(await getAppQuota(this.appId))
}
}
setQuota(quota) {
2020-12-05 01:07:51 +13:00
if (!quota) {
return
}
this.quota = quota
}
getQuota() {
return this.quota
}
getAppId() {
return this.appId
}
setVerification(verification) {
2020-12-05 01:07:51 +13:00
if (!verification) {
return
}
if (this.verification.quota) {
this.quota = this.verification.quota
}
this.verification = verification
}
getVerification() {
return this.verification
}
setStatus(status, err = null) {
this.status = status
if (err) {
this.err = err
}
}
fromJSON(json) {
if (json.verification) {
this.setVerification(json.verification)
}
if (json.quota) {
this.setQuota(json.quota)
}
if (json.status) {
this.setStatus(json.status, json.err)
}
}
getJSON() {
const obj = {
_id: this._id,
appId: this.appId,
status: this.status,
}
if (this.err) {
obj.err = this.err
}
if (this.verification && this.verification.cfDistribution) {
obj.cfDistribution = this.verification.cfDistribution
}
if (this.quota) {
obj.quota = this.quota
}
return obj
}
}
module.exports = Deployment