feat: refs #7965 added #6242 back to unify PR
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
632c1b2fc7
commit
568661021a
|
@ -0,0 +1,3 @@
|
|||
-- Place your SQL code here
|
||||
INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId)
|
||||
VALUES ('Ticket','getTicketProblems','READ','ALLOW','ROLE','employee');
|
|
@ -306,11 +306,7 @@ module.exports = Self => {
|
|||
(INDEX (ticketFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT f.id ticketFk
|
||||
FROM tmp.filter f
|
||||
LEFT JOIN alertLevel al ON al.id = f.alertLevel
|
||||
WHERE (al.code = 'FREE' OR f.alertLevel IS NULL)
|
||||
AND f.shipped >= ?
|
||||
`, [date]);
|
||||
FROM tmp.filter f`);
|
||||
|
||||
stmts.push(stmt);
|
||||
stmts.push('CALL ticket_getProblems(FALSE)');
|
||||
|
@ -330,34 +326,13 @@ module.exports = Self => {
|
|||
if (args.problems != undefined && (!args.from && !args.to))
|
||||
throw new UserError('Choose a date range or days forward');
|
||||
|
||||
let condition;
|
||||
let hasProblem;
|
||||
let hasWhere;
|
||||
switch (args.problems) {
|
||||
case true:
|
||||
condition = `or`;
|
||||
hasProblem = true;
|
||||
hasWhere = true;
|
||||
break;
|
||||
|
||||
case false:
|
||||
condition = `and`;
|
||||
hasProblem = null;
|
||||
hasWhere = true;
|
||||
break;
|
||||
if (typeof args.problems == 'boolean') {
|
||||
let condition = 0;
|
||||
if (args.problems)
|
||||
condition = {neq: condition};
|
||||
stmt.merge(conn.makeWhere({'tp.totalProblems': condition}));
|
||||
}
|
||||
|
||||
const problems = {[condition]: [
|
||||
{'tp.isFreezed': hasProblem},
|
||||
{'tp.hasRisk': hasProblem},
|
||||
{'tp.hasTicketRequest': hasProblem},
|
||||
{'tp.hasItemShortage': hasProblem},
|
||||
{'tp.hasRounding': hasProblem}
|
||||
]};
|
||||
|
||||
if (hasWhere)
|
||||
stmt.merge(conn.makeWhere(problems));
|
||||
|
||||
if (filter.order) {
|
||||
if (typeof filter.order == 'string') filter.order = [filter.order];
|
||||
const index = filter.order.findIndex(o => o.includes('stateFk'));
|
||||
|
|
|
@ -98,14 +98,9 @@ module.exports = Self => {
|
|||
|
||||
for (let sale of sales) {
|
||||
const problems = saleProblems.get(sale.id);
|
||||
const itemStock = itemAvailable.get(sale.itemFk);
|
||||
sale.available = itemStock.available;
|
||||
sale.visible = itemStock.visible;
|
||||
sale.claim = claimedSales.get(sale.id);
|
||||
if (problems) {
|
||||
sale.itemShortage = problems.itemShortage;
|
||||
sale.hasTicketRequest = problems.hasTicketRequest;
|
||||
sale.hasComponentLack = problems.hasComponentLack;
|
||||
for (const problem in problems)
|
||||
sale[problem] = problems[problem];
|
||||
}
|
||||
if (salesWithLogs.includes(sale.id))
|
||||
sale.$hasLogs = true;
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
const {buildFilter} = require('vn-loopback/util/filter');
|
||||
|
||||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('getTicketProblems', {
|
||||
description: 'Get problems for a ticket',
|
||||
accessType: 'READ',
|
||||
accepts: [{
|
||||
arg: 'id',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'The ticket id',
|
||||
http: {source: 'path'}
|
||||
}],
|
||||
returns: {
|
||||
type: ['object'],
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/getTicketProblems`,
|
||||
verb: 'get'
|
||||
}
|
||||
});
|
||||
|
||||
Self.getTicketProblems = async(ctx, id, options) => {
|
||||
const myOptions = {};
|
||||
const stmts = [];
|
||||
const conn = Self.dataSource.connector;
|
||||
let stmt;
|
||||
const ticketId = id;
|
||||
const where = buildFilter(ctx.args, param => {
|
||||
switch (param) {
|
||||
case 'id':
|
||||
return {'t.id': ticketId};
|
||||
}
|
||||
});
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
stmt = new ParameterizedSQL(`
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.filter
|
||||
(INDEX (id))
|
||||
ENGINE = MEMORY
|
||||
SELECT t.id
|
||||
FROM ticket t
|
||||
`);
|
||||
|
||||
stmt.merge(conn.makeWhere(where));
|
||||
stmts.push(stmt);
|
||||
|
||||
stmt = new ParameterizedSQL(`
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||
(INDEX (ticketFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT f.id AS ticketFk
|
||||
FROM tmp.filter f
|
||||
`);
|
||||
stmts.push(stmt);
|
||||
|
||||
stmts.push('CALL ticket_getProblems(FALSE)');
|
||||
|
||||
stmt = new ParameterizedSQL(`
|
||||
SELECT f.*, tp.*
|
||||
FROM tmp.filter f
|
||||
LEFT JOIN tmp.ticketProblems tp ON tp.ticketFk = f.id
|
||||
`);
|
||||
const ticketsIndex = stmts.push(stmt) - 1;
|
||||
|
||||
stmts.push(`
|
||||
DROP TEMPORARY TABLE IF EXISTS
|
||||
tmp.filter,
|
||||
tmp.ticket,
|
||||
tmp.ticketProblems
|
||||
`);
|
||||
|
||||
const sql = ParameterizedSQL.join(stmts, ';');
|
||||
const result = await conn.executeStmt(sql, myOptions);
|
||||
|
||||
return result[ticketsIndex];
|
||||
};
|
||||
};
|
|
@ -0,0 +1,21 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
fdescribe('ticket getTicketProblems()', () => {
|
||||
const ctx = {req: {accessToken: 9}};
|
||||
it('should return the problems of a ticket', async() => {
|
||||
const tx = await models.Ticket.beginTransaction({});
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
const problems = await models.Ticket.getTicketProblems(ctx, 11, options);
|
||||
|
||||
expect(problems[7].totalProblems).toEqual(3);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
|
@ -46,4 +46,5 @@ module.exports = function(Self) {
|
|||
require('../methods/ticket/docuwareDownload')(Self);
|
||||
require('../methods/ticket/myLastModified')(Self);
|
||||
require('../methods/ticket/setWeight')(Self);
|
||||
require('../methods/ticket/getTicketProblems')(Self);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue