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`);
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);
const itemStock = await models.Item.getVisibleAvailable(
ctx.args.itemFk,
request.ticket().warehouseFk,
@ -90,8 +98,7 @@ module.exports = Self => {
await Self.rawSql(query, [sale.id], myOptions);
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', {
quantity: sale.quantity,
concept: sale.concept,

View File

@ -1,18 +1,21 @@
module.exports = Self => {
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',
accepts: [{
arg: 'id',
type: 'number',
required: true,
description: 'The request ID',
}, {
arg: 'observation',
type: 'String',
required: true,
description: 'The request observation',
}],
accepts: [
{
arg: 'id',
type: 'number',
required: true,
description: 'The request ID',
},
{
arg: 'observation',
type: 'string',
required: true,
description: 'The request observation',
}
],
returns: {
type: 'number',
root: true
@ -29,7 +32,7 @@ module.exports = Self => {
const myOptions = {};
let tx;
if (typeof options == 'object')
if (typeof options === 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
@ -39,7 +42,8 @@ module.exports = Self => {
try {
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 = {
isOk: false,
@ -47,19 +51,33 @@ module.exports = Self => {
response: ctx.args.observation,
};
const request = await Self.app.models.TicketRequest.findById(ctx.args.id, null, myOptions);
await request.updateAttributes(params, myOptions);
const request = await models.TicketRequest.findById(ctx.args.id, {
include: {
relation: 'ticket',
scope: {
include: {
relation: 'client',
scope: {
fields: ['id', 'name', 'salesPersonFk']
}
}
}
}
}, myOptions);
const url = await Self.app.models.Url.getUrl();
const requesterId = request.requesterFk;
if (!request || !request.ticket() || !request.ticket().client())
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', {
ticketId: request.ticketFk,
url: `${url}ticket/${request.ticketFk}/request/index`,
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();