feat(getUrl): se añade el metodo getUrl refs #5979
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Pablo Natek 2023-10-19 08:37:28 +02:00
parent 9870a0e60a
commit 488181e1b6
27 changed files with 34 additions and 30 deletions

View File

@ -26,7 +26,7 @@ module.exports = Self => {
Self.getTickets = async(ctx, id, print, options) => { Self.getTickets = async(ctx, id, print, options) => {
const userId = ctx.req.accessToken.userId; const userId = ctx.req.accessToken.userId;
const url = Self.app.models.Application.getUrl(); const url = Self.app.models.Url.getUrl();
const $t = ctx.req.__; const $t = ctx.req.__;
const myOptions = {}; const myOptions = {};

View File

@ -1,9 +1,10 @@
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('getUrl', { Self.remoteMethod('getUrl', {
description: 'Returns the colling app name', description: 'Returns the colling app name',
accessType: 'READ',
accepts: [ accepts: [
{ {
arg: 'appName', arg: 'app',
type: 'string', type: 'string',
required: false required: false
} }
@ -18,13 +19,14 @@ module.exports = Self => {
} }
}); });
Self.getUrl = async(appName = 'salix') => { Self.getUrl = async(appName = 'salix') => {
console.log('appName: ', appName);
const {url} = await Self.app.models.Url.findOne({ const {url} = await Self.app.models.Url.findOne({
where: { where: {
appName, appName,
enviroment: process.env.NODE_ENV || 'development' enviroment: process.env.NODE_ENV || 'development'
} }
}); });
console.log('url: ', url);
return url; return url;
}; };
}; };

3
back/models/url.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = Self => {
require('../methods/url/getUrl')(Self);
};

View File

@ -89,7 +89,7 @@ module.exports = function(Self) {
}; };
Self.on('resetPasswordRequest', async function(info) { Self.on('resetPasswordRequest', async function(info) {
const url = await Self.app.models.Application.getUrl(); const url = await Self.app.models.Url.getUrl();
const defaultHash = '/reset-password?access_token=$token$'; const defaultHash = '/reset-password?access_token=$token$';
const recoverHashes = { const recoverHashes = {

View File

@ -2,5 +2,4 @@
module.exports = function(Self) { module.exports = function(Self) {
require('../methods/application/status')(Self); require('../methods/application/status')(Self);
require('../methods/application/post')(Self); require('../methods/application/post')(Self);
require('../methods/application/getUrl')(Self);
}; };

View File

@ -44,7 +44,7 @@ module.exports = Self => {
Self.claimPickupEmail = async ctx => { Self.claimPickupEmail = async ctx => {
const models = Self.app.models; const models = Self.app.models;
const $t = ctx.req.__; // $translate const $t = ctx.req.__; // $translate
const url = await Self.app.models.Application.getUrl(); const url = await Self.app.models.Url.getUrl();
const args = Object.assign({}, ctx.args); const args = Object.assign({}, ctx.args);
const params = { const params = {

View File

@ -94,7 +94,7 @@ module.exports = Self => {
const salesPerson = ticket.client().salesPersonUser(); const salesPerson = ticket.client().salesPersonUser();
if (salesPerson) { if (salesPerson) {
const url = await Self.app.models.Application.getUrl(); const url = await Self.app.models.Url.getUrl();
const message = $t('Created claim', { const message = $t('Created claim', {
claimId: newClaim.id, claimId: newClaim.id,

View File

@ -56,7 +56,7 @@ module.exports = Self => {
const salesPerson = sale.ticket().client().salesPersonUser(); const salesPerson = sale.ticket().client().salesPersonUser();
if (salesPerson) { if (salesPerson) {
const nickname = address && address.nickname || destination.description; const nickname = address && address.nickname || destination.description;
const url = await Self.app.models.Application.getUrl(); const url = await Self.app.models.Url.getUrl();
const message = $t('Sent units from ticket', { const message = $t('Sent units from ticket', {
quantity: sale.quantity, quantity: sale.quantity,
concept: sale.concept, concept: sale.concept,

View File

@ -4,7 +4,7 @@ const LoopBackContext = require('loopback-context');
describe('Update Claim', () => { describe('Update Claim', () => {
let url; let url;
beforeAll(async() => { beforeAll(async() => {
url = await app.models.Application.getUrl(); url = await app.models.Url.getUrl();
const activeCtx = { const activeCtx = {
accessToken: {userId: 9}, accessToken: {userId: 9},
http: { http: {

View File

@ -114,7 +114,7 @@ module.exports = Self => {
async function notifyStateChange(ctx, workerId, claim, state) { async function notifyStateChange(ctx, workerId, claim, state) {
const models = Self.app.models; const models = Self.app.models;
const url = await models.Application.getUrl(); const url = await models.Url.getUrl();
const $t = ctx.req.__; // $translate const $t = ctx.req.__; // $translate
const message = $t(`Claim state has changed to ${state}`, { const message = $t(`Claim state has changed to ${state}`, {
@ -128,7 +128,7 @@ module.exports = Self => {
async function notifyPickUp(ctx, workerId, claim) { async function notifyPickUp(ctx, workerId, claim) {
const models = Self.app.models; const models = Self.app.models;
const url = await models.Application.getUrl('lilium'); const url = await models.Url.getUrl('lilium');
const $t = ctx.req.__; // $translate const $t = ctx.req.__; // $translate
const message = $t('Claim will be picked', { const message = $t('Claim will be picked', {

View File

@ -353,7 +353,7 @@ module.exports = Self => {
const httpCtx = {req: loopBackContext.active}; const httpCtx = {req: loopBackContext.active};
const httpRequest = httpCtx.req.http.req; const httpRequest = httpCtx.req.http.req;
const $t = httpRequest.__; const $t = httpRequest.__;
const url = await Self.app.models.Application.getUrl(); const url = await Self.app.models.Url.getUrl();
const salesPersonId = instance.salesPersonFk; const salesPersonId = instance.salesPersonFk;
@ -395,7 +395,7 @@ module.exports = Self => {
const httpCtx = {req: loopBackContext.active}; const httpCtx = {req: loopBackContext.active};
const httpRequest = httpCtx.req.http.req; const httpRequest = httpCtx.req.http.req;
const $t = httpRequest.__; const $t = httpRequest.__;
const url = await Self.app.models.Application.getUrl(); const url = await Self.app.models.Url.getUrl();
const models = Self.app.models; const models = Self.app.models;
let previousWorker = {name: $t('None')}; let previousWorker = {name: $t('None')};

View File

@ -57,7 +57,7 @@ module.exports = function(Self) {
const httpRequest = httpCtx.req.http.req; const httpRequest = httpCtx.req.http.req;
const $t = httpRequest.__; const $t = httpRequest.__;
const url = await Self.app.models.Application.getUrl(); const url = await Self.app.models.Url.getUrl();
const fullPath = `${url}client/${client.id}/credit-insurance/index`; const fullPath = `${url}client/${client.id}/credit-insurance/index`;
const message = $t('MESSAGE_INSURANCE_CHANGE', { const message = $t('MESSAGE_INSURANCE_CHANGE', {
clientId: client.id, clientId: client.id,

View File

@ -59,7 +59,7 @@ module.exports = Self => {
}; };
await Self.invoiceEmail(ctx, ref); await Self.invoiceEmail(ctx, ref);
} catch (err) { } catch (err) {
const url = await Self.app.models.Application.getUrl(); const url = await Self.app.models.Url.getUrl();
const message = ctx.req.__('Mail not sent', { const message = ctx.req.__('Mail not sent', {
clientId: client.id, clientId: client.id,
clientUrl: `${url}claim/${id}/summary` clientUrl: `${url}claim/${id}/summary`

View File

@ -68,7 +68,7 @@ module.exports = Self => {
const salesPerson = ticket.client().salesPersonUser(); const salesPerson = ticket.client().salesPersonUser();
if (salesPerson) { if (salesPerson) {
const url = await Self.app.models.Application.getUrl(); const url = await Self.app.models.Url.getUrl();
const message = $t('Deleted sales from ticket', { const message = $t('Deleted sales from ticket', {
ticketId: ticketId, ticketId: ticketId,

View File

@ -85,7 +85,7 @@ module.exports = Self => {
const salesPerson = ticket.client().salesPersonUser(); const salesPerson = ticket.client().salesPersonUser();
if (salesPerson) { if (salesPerson) {
const url = await Self.app.models.Application.getUrl(); const url = await Self.app.models.Url.getUrl();
const message = $t('Changed sale reserved state', { const message = $t('Changed sale reserved state', {
ticketId: ticketId, ticketId: ticketId,

View File

@ -98,7 +98,7 @@ module.exports = Self => {
const salesPerson = sale.ticket().client().salesPersonUser(); const salesPerson = sale.ticket().client().salesPersonUser();
if (salesPerson) { if (salesPerson) {
const url = await Self.app.models.Application.getUrl(); const url = await Self.app.models.Url.getUrl();
const message = $t('Changed sale price', { const message = $t('Changed sale price', {
ticketId: sale.ticket().id, ticketId: sale.ticket().id,
itemId: sale.itemFk, itemId: sale.itemFk,

View File

@ -80,7 +80,7 @@ module.exports = Self => {
const salesPerson = sale.ticket().client().salesPersonUser(); const salesPerson = sale.ticket().client().salesPersonUser();
if (salesPerson) { if (salesPerson) {
const url = await Self.app.models.Application.getUrl(); const url = await Self.app.models.Url.getUrl();
const message = $t('Changed sale quantity', { const message = $t('Changed sale quantity', {
ticketId: sale.ticket().id, ticketId: sale.ticket().id,
itemId: sale.itemFk, itemId: sale.itemFk,

View File

@ -84,7 +84,7 @@ module.exports = Self => {
const query = `CALL vn.sale_calculateComponent(?, NULL)`; const query = `CALL vn.sale_calculateComponent(?, NULL)`;
await Self.rawSql(query, [sale.id], myOptions); await Self.rawSql(query, [sale.id], myOptions);
const url = await Self.app.models.Application.getUrl(); const url = await Self.app.models.Url.getUrl();
const requesterId = request.requesterFk; const requesterId = request.requesterFk;
const message = $t('Bought units from buy request', { const message = $t('Bought units from buy request', {

View File

@ -50,7 +50,7 @@ module.exports = Self => {
const request = await Self.app.models.TicketRequest.findById(ctx.args.id, null, myOptions); const request = await Self.app.models.TicketRequest.findById(ctx.args.id, null, myOptions);
await request.updateAttributes(params, myOptions); await request.updateAttributes(params, myOptions);
const url = await Self.app.models.Application.getUrl(); const url = await Self.app.models.Url.getUrl();
const requesterId = request.requesterFk; const requesterId = request.requesterFk;
const message = $t('Deny buy request', { const message = $t('Deny buy request', {

View File

@ -94,7 +94,7 @@ module.exports = Self => {
const salesPerson = ticket.client().salesPersonUser(); const salesPerson = ticket.client().salesPersonUser();
if (salesPerson) { if (salesPerson) {
const url = await Self.app.models.Application.getUrl(); const url = await Self.app.models.Url.getUrl();
const message = $t('Added sale to ticket', { const message = $t('Added sale to ticket', {
ticketId: id, ticketId: id,

View File

@ -237,7 +237,7 @@ module.exports = Self => {
const salesPersonId = originalTicket.client().salesPersonFk; const salesPersonId = originalTicket.client().salesPersonFk;
if (salesPersonId) { if (salesPersonId) {
const url = await Self.app.models.Application.getUrl(); const url = await Self.app.models.Url.getUrl();
let changesMade = ''; let changesMade = '';
for (let change in newProperties) { for (let change in newProperties) {

View File

@ -25,7 +25,7 @@ module.exports = Self => {
Self.merge = async(ctx, tickets, options) => { Self.merge = async(ctx, tickets, options) => {
const httpRequest = ctx.req; const httpRequest = ctx.req;
const $t = httpRequest.__; const $t = httpRequest.__;
const url = await Self.app.models.Application.getUrl(); const url = await Self.app.models.Url.getUrl();
const models = Self.app.models; const models = Self.app.models;
const myOptions = {}; const myOptions = {};
let tx; let tx;

View File

@ -48,7 +48,7 @@ module.exports = Self => {
// Send notification to salesPerson // Send notification to salesPerson
const salesPersonId = ticket.client().salesPersonFk; const salesPersonId = ticket.client().salesPersonFk;
if (salesPersonId) { if (salesPersonId) {
const url = await Self.app.models.Application.getUrl(); const url = await Self.app.models.Url.getUrl();
const message = $t(`I have restored the ticket id`, { const message = $t(`I have restored the ticket id`, {
id: id, id: id,
url: `${url}ticket/${id}/summary` url: `${url}ticket/${id}/summary`

View File

@ -119,7 +119,7 @@ module.exports = Self => {
// Send notification to salesPerson // Send notification to salesPerson
const salesPersonUser = ticket.client().salesPersonUser(); const salesPersonUser = ticket.client().salesPersonUser();
if (salesPersonUser && sales.length) { if (salesPersonUser && sales.length) {
const url = await Self.app.models.Application.getUrl(); const url = await Self.app.models.Url.getUrl();
const message = $t(`I have deleted the ticket id`, { const message = $t(`I have deleted the ticket id`, {
id: id, id: id,
url: `${url}ticket/${id}/summary` url: `${url}ticket/${id}/summary`

View File

@ -165,7 +165,7 @@ module.exports = Self => {
const salesPerson = ticket.client().salesPersonUser(); const salesPerson = ticket.client().salesPersonUser();
if (salesPerson) { if (salesPerson) {
const url = await Self.app.models.Application.getUrl(); const url = await Self.app.models.Url.getUrl();
const message = $t('Changed sale discount', { const message = $t('Changed sale discount', {
ticketId: id, ticketId: id,
ticketUrl: `${url}ticket/${id}/sale`, ticketUrl: `${url}ticket/${id}/sale`,

View File

@ -109,7 +109,7 @@ module.exports = Self => {
const absenceType = await models.AbsenceType.findById(args.absenceTypeId, null, myOptions); const absenceType = await models.AbsenceType.findById(args.absenceTypeId, null, myOptions);
const account = await models.VnUser.findById(userId, null, myOptions); const account = await models.VnUser.findById(userId, null, myOptions);
const subordinated = await models.VnUser.findById(id, null, myOptions); const subordinated = await models.VnUser.findById(id, null, myOptions);
const url = await Self.app.models.Application.getUrl(); const url = await Self.app.models.Url.getUrl();
const body = $t('Created absence', { const body = $t('Created absence', {
author: account.nickname, author: account.nickname,
employee: subordinated.nickname, employee: subordinated.nickname,

View File

@ -60,7 +60,7 @@ module.exports = Self => {
const absenceType = await models.AbsenceType.findById(absence.dayOffTypeFk, null, myOptions); const absenceType = await models.AbsenceType.findById(absence.dayOffTypeFk, null, myOptions);
const account = await models.VnUser.findById(userId, null, myOptions); const account = await models.VnUser.findById(userId, null, myOptions);
const subordinated = await models.VnUser.findById(labour.workerFk, null, myOptions); const subordinated = await models.VnUser.findById(labour.workerFk, null, myOptions);
const url = await Self.app.models.Application.getUrl(); const url = await Self.app.models.Url.getUrl();
const body = $t('Deleted absence', { const body = $t('Deleted absence', {
author: account.nickname, author: account.nickname,
employee: subordinated.nickname, employee: subordinated.nickname,