refactor(createFromSales): now claimManager can claim any time
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
2a2c54e06a
commit
d86aa5535c
|
@ -59,11 +59,12 @@ module.exports = Self => {
|
||||||
|
|
||||||
const landedPlusWeek = new Date(ticket.landed);
|
const landedPlusWeek = new Date(ticket.landed);
|
||||||
landedPlusWeek.setDate(landedPlusWeek.getDate() + 7);
|
landedPlusWeek.setDate(landedPlusWeek.getDate() + 7);
|
||||||
|
const hasClaimManagerRole = await models.Account.hasRole(userId, 'claimManager', myOptions);
|
||||||
const isClaimable = landedPlusWeek >= new Date();
|
const isClaimable = landedPlusWeek >= new Date();
|
||||||
|
|
||||||
if (ticket.isDeleted)
|
if (ticket.isDeleted)
|
||||||
throw new UserError(`You can't create a claim for a removed ticket`);
|
throw new UserError(`You can't create a claim for a removed ticket`);
|
||||||
if (!isClaimable)
|
if (!isClaimable && !hasClaimManagerRole)
|
||||||
throw new UserError(`You can't create a claim from a ticket delivered more than seven days ago`);
|
throw new UserError(`You can't create a claim from a ticket delivered more than seven days ago`);
|
||||||
|
|
||||||
const newClaim = await Self.create({
|
const newClaim = await Self.create({
|
||||||
|
|
|
@ -46,9 +46,40 @@ describe('Claim createFromSales()', () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should be able to create a claim for a ticket delivered more than seven days ago as claimManager', async() => {
|
||||||
|
const tx = await models.Claim.beginTransaction({});
|
||||||
|
const claimManagerId = 72;
|
||||||
|
activeCtx.accessToken.userId = claimManagerId;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const todayMinusEightDays = new Date();
|
||||||
|
todayMinusEightDays.setDate(todayMinusEightDays.getDate() - 8);
|
||||||
|
|
||||||
|
const ticket = await models.Ticket.findById(ticketId, options);
|
||||||
|
await ticket.updateAttribute('landed', todayMinusEightDays, options);
|
||||||
|
|
||||||
|
const claim = await models.Claim.createFromSales(ctx, ticketId, newSale, options);
|
||||||
|
|
||||||
|
expect(claim.ticketFk).toEqual(ticketId);
|
||||||
|
|
||||||
|
const claimBeginning = await models.ClaimBeginning.findOne({where: {claimFk: claim.id}}, options);
|
||||||
|
|
||||||
|
expect(claimBeginning.saleFk).toEqual(newSale[0].id);
|
||||||
|
expect(claimBeginning.quantity).toEqual(newSale[0].quantity);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it('should not be able to create a claim for a ticket delivered more than seven days ago', async() => {
|
it('should not be able to create a claim for a ticket delivered more than seven days ago', async() => {
|
||||||
const tx = await models.Claim.beginTransaction({});
|
const tx = await models.Claim.beginTransaction({});
|
||||||
|
|
||||||
|
activeCtx.accessToken.userId = 1;
|
||||||
let error;
|
let error;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -40,7 +40,9 @@ class Controller extends Section {
|
||||||
const landedPlusWeek = new Date(this.ticket.landed);
|
const landedPlusWeek = new Date(this.ticket.landed);
|
||||||
landedPlusWeek.setDate(landedPlusWeek.getDate() + 7);
|
landedPlusWeek.setDate(landedPlusWeek.getDate() + 7);
|
||||||
|
|
||||||
return landedPlusWeek >= new Date();
|
const hasClaimManagerRole = this.aclService.hasAny(['claimManager']);
|
||||||
|
|
||||||
|
return landedPlusWeek >= new Date() || hasClaimManagerRole;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue