Skip to content

Commit

Permalink
feat: support define options queryKeyWhiteList.where and `queryKeyW…
Browse files Browse the repository at this point in the history
…hiteList.findBy`
  • Loading branch information
richardo2016 committed Jul 27, 2022
1 parent 92aa08e commit 1041058
Show file tree
Hide file tree
Showing 19 changed files with 1,403 additions and 213 deletions.
10 changes: 5 additions & 5 deletions demo/defs/acl/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ describe("acl", () => {
}
});
check_result(rep.json(), {
"code": 4030301,
"code": 4030501,
"message": "The operation isn’t allowed to 'test_acl' for clients due to class-level permissions."
});

Expand Down Expand Up @@ -385,7 +385,7 @@ describe("acl", () => {

var rep = http.get(tSrvInfo.appUrlBase + `/test_acl/${id}`);
check_result(rep.json(), {
"code": 4030501,
"code": 4030701,
"message": "The operation isn’t allowed to 'test_acl' for clients due to class-level permissions."
});

Expand Down Expand Up @@ -440,7 +440,7 @@ describe("acl", () => {
}
});
check_result(rep.json(), {
"code": 4030501,
"code": 4030701,
"message": "The operation isn’t allowed to 'test_acl' for clients due to class-level permissions."
});

Expand Down Expand Up @@ -484,7 +484,7 @@ describe("acl", () => {

var rep = http.get(tSrvInfo.appUrlBase + `/test_acl/${id}/ext`);
check_result(rep.json(), {
"code": 4030301,
"code": 4030501,
"message": "The operation isn’t allowed to 'test_acl' for clients due to class-level permissions."
});

Expand Down Expand Up @@ -533,7 +533,7 @@ describe("acl", () => {

var rep = http.del(tSrvInfo.appUrlBase + `/test_acl/${id}/ext/${rid1}`);
check_result(rep.json(), {
"code": 4030301,
"code": 4030501,
"message": "The operation isn’t allowed to 'test_acl' for clients due to class-level permissions."
});

Expand Down
1 change: 1 addition & 0 deletions demo/defs/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = [
require('./user'),
require('./person'),
require('./person_query'),
require('./acl'),
require('./city'),
require('./people'),
Expand Down
66 changes: 66 additions & 0 deletions demo/defs/person_query/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const orm = require('@fxjs/orm');
const util = require('util')

const assert = require('assert')

module.exports = db => {
db.define('person_query', {
name: String,
sex: ["male", "female"],
age: Number
}, {
validations: {
age: orm.enforce.ranges.number(10, 18, "teenage")
},
functions: {
test: (req, data) => {
return {
success: {
message: "test",
data: data
}
}
},

getPersonByName: (req, data) => {
const app = db.app
const findRep = app.api.find({
...req,
query: {
...req.query,
where: {name: { eq: data.name }}
}
}, db, db.models['person_query'])

if (findRep.error) {
throw findRep.error
}

return {
success: {
message: 'ok',
data: findRep.success.map(x => util.pick(x, 'name'))
}
};
}
},
webx: {
queryKeyWhiteList: {
where: ['id'],
}
},
});

var PetQuery = db.define('pet_query', {
name: String
}, {
webx: {
queryKeyWhiteList: {
findby: ['createdBy'],
}
},
});

PetQuery.hasOne('createdBy', db.models.person_query);
PetQuery.hasOne('createdBy2', db.models.person_query);
};
Loading

0 comments on commit 1041058

Please sign in to comment.