3973-monitor-client_dateFilter_Master #965

Merged
joan merged 6 commits from 3973-monitor-client_dateFilter into master 2022-05-09 07:28:34 +00:00
8 changed files with 109 additions and 65 deletions

View File

@ -1,5 +1,5 @@
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('setSaleQuantity', { Self.remoteMethod('setSaleQuantity', {
description: 'Update sale quantity', description: 'Update sale quantity',
accessType: 'WRITE', accessType: 'WRITE',
accepts: [{ accepts: [{
@ -24,11 +24,13 @@ module.exports = Self => {
} }
}); });
Self.setSaleQuantity = async ctx => { Self.setSaleQuantity = async(saleId, quantity) => {
const args = ctx.args;
const models = Self.app.models; const models = Self.app.models;
const sale = await models.Sale.findById(args.saleId,); const sale = await models.Sale.findById(saleId);
return await sale.updateAttribute('quantity', args.quantity); return await sale.updateAttributes({
originalQuantity: sale.quantity,
quantity: quantity
});
}; };
}; };

View File

@ -5,19 +5,12 @@ describe('setSaleQuantity()', () => {
const saleId = 30; const saleId = 30;
const newQuantity = 10; const newQuantity = 10;
const ctx = {
args: {
saleId: saleId,
quantity: newQuantity
}
};
const originalSale = await models.Sale.findById(saleId); const originalSale = await models.Sale.findById(saleId);
await models.Collection.setSaleQuantity(ctx); await models.Collection.setSaleQuantity(saleId, newQuantity);
const updateSale = await models.Sale.findById(saleId); const updateSale = await models.Sale.findById(saleId);
expect(updateSale.quantity).toBeLessThan(originalSale.quantity); expect(updateSale.originalQuantity).toEqual(originalSale.quantity);
expect(updateSale.quantity).toEqual(newQuantity); expect(updateSale.quantity).toEqual(newQuantity);
}); });
}); });

View File

@ -1648,7 +1648,9 @@ INSERT INTO `hedera`.`visit`(`id`, `firstAgentFk`)
(6, NULL), (6, NULL),
(7, NULL), (7, NULL),
(8, NULL), (8, NULL),
(9, NULL); (9, NULL),
(10, NULL),
(11, NULL);
INSERT INTO `hedera`.`visitAgent`(`id`, `visitFk`) INSERT INTO `hedera`.`visitAgent`(`id`, `visitFk`)
VALUES VALUES
@ -1660,7 +1662,9 @@ INSERT INTO `hedera`.`visitAgent`(`id`, `visitFk`)
(6, 6), (6, 6),
(7, 7), (7, 7),
(8, 8), (8, 8),
(9, 9); (9, 9),
(10, 10),
(11, 11);
INSERT INTO `hedera`.`visitAccess`(`id`, `agentFk`, `stamp`) INSERT INTO `hedera`.`visitAccess`(`id`, `agentFk`, `stamp`)
VALUES VALUES
@ -1672,7 +1676,9 @@ INSERT INTO `hedera`.`visitAccess`(`id`, `agentFk`, `stamp`)
(6, 6, CURDATE()), (6, 6, CURDATE()),
(7, 7, CURDATE()), (7, 7, CURDATE()),
(8, 8, CURDATE()), (8, 8, CURDATE()),
(9, 9, CURDATE()); (9, 9, CURDATE()),
(10, 10, CURDATE()),
(11, 11, CURDATE());
INSERT INTO `hedera`.`visitUser`(`id`, `accessFk`, `userFk`, `stamp`) INSERT INTO `hedera`.`visitUser`(`id`, `accessFk`, `userFk`, `stamp`)
VALUES VALUES
@ -1684,7 +1690,9 @@ INSERT INTO `hedera`.`visitUser`(`id`, `accessFk`, `userFk`, `stamp`)
(6, 6, 1102, CURDATE()), (6, 6, 1102, CURDATE()),
(7, 7, 1103, CURDATE()), (7, 7, 1103, CURDATE()),
(8, 8, 1103, CURDATE()), (8, 8, 1103, CURDATE()),
(9, 9, 1103, CURDATE()); (9, 9, 1103, CURDATE()),
(10, 10, 1102, DATE_SUB(CURDATE(), INTERVAL 1 DAY)),
(11, 11, 1103, DATE_SUB(CURDATE(), INTERVAL 1 DAY));
INSERT INTO `hedera`.`userSession`(`created`, `lastUpdate`, `ssid`, `data`, `userVisitFk`) INSERT INTO `hedera`.`userSession`(`created`, `lastUpdate`, `ssid`, `data`, `userVisitFk`)
VALUES VALUES

View File

@ -43,11 +43,9 @@ module.exports = Self => {
TIME(v.stamp) AS hour, TIME(v.stamp) AS hour,
DATE(v.stamp) AS dated, DATE(v.stamp) AS dated,
wtc.workerFk wtc.workerFk
FROM hedera.userSession s FROM hedera.visitUser v
JOIN hedera.visitUser v ON v.id = s.userVisitFk
JOIN client c ON c.id = v.userFk JOIN client c ON c.id = v.userFk
LEFT JOIN account.user u ON c.salesPersonFk = u.id JOIN account.user u ON c.salesPersonFk = u.id
LEFT JOIN worker w ON c.salesPersonFk = w.id
LEFT JOIN sharingCart sc ON sc.workerFk = c.salesPersonFk LEFT JOIN sharingCart sc ON sc.workerFk = c.salesPersonFk
AND CURDATE() BETWEEN sc.started AND sc.ended AND CURDATE() BETWEEN sc.started AND sc.ended
LEFT JOIN workerTeamCollegues wtc LEFT JOIN workerTeamCollegues wtc
@ -58,7 +56,9 @@ module.exports = Self => {
const where = filter.where; const where = filter.where;
where['wtc.workerFk'] = userId; where['wtc.workerFk'] = userId;
stmt.merge(conn.makeSuffix(filter)); stmt.merge(conn.makeWhere(filter.where));
stmt.merge(`GROUP BY clientFk, v.stamp`);
stmt.merge(conn.makePagination(filter));
return conn.executeStmt(stmt, myOptions); return conn.executeStmt(stmt, myOptions);
}; };

View File

@ -6,12 +6,49 @@ describe('SalesMonitor clientsFilter()', () => {
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
const ctx = {req: {accessToken: {userId: 18}}, args: {}}; const ctx = {req: {accessToken: {userId: 18}}, args: {}};
const filter = {order: 'dated DESC'};
const from = new Date();
const to = new Date();
from.setHours(0, 0, 0, 0);
to.setHours(23, 59, 59, 59);
const filter = {
where: {
'v.stamp': {between: [from, to]}
}
};
const result = await models.SalesMonitor.clientsFilter(ctx, filter, options); const result = await models.SalesMonitor.clientsFilter(ctx, filter, options);
expect(result.length).toEqual(9); expect(result.length).toEqual(3);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should return the clients web activity filtered', async() => {
const tx = await models.SalesMonitor.beginTransaction({});
try {
const options = {transaction: tx};
const ctx = {req: {accessToken: {userId: 18}}, args: {}};
const yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
const today = new Date();
yesterday.setHours(0, 0, 0, 0);
today.setHours(23, 59, 59, 59);
const filter = {
where: {
'v.stamp': {between: [yesterday, today]}
}
};
const result = await models.SalesMonitor.clientsFilter(ctx, filter, options);
expect(result.length).toEqual(5);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {

View File

@ -14,7 +14,7 @@
"properties": { "properties": {
"id": { "id": {
"id": true, "id": true,
"type": "Number", "type": "number",
"description": "Identifier" "description": "Identifier"
}, },
"concept": { "concept": {
@ -22,22 +22,25 @@
"required": true "required": true
}, },
"quantity": { "quantity": {
"type": "Number" "type": "number"
}, },
"price": { "price": {
"type": "Number" "type": "number"
}, },
"discount": { "discount": {
"type": "Number" "type": "number"
}, },
"reserved": { "reserved": {
"type": "boolean" "type": "boolean"
}, },
"isPicked": { "isPicked": {
"type": "Number" "type": "number"
}, },
"created": { "created": {
"type": "date" "type": "date"
},
"originalQuantity":{
"type": "number"
} }
}, },
"relations": { "relations": {

View File

@ -135,7 +135,8 @@ module.exports = Self => {
function formatDate(date) { function formatDate(date) {
let day = date.getDate(); let day = date.getDate();
if (day < 10) day = `0${day}`; if (day < 10) day = `0${day}`;
let month = date.getMonth();
let month = date.getMonth() + 1;
if (month < 10) month = `0${month}`; if (month < 10) month = `0${month}`;
let year = date.getFullYear(); let year = date.getFullYear();

View File

@ -87,7 +87,7 @@ module.exports = Self => {
function formatDate(date) { function formatDate(date) {
let day = date.getDate(); let day = date.getDate();
if (day < 10) day = `0${day}`; if (day < 10) day = `0${day}`;
let month = date.getMonth(); let month = date.getMonth() + 1;
if (month < 10) month = `0${month}`; if (month < 10) month = `0${month}`;
let year = date.getFullYear(); let year = date.getFullYear();