/**
 * Created by Mai on 2017/6/13.
 */

let baseModel = require('./base_model');

class projCounter extends baseModel {
    constructor (name) {
        let db = require("../db/project_db");
        let Schema = require("mongoose").Schema;
        let projCounterSchema = new Schema({
            projectID: Number,
            bills: Number,
            ration: Number
        });
        let projCounterModel = db.model(name, projCounterSchema);
        super(projCounterModel);
        this.collectionName = name;
    };

    getData (projectID, callback) {
        this.model.findOne({"projectID": projectID}, '-_id', function (err, result) {
            if (!err) {
                callback(0, '', result);
            } else {
                callback(1, '查询数据失败。', null);
            }
        });
    };

    save (user_id, data, callback) {
        this.model.update({"projectID": data.projectID}, data, callback);
    }
};

module.exports = new projCounter('projCounter');
