feat: refs #7524 add mock limit on find query
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Jorge Penadés 2024-07-30 09:40:34 +02:00
parent fcd26784bf
commit 766da06c2f
5 changed files with 62 additions and 2 deletions

View File

@ -115,6 +115,9 @@
"NotificationSubscription": { "NotificationSubscription": {
"dataSource": "vn" "dataSource": "vn"
}, },
"OrmConfig": {
"dataSource": "vn"
},
"Province": { "Province": {
"dataSource": "vn" "dataSource": "vn"
}, },

View File

@ -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"
}
]
}

View File

@ -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;

View File

@ -5,6 +5,7 @@ const utils = require('loopback/lib/utils');
module.exports = function(Self) { module.exports = function(Self) {
Self.ParameterizedSQL = ParameterizedSQL; Self.ParameterizedSQL = ParameterizedSQL;
let isSelect;
require('../methods/vn-model/getSetValues')(Self); require('../methods/vn-model/getSetValues')(Self);
require('../methods/vn-model/getEnumValues')(Self); require('../methods/vn-model/getEnumValues')(Self);
@ -13,7 +14,6 @@ module.exports = function(Self) {
Object.assign(Self, { Object.assign(Self, {
setup() { setup() {
Self.super_.setup.call(this); Self.super_.setup.call(this);
/** /**
* Setting a global transaction timeout to find out if the service * Setting a global transaction timeout to find out if the service
* is blocked because the connection pool is empty. * 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 // Register field ACL validation
/* /*
this.beforeRemote('prototype.patchAttributes', ctx => this.checkUpdateAcls(ctx)); this.beforeRemote('prototype.patchAttributes', ctx => this.checkUpdateAcls(ctx));

View File

@ -368,5 +368,6 @@
"Payment method is required": "El método de pago es obligatorio", "Payment method is required": "El método de pago es obligatorio",
"Cannot send mail": "Não é possível enviar o email", "Cannot send mail": "Não é possível enviar o email",
"CONSTRAINT `supplierAccountTooShort` failed for `vn`.`supplier`": "La cuenta debe tener exactamente 10 dígitos", "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"
} }