8355-testToMaster #3336

Merged
alexm merged 241 commits from 8355-testToMaster into master 2025-01-07 06:44:57 +00:00
2 changed files with 48 additions and 23 deletions
Showing only changes of commit 391f1d8c97 - Show all commits

View File

@ -54,9 +54,17 @@ module.exports = Self => {
throw new UserError(`That item doesn't exists`); throw new UserError(`That item doesn't exists`);
const request = await models.TicketRequest.findById(ctx.args.id, { const request = await models.TicketRequest.findById(ctx.args.id, {
include: {relation: 'ticket'} include: {
relation: 'ticket',
scope: {
include: {
relation: 'client',
scope: {
fields: ['id', 'name', 'salesPersonFk']
}
}
}}
}, myOptions); }, myOptions);
const itemStock = await models.Item.getVisibleAvailable( const itemStock = await models.Item.getVisibleAvailable(
ctx.args.itemFk, ctx.args.itemFk,
request.ticket().warehouseFk, request.ticket().warehouseFk,
@ -90,8 +98,7 @@ module.exports = Self => {
await Self.rawSql(query, [sale.id], myOptions); await Self.rawSql(query, [sale.id], myOptions);
const url = await Self.app.models.Url.getUrl(); const url = await Self.app.models.Url.getUrl();
const requesterId = request.requesterFk; const requesterId = request.ticket().client().salesPersonFk;
const message = $t('Bought units from buy request', { const message = $t('Bought units from buy request', {
quantity: sale.quantity, quantity: sale.quantity,
concept: sale.concept, concept: sale.concept,

View File

@ -1,18 +1,21 @@
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('deny', { Self.remoteMethodCtx('deny', {
description: 'sets a ticket request to denied and returns the changes', description: 'Sets a ticket request to denied and returns the changes',
accessType: 'WRITE', accessType: 'WRITE',
accepts: [{ accepts: [
arg: 'id', {
type: 'number', arg: 'id',
required: true, type: 'number',
description: 'The request ID', required: true,
}, { description: 'The request ID',
arg: 'observation', },
type: 'String', {
required: true, arg: 'observation',
description: 'The request observation', type: 'string',
}], required: true,
description: 'The request observation',
}
],
returns: { returns: {
type: 'number', type: 'number',
root: true root: true
@ -29,7 +32,7 @@ module.exports = Self => {
const myOptions = {}; const myOptions = {};
let tx; let tx;
if (typeof options == 'object') if (typeof options === 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
if (!myOptions.transaction) { if (!myOptions.transaction) {
@ -39,7 +42,8 @@ module.exports = Self => {
try { try {
const userId = ctx.req.accessToken.userId; const userId = ctx.req.accessToken.userId;
const worker = await Self.app.models.Worker.findOne({where: {id: userId}}, myOptions); const worker = await models.Worker.findOne({where: {id: userId}}, myOptions);
if (!worker) throw new Error('Worker not found');
const params = { const params = {
isOk: false, isOk: false,
@ -47,19 +51,33 @@ module.exports = Self => {
response: ctx.args.observation, response: ctx.args.observation,
}; };
const request = await Self.app.models.TicketRequest.findById(ctx.args.id, null, myOptions); const request = await models.TicketRequest.findById(ctx.args.id, {
await request.updateAttributes(params, myOptions); include: {
relation: 'ticket',
scope: {
include: {
relation: 'client',
scope: {
fields: ['id', 'name', 'salesPersonFk']
}
}
}
}
}, myOptions);
const url = await Self.app.models.Url.getUrl(); if (!request || !request.ticket() || !request.ticket().client())
const requesterId = request.requesterFk; throw new Error('Invalid request or related ticket/client data');
const url = await models.Url.getUrl();
const requesterId = request.ticket().client().salesPersonFk;
const message = $t('Deny buy request', { const message = $t('Deny buy request', {
ticketId: request.ticketFk, ticketId: request.ticketFk,
url: `${url}ticket/${request.ticketFk}/request/index`, url: `${url}ticket/${request.ticketFk}/request/index`,
observation: params.response observation: params.response
}); });
await models.Chat.sendCheckingPresence(ctx, requesterId, message, myOptions); await models.Chat.sendCheckingPresence(ctx, requesterId, message);
await request.updateAttributes(params, myOptions);
if (tx) await tx.commit(); if (tx) await tx.commit();