feat: refs #6636 Added getEnumValue method
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
16a6e3d8a6
commit
6c1e44638e
|
@ -1 +1,15 @@
|
|||
CREATE OR REPLACE TEMPORARY TABLE tmp.claimsWithHasToPickUp
|
||||
SELECT id
|
||||
FROM vn.claim
|
||||
WHERE hasToPickUp;
|
||||
|
||||
ALTER TABLE vn.claim CHANGE hasToPickUp pickup ENUM('agency', 'delivery') DEFAULT NULL;
|
||||
|
||||
UPDATE vn.claim c
|
||||
JOIN tmp.claimsWithHasToPickUp tmp ON tmp.id = c.id
|
||||
SET c.pickup = 'delivery';
|
||||
|
||||
DROP TEMPORARY TABLE tmp.claimsWithHasToPickUp;
|
||||
|
||||
INSERT INTO salix.ACL (model,property,accessType,principalId)
|
||||
VALUES ('Application','getEnumValues','*','employee');
|
|
@ -0,0 +1,56 @@
|
|||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||
const UserError = require('vn-loopback/util/user-error');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('getEnumValues', {
|
||||
description: 'Return enum values of column',
|
||||
accessType: 'EXECUTE',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'schema',
|
||||
type: 'string',
|
||||
description: 'The schema of db',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'table',
|
||||
type: 'string',
|
||||
description: 'The table of schema',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'column',
|
||||
type: 'string',
|
||||
description: 'The column of table',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
returns: {
|
||||
type: 'any',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/get-enum-values`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.getEnumValues = async(schema, table, column) => {
|
||||
const stmt = new ParameterizedSQL(`
|
||||
SELECT COLUMN_TYPE
|
||||
FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = ?
|
||||
AND TABLE_NAME = ?
|
||||
AND COLUMN_NAME = ?
|
||||
AND DATA_TYPE = 'enum';`,
|
||||
[schema, table, column]);
|
||||
|
||||
const conn = Self.dataSource.connector;
|
||||
const [result] = await conn.executeStmt(stmt);
|
||||
|
||||
if (!result) throw new UserError(`No results found`);
|
||||
|
||||
const regex = /'([^']*)'/g;
|
||||
return result.COLUMN_TYPE.match(regex).map(match => match.slice(1, -1));
|
||||
};
|
||||
};
|
|
@ -5,4 +5,5 @@ module.exports = function(Self) {
|
|||
require('../methods/application/execute')(Self);
|
||||
require('../methods/application/executeProc')(Self);
|
||||
require('../methods/application/executeFunc')(Self);
|
||||
require('../methods/application/getEnumValues')(Self);
|
||||
};
|
||||
|
|
|
@ -351,5 +351,6 @@
|
|||
"The address of the customer must have information about Incoterms and Customs Agent": "El consignatario del cliente debe tener informado Incoterms y Agente de aduanas",
|
||||
"The line could not be marked": "La linea no puede ser marcada",
|
||||
"This password can only be changed by the user themselves": "Esta contraseña solo puede ser modificada por el propio usuario",
|
||||
"They're not your subordinate": "No es tu subordinado/a."
|
||||
"They're not your subordinate": "No es tu subordinado/a.",
|
||||
"No results found": "No se han encontrado resultados"
|
||||
}
|
Loading…
Reference in New Issue