deploy.js 952 Bytes
'use strict';

import Model from './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
        }});
    }
}

export default Deploy;