feat: refs #7524 add mock limit on find query
gitea/salix/pipeline/pr-dev This commit looks good
Details
gitea/salix/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
parent
fcd26784bf
commit
766da06c2f
|
@ -115,6 +115,9 @@
|
|||
"NotificationSubscription": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"OrmConfig": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"Province": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"name": "OrmConfig",
|
||||
"base": "VnModel",
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "ormConfig"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "number",
|
||||
"id": true
|
||||
},
|
||||
"selectLimit": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$authenticated",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
USE vn;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS ormConfig (
|
||||
id int(5) NOT NULL AUTO_INCREMENT primary key,
|
||||
selectLimit int(5) NOT NULL
|
||||
);
|
||||
|
||||
INSERT IGNORE INTO ormConfig SET selectLimit = 1000;
|
|
@ -5,6 +5,7 @@ const utils = require('loopback/lib/utils');
|
|||
|
||||
module.exports = function(Self) {
|
||||
Self.ParameterizedSQL = ParameterizedSQL;
|
||||
let isSelect;
|
||||
|
||||
require('../methods/vn-model/getSetValues')(Self);
|
||||
require('../methods/vn-model/getEnumValues')(Self);
|
||||
|
@ -13,7 +14,6 @@ module.exports = function(Self) {
|
|||
Object.assign(Self, {
|
||||
setup() {
|
||||
Self.super_.setup.call(this);
|
||||
|
||||
/**
|
||||
* Setting a global transaction timeout to find out if the service
|
||||
* is blocked because the connection pool is empty.
|
||||
|
@ -28,6 +28,28 @@ module.exports = function(Self) {
|
|||
};
|
||||
});
|
||||
|
||||
/*
|
||||
* Intercept GET request for find
|
||||
*/
|
||||
this.beforeRemote('find', async function(ctx) {
|
||||
isSelect = true;
|
||||
const filter = ctx.args.filter || {};
|
||||
// const models = this.app.models;
|
||||
if (filter.limit === undefined) {
|
||||
// WIP
|
||||
// const {limit} = await models.OrmConfig.findOne(); Not working
|
||||
// const [{selectLimit: limit}] = await this.rawSql('SELECT selectLimit FROM ormConfig', null);
|
||||
filter.limit = 1/* limit */;
|
||||
ctx.args.filter = filter;
|
||||
}
|
||||
});
|
||||
|
||||
this.observe('loaded', async function({data}) {
|
||||
if (!isSelect) return;
|
||||
const length = Array.isArray(data) ? data.length : data ? 1 : 0;
|
||||
if (length >= 1) throw new UserError('Too many records');
|
||||
});
|
||||
|
||||
// Register field ACL validation
|
||||
/*
|
||||
this.beforeRemote('prototype.patchAttributes', ctx => this.checkUpdateAcls(ctx));
|
||||
|
|
|
@ -368,5 +368,6 @@
|
|||
"Payment method is required": "El método de pago es obligatorio",
|
||||
"Cannot send mail": "Não é possível enviar o email",
|
||||
"CONSTRAINT `supplierAccountTooShort` failed for `vn`.`supplier`": "La cuenta debe tener exactamente 10 dígitos",
|
||||
"The sale not exists in the item shelving": "La venta no existe en la estantería del artículo"
|
||||
"The sale not exists in the item shelving": "La venta no existe en la estantería del artículo",
|
||||
"Too many records": "Demasiados registros"
|
||||
}
|
Loading…
Reference in New Issue