2017-12-21 1 views
0

나는 Feathers.js몽구스을 사용하고 있으며 서비스로 변경할 수없는 필드를 만들고 싶습니다.서비스 변경 방지 방법

// account-model.js - A mongoose model 
// 
// See http://mongoosejs.com/docs/models.html 
// for more of what you can do here. 
const mongoose = require('mongoose'); 
require('mongoose-type-email'); 

module.exports = function(app) { 
    const mongooseClient = app.get('mongooseClient'); 

    const recovery = new mongooseClient.Schema({ 
    token: { type: String, required: true } 
    }, { 
    timestamps: true 
    }); 

    const account = new mongooseClient.Schema({ 
    firstName: { type: String, required: true }, 
    surname: { type: String, require: true }, 
    phone: { type: String, require: true }, 
    email: { type: mongoose.SchemaTypes.Email, required: true, unique: true }, 
    birth: { type: Date, required: true }, 
    gender: { type: String, required: true }, 
    country: { type: String, required: true }, 
    address: { type: String, required: true }, 
    address2: { type: String, required: false }, 
    city: { type: String, required: true }, 
    postcode: { type: String, required: true }, 
    password: { type: String, required: true }, 
    status: { type: String, required true } 
    }, { 
    timestamps: true 
    }); 

    return mongooseClient.model('account', account); 
}; 

아무도 /account/<id>에서 게시물을하지 않으며 분야 status을 변경할 수 있습니다. 이 필드는 내부적으로 만 변경해야합니다. 일부 승인 서비스 요청.

이 동작을 어떻게 구현할 수 있습니까?

답변

1

Feathers hooks의 완벽한 사용 사례입니다. params.provider 그렇게 설정됩니다 service method 전화에 외부에서 접근 할 때 당신이 그것을 확인하고 data에서 필드를 제거 할 수는 경우 :

module.exports = function() { 
    return async context => { 
    if(context.params.provider) { 
     delete context.data.status; 
    } 
    } 
} 

이 후크는 create, updatepatch 방법에 대한 before 후크 될 것입니다 .