Merge branch 'dev' into 5749-autoincrement-zoneIncluded
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
commit
39a0f13500
|
@ -23,10 +23,6 @@
|
||||||
"columnName": "name"
|
"columnName": "name"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"password": {
|
|
||||||
"type": "string",
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
"roleFk": {
|
"roleFk": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"mysql": {
|
"mysql": {
|
||||||
|
@ -42,9 +38,6 @@
|
||||||
"active": {
|
"active": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
"email": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"created": {
|
"created": {
|
||||||
"type": "date"
|
"type": "date"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,15 +1,24 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('Client transactions', () => {
|
describe('Client transactions', () => {
|
||||||
|
const ctx = {};
|
||||||
|
|
||||||
it('should call transactions() method to receive a list of Web Payments from BRUCE WAYNE', async() => {
|
it('should call transactions() method to receive a list of Web Payments from BRUCE WAYNE', async() => {
|
||||||
const tx = await models.Client.beginTransaction({});
|
const tx = await models.Client.beginTransaction({});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
const ctx = {};
|
|
||||||
const filter = {where: {clientFk: 1101}};
|
const filter = {where: {clientFk: 1101}};
|
||||||
const result = await models.Client.transactions(ctx, filter, options);
|
const result = await models.Client.transactions(
|
||||||
|
ctx,
|
||||||
|
filter,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
options
|
||||||
|
);
|
||||||
|
|
||||||
expect(result[1].id).toBeTruthy();
|
expect(result[1].id).toBeTruthy();
|
||||||
|
|
||||||
|
@ -26,9 +35,17 @@ describe('Client transactions', () => {
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
const ctx = {args: {orderFk: 6}};
|
|
||||||
const filter = {};
|
const filter = {};
|
||||||
const result = await models.Client.transactions(ctx, filter, options);
|
const result = await models.Client.transactions(
|
||||||
|
ctx,
|
||||||
|
filter,
|
||||||
|
6,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
options
|
||||||
|
);
|
||||||
|
|
||||||
const firstRow = result[0];
|
const firstRow = result[0];
|
||||||
|
|
||||||
|
@ -47,10 +64,17 @@ describe('Client transactions', () => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
const ctx = {args: {amount: 40}};
|
|
||||||
const filter = {};
|
const filter = {};
|
||||||
const result = await models.Client.transactions(ctx, filter, options);
|
const result = await models.Client.transactions(
|
||||||
|
ctx,
|
||||||
|
filter,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
40,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
options
|
||||||
|
);
|
||||||
|
|
||||||
const randomIndex = Math.floor(Math.random() * result.length);
|
const randomIndex = Math.floor(Math.random() * result.length);
|
||||||
const transaction = result[randomIndex];
|
const transaction = result[randomIndex];
|
||||||
|
@ -63,4 +87,43 @@ describe('Client transactions', () => {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should call transactions() method filtering by date', async() => {
|
||||||
|
const tx = await models.Client.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
const filter = {};
|
||||||
|
const withResults = await models.Client.transactions(
|
||||||
|
ctx,
|
||||||
|
filter,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
'2000/12/31',
|
||||||
|
undefined,
|
||||||
|
options
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(withResults.length).toEqual(6);
|
||||||
|
|
||||||
|
const noResults = await models.Client.transactions(
|
||||||
|
ctx,
|
||||||
|
filter,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
'2099/12/31',
|
||||||
|
undefined,
|
||||||
|
options
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(noResults.length).toEqual(0);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -12,22 +12,26 @@ module.exports = Self => {
|
||||||
arg: 'filter',
|
arg: 'filter',
|
||||||
type: 'object',
|
type: 'object',
|
||||||
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string',
|
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string',
|
||||||
http: {source: 'query'}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'orderFk',
|
arg: 'orderFk',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
http: {source: 'query'}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'clientFk',
|
arg: 'clientFk',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
http: {source: 'query'}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'amount',
|
arg: 'amount',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
http: {source: 'query'}
|
},
|
||||||
|
{
|
||||||
|
arg: 'from',
|
||||||
|
type: 'date',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'to',
|
||||||
|
type: 'date',
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
returns: {
|
returns: {
|
||||||
|
@ -40,14 +44,15 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.transactions = async(ctx, filter, options) => {
|
Self.transactions = async(ctx, filter, orderFk, clientFk, amount, from, to, options) => {
|
||||||
const args = ctx.args;
|
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
const where = buildFilter(args, (param, value) => {
|
if (to) to.setHours(23, 59, 59, 999);
|
||||||
|
|
||||||
|
const where = buildFilter({orderFk, clientFk, amount, from, to}, (param, value) => {
|
||||||
switch (param) {
|
switch (param) {
|
||||||
case 'orderFk':
|
case 'orderFk':
|
||||||
return {'t.id': value};
|
return {'t.id': value};
|
||||||
|
@ -55,6 +60,10 @@ module.exports = Self => {
|
||||||
return {'t.clientFk': value};
|
return {'t.clientFk': value};
|
||||||
case 'amount':
|
case 'amount':
|
||||||
return {'t.amount': (value * 100)};
|
return {'t.amount': (value * 100)};
|
||||||
|
case 'from':
|
||||||
|
return {'t.created': {gte: value}};
|
||||||
|
case 'to':
|
||||||
|
return {'t.created': {lte: value}};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -138,14 +138,15 @@ module.exports = Self => {
|
||||||
// Update original sale
|
// Update original sale
|
||||||
const rest = originalSale.quantity - sale.quantity;
|
const rest = originalSale.quantity - sale.quantity;
|
||||||
query = `UPDATE sale
|
query = `UPDATE sale
|
||||||
SET quantity = ?
|
SET quantity = ?,
|
||||||
|
originalQuantity = ?
|
||||||
WHERE id = ?`;
|
WHERE id = ?`;
|
||||||
await Self.rawSql(query, [rest, sale.id], options);
|
await Self.rawSql(query, [rest, rest, sale.id], options);
|
||||||
|
|
||||||
// Clone sale with new quantity
|
// Clone sale with new quantity
|
||||||
query = `INSERT INTO sale (itemFk, ticketFk, concept, quantity, originalQuantity, price, discount, priceFixed,
|
query = `INSERT INTO sale (itemFk, ticketFk, concept, quantity, price, discount, priceFixed,
|
||||||
reserved, isPicked, isPriceFixed, isAdded)
|
reserved, isPicked, isPriceFixed, isAdded)
|
||||||
SELECT itemFk, ?, concept, ?, originalQuantity, price, discount, priceFixed,
|
SELECT itemFk, ?, concept, ?, price, discount, priceFixed,
|
||||||
reserved, isPicked, isPriceFixed, isAdded
|
reserved, isPicked, isPriceFixed, isAdded
|
||||||
FROM sale
|
FROM sale
|
||||||
WHERE id = ?`;
|
WHERE id = ?`;
|
||||||
|
|
Loading…
Reference in New Issue