如何防止服务的变化

时间:2017-12-21 20:51:29

标签: node.js mongodb validation mongoose feathersjs

我将 Feathers.js Mongoose 一起使用,我想创建一个服务无法更改的字段。

<script>

没有人可以在// 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>。 该字段只能在内部更改。当一些批准服务请求时。

如何实现此行为?

1 个答案:

答案 0 :(得分:1)

这是Feathers hooks的完美用例。如果在外部访问,则会在service method来电params.provider中进行设置,以便您检查并删除<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> </head> <body> <div class="row col-md-12"> <asp:RadioButtonList ID="rblCleanliness" RepeatDirection="Horizontal" runat="server"> <asp:ListItem Value="1" class="box col-md-2 1">rb1</asp:ListItem> <asp:ListItem Value="2" class="box col-md-2 2">rb2</asp:ListItem> <asp:ListItem Value="3" class="box col-md-2 3">rb3</asp:ListItem> <asp:ListItem Value="4" class="box col-md-2 4">rb4</asp:ListItem> <asp:ListItem Value="5" class="box col-md-2 5">rb5</asp:ListItem> </asp:RadioButtonList> </div> </body> 字段,如果是:

data

此挂钩将是module.exports = function() { return async context => { if(context.params.provider) { delete context.data.status; } } } beforecreate方法的update挂钩。