accept array in params
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
b421038bbe
commit
a136d8b03d
|
@ -40,7 +40,6 @@ module.exports = Self => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const salesIds = [];
|
const salesIds = [];
|
||||||
const params = [];
|
|
||||||
const userId = ctx.req.accessToken.userId;
|
const userId = ctx.req.accessToken.userId;
|
||||||
|
|
||||||
const isClaimManager = await Self.app.models.Account.hasRole(userId, 'claimManager');
|
const isClaimManager = await Self.app.models.Account.hasRole(userId, 'claimManager');
|
||||||
|
@ -50,23 +49,19 @@ module.exports = Self => {
|
||||||
if (!hasValidRole)
|
if (!hasValidRole)
|
||||||
throw new UserError(`You don't have privileges to create pay back`);
|
throw new UserError(`You don't have privileges to create pay back`);
|
||||||
|
|
||||||
sales.forEach(sale => {
|
for (let sale of sales)
|
||||||
salesIds.push(sale.id);
|
salesIds.push(sale.id);
|
||||||
params.push('?');
|
|
||||||
});
|
|
||||||
|
|
||||||
const paramsString = params.join();
|
|
||||||
|
|
||||||
const query = `
|
const query = `
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.sale;
|
DROP TEMPORARY TABLE IF EXISTS tmp.sale;
|
||||||
CREATE TEMPORARY TABLE tmp.sale
|
CREATE TEMPORARY TABLE tmp.sale
|
||||||
SELECT s.id, s.itemFk, - s.quantity, s.concept, s.price, s.discount
|
SELECT s.id, s.itemFk, - s.quantity, s.concept, s.price, s.discount
|
||||||
FROM sale s
|
FROM sale s
|
||||||
WHERE s.id IN (${paramsString});
|
WHERE s.id IN (?);
|
||||||
CALL vn.ticket_doRefund(${ticketId}, @newTicket);
|
CALL vn.ticket_doRefund(?, @newTicket);
|
||||||
DROP TEMPORARY TABLE tmp.sale;`;
|
DROP TEMPORARY TABLE tmp.sale;`;
|
||||||
|
|
||||||
await Self.rawSql(query, salesIds, myOptions);
|
await Self.rawSql(query, [salesIds, ticketId], myOptions);
|
||||||
const [newTicket] = await Self.rawSql('SELECT @newTicket id', null, myOptions);
|
const [newTicket] = await Self.rawSql('SELECT @newTicket id', null, myOptions);
|
||||||
ticketId = newTicket.id;
|
ticketId = newTicket.id;
|
||||||
|
|
||||||
|
|
|
@ -35,11 +35,8 @@ module.exports = Self => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const salesIds = [];
|
const salesIds = [];
|
||||||
const params = [];
|
for (let sale of sales)
|
||||||
sales.forEach(sale => {
|
|
||||||
salesIds.push(sale.id);
|
salesIds.push(sale.id);
|
||||||
params.push('?');
|
|
||||||
});
|
|
||||||
|
|
||||||
const isEditable = await models.Ticket.isEditable(ctx, sales[0].ticketFk, myOptions);
|
const isEditable = await models.Ticket.isEditable(ctx, sales[0].ticketFk, myOptions);
|
||||||
if (!isEditable)
|
if (!isEditable)
|
||||||
|
@ -49,14 +46,12 @@ module.exports = Self => {
|
||||||
if (!canEditSale)
|
if (!canEditSale)
|
||||||
throw new UserError(`Sale(s) blocked, please contact production`);
|
throw new UserError(`Sale(s) blocked, please contact production`);
|
||||||
|
|
||||||
const paramsString = params.join();
|
|
||||||
|
|
||||||
const query = `
|
const query = `
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.recalculateSales;
|
DROP TEMPORARY TABLE IF EXISTS tmp.recalculateSales;
|
||||||
CREATE TEMPORARY TABLE tmp.recalculateSales
|
CREATE TEMPORARY TABLE tmp.recalculateSales
|
||||||
SELECT s.id
|
SELECT s.id
|
||||||
FROM sale s
|
FROM sale s
|
||||||
WHERE s.id IN (${paramsString});
|
WHERE s.id IN (?);
|
||||||
CALL vn.sale_recalcComponent(null);
|
CALL vn.sale_recalcComponent(null);
|
||||||
DROP TEMPORARY TABLE tmp.recalculateSales;`;
|
DROP TEMPORARY TABLE tmp.recalculateSales;`;
|
||||||
|
|
||||||
|
|
|
@ -30,14 +30,6 @@ module.exports = Self => {
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
const params = [];
|
|
||||||
const paramsSql = [date, date, date];
|
|
||||||
for (id of zonesId) {
|
|
||||||
params.push('?');
|
|
||||||
paramsSql.push(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
const paramsString = params.join();
|
|
||||||
query = `
|
query = `
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM (
|
FROM (
|
||||||
|
@ -56,10 +48,10 @@ module.exports = Self => {
|
||||||
OR ? BETWEEN started AND ended
|
OR ? BETWEEN started AND ended
|
||||||
OR INSTR(weekDays, SUBSTRING(DAYNAME(?), 1, 3) ) > 0
|
OR INSTR(weekDays, SUBSTRING(DAYNAME(?), 1, 3) ) > 0
|
||||||
)
|
)
|
||||||
AND z.id IN (${paramsString})
|
AND z.id IN (?)
|
||||||
ORDER BY type='day' DESC, type='range' DESC, type='indefinitely' DESC) z
|
ORDER BY type='day' DESC, type='range' DESC, type='indefinitely' DESC) z
|
||||||
GROUP BY z.id`;
|
GROUP BY z.id`;
|
||||||
|
|
||||||
return await Self.rawSql(query, paramsSql, myOptions);
|
return Self.rawSql(query, [date, date, date, zonesId], myOptions);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue