2905 - Restore ticket shipped and landed
This commit is contained in:
parent
fc00e759c2
commit
e6e91ced99
|
@ -36802,11 +36802,7 @@ BEGIN
|
||||||
`body` = CONCAT(account.myUserGetName(), ' ha modificado el ticket ',
|
`body` = CONCAT(account.myUserGetName(), ' ha modificado el ticket ',
|
||||||
NEW.id);
|
NEW.id);
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
IF !(DATE(NEW.shipped) <=> DATE(OLD.shipped)) AND DATE(NEW.shipped) = CURDATE() THEN
|
|
||||||
INSERT INTO tmp.ticketDate_updated(ticketFk, oldShipped, newShipped, workerFk)
|
|
||||||
VALUES (NEW.id, OLD.shipped, NEW.shipped, vn.getUser());
|
|
||||||
END IF;
|
|
||||||
END */;;
|
END */;;
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
/*!50003 SET sql_mode = @saved_sql_mode */ ;
|
/*!50003 SET sql_mode = @saved_sql_mode */ ;
|
||||||
|
|
|
@ -21,9 +21,15 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.restore = async(ctx, id) => {
|
Self.restore = async(ctx, id, options) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const $t = ctx.req.__; // $translate
|
const $t = ctx.req.__; // $translate
|
||||||
|
|
||||||
|
let myOptions = {};
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
const ticket = await models.Ticket.findById(id, {
|
const ticket = await models.Ticket.findById(id, {
|
||||||
include: [{
|
include: [{
|
||||||
relation: 'client',
|
relation: 'client',
|
||||||
|
@ -31,7 +37,7 @@ module.exports = Self => {
|
||||||
fields: ['id', 'salesPersonFk']
|
fields: ['id', 'salesPersonFk']
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
});
|
}, myOptions);
|
||||||
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const maxDate = new Date(ticket.updated);
|
const maxDate = new Date(ticket.updated);
|
||||||
|
@ -51,6 +57,16 @@ module.exports = Self => {
|
||||||
await models.Chat.sendCheckingPresence(ctx, salesPersonId, message);
|
await models.Chat.sendCheckingPresence(ctx, salesPersonId, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ticket.updateAttribute('isDeleted', false);
|
const fullYear = new Date().getFullYear();
|
||||||
|
const newShipped = ticket.shipped;
|
||||||
|
const newLanded = ticket.landed;
|
||||||
|
newShipped.setFullYear(fullYear);
|
||||||
|
newLanded.setFullYear(fullYear);
|
||||||
|
|
||||||
|
return ticket.updateAttributes({
|
||||||
|
shipped: newShipped,
|
||||||
|
landed: newLanded,
|
||||||
|
isDeleted: false
|
||||||
|
}, myOptions);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,6 +4,7 @@ const models = app.models;
|
||||||
|
|
||||||
describe('ticket restore()', () => {
|
describe('ticket restore()', () => {
|
||||||
const employeeUser = 110;
|
const employeeUser = 110;
|
||||||
|
const ticketId = 18;
|
||||||
const activeCtx = {
|
const activeCtx = {
|
||||||
accessToken: {userId: employeeUser},
|
accessToken: {userId: employeeUser},
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -13,45 +14,30 @@ describe('ticket restore()', () => {
|
||||||
};
|
};
|
||||||
const ctx = {req: activeCtx};
|
const ctx = {req: activeCtx};
|
||||||
|
|
||||||
let createdTicket;
|
beforeEach(() => {
|
||||||
|
|
||||||
beforeEach(async done => {
|
|
||||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
active: activeCtx
|
active: activeCtx
|
||||||
});
|
});
|
||||||
try {
|
|
||||||
const sampleTicket = await models.Ticket.findById(11);
|
|
||||||
sampleTicket.id = undefined;
|
|
||||||
|
|
||||||
createdTicket = await models.Ticket.create(sampleTicket);
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(async done => {
|
|
||||||
try {
|
|
||||||
await models.Ticket.destroyById(createdTicket.id);
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error if the given ticket has past the deletion time', async() => {
|
it('should throw an error if the given ticket has past the deletion time', async() => {
|
||||||
let error;
|
let error;
|
||||||
|
|
||||||
|
const tx = await app.models.Ticket.beginTransaction({});
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
now.setHours(now.getHours() - 1);
|
now.setHours(now.getHours() - 1);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const ticket = await models.Ticket.findById(createdTicket.id);
|
const options = {transaction: tx};
|
||||||
await ticket.updateAttributes({isDeleted: true, updated: now});
|
const ticket = await models.Ticket.findById(ticketId, null, options);
|
||||||
await app.models.Ticket.restore(ctx, createdTicket.id);
|
await ticket.updateAttributes({
|
||||||
|
isDeleted: true,
|
||||||
|
updated: now
|
||||||
|
}, options);
|
||||||
|
await app.models.Ticket.restore(ctx, ticketId, options);
|
||||||
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
error = e;
|
error = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,17 +45,37 @@ describe('ticket restore()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should restore the ticket making its state no longer deleted', async() => {
|
it('should restore the ticket making its state no longer deleted', async() => {
|
||||||
|
const tx = await app.models.Ticket.beginTransaction({});
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const ticketBeforeUpdate = await models.Ticket.findById(createdTicket.id);
|
|
||||||
await ticketBeforeUpdate.updateAttributes({isDeleted: true, updated: now});
|
|
||||||
|
|
||||||
const ticketAfterUpdate = await models.Ticket.findById(createdTicket.id);
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
expect(ticketAfterUpdate.isDeleted).toBeTruthy();
|
const ticketBeforeUpdate = await models.Ticket.findById(ticketId, null, options);
|
||||||
|
await ticketBeforeUpdate.updateAttributes({
|
||||||
|
isDeleted: true,
|
||||||
|
updated: now
|
||||||
|
}, options);
|
||||||
|
|
||||||
await models.Ticket.restore(ctx, createdTicket.id);
|
const ticketAfterUpdate = await models.Ticket.findById(ticketId, null, options);
|
||||||
const ticketAfterRestore = await models.Ticket.findById(createdTicket.id);
|
|
||||||
|
|
||||||
expect(ticketAfterRestore.isDeleted).toBeFalsy();
|
expect(ticketAfterUpdate.isDeleted).toBeTruthy();
|
||||||
|
|
||||||
|
await models.Ticket.restore(ctx, ticketId, options);
|
||||||
|
const ticketAfterRestore = await models.Ticket.findById(ticketId, null, options);
|
||||||
|
|
||||||
|
const fullYear = now.getFullYear();
|
||||||
|
const shippedFullYear = ticketAfterRestore.shipped.getFullYear();
|
||||||
|
const landedFullYear = ticketAfterRestore.landed.getFullYear();
|
||||||
|
|
||||||
|
expect(ticketAfterRestore.isDeleted).toBeFalsy();
|
||||||
|
expect(shippedFullYear).toEqual(fullYear);
|
||||||
|
expect(landedFullYear).toEqual(fullYear);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue