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) => {
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 myOptions = {};

View File

@ -1,9 +1,10 @@
module.exports = Self => {
Self.remoteMethodCtx('getUrl', {
Self.remoteMethod('getUrl', {
description: 'Returns the colling app name',
accessType: 'READ',
accepts: [
{
arg: 'appName',
arg: 'app',
type: 'string',
required: false
}
@ -18,13 +19,14 @@ module.exports = Self => {
}
});
Self.getUrl = async(appName = 'salix') => {
console.log('appName: ', appName);
const {url} = await Self.app.models.Url.findOne({
where: {
appName,
enviroment: process.env.NODE_ENV || 'development'
}
});
console.log('url: ', 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) {
const url = await Self.app.models.Application.getUrl();
const url = await Self.app.models.Url.getUrl();
const defaultHash = '/reset-password?access_token=$token$';
const recoverHashes = {

View File

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

View File

@ -44,7 +44,7 @@ module.exports = Self => {
Self.claimPickupEmail = async ctx => {
const models = Self.app.models;
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 params = {

View File

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

View File

@ -56,7 +56,7 @@ module.exports = Self => {
const salesPerson = sale.ticket().client().salesPersonUser();
if (salesPerson) {
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', {
quantity: sale.quantity,
concept: sale.concept,

View File

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

View File

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

View File

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

View File

@ -57,7 +57,7 @@ module.exports = function(Self) {
const httpRequest = httpCtx.req.http.req;
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 message = $t('MESSAGE_INSURANCE_CHANGE', {
clientId: client.id,

View File

@ -59,7 +59,7 @@ module.exports = Self => {
};
await Self.invoiceEmail(ctx, ref);
} 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', {
clientId: client.id,
clientUrl: `${url}claim/${id}/summary`

View File

@ -68,7 +68,7 @@ module.exports = Self => {
const salesPerson = ticket.client().salesPersonUser();
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', {
ticketId: ticketId,

View File

@ -85,7 +85,7 @@ module.exports = Self => {
const salesPerson = ticket.client().salesPersonUser();
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', {
ticketId: ticketId,

View File

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

View File

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

View File

@ -84,7 +84,7 @@ module.exports = Self => {
const query = `CALL vn.sale_calculateComponent(?, NULL)`;
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 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);
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 message = $t('Deny buy request', {

View File

@ -94,7 +94,7 @@ module.exports = Self => {
const salesPerson = ticket.client().salesPersonUser();
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', {
ticketId: id,

View File

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

View File

@ -25,7 +25,7 @@ module.exports = Self => {
Self.merge = async(ctx, tickets, options) => {
const httpRequest = ctx.req;
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 myOptions = {};
let tx;

View File

@ -48,7 +48,7 @@ module.exports = Self => {
// Send notification to salesPerson
const salesPersonId = ticket.client().salesPersonFk;
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`, {
id: id,
url: `${url}ticket/${id}/summary`

View File

@ -119,7 +119,7 @@ module.exports = Self => {
// Send notification to salesPerson
const salesPersonUser = ticket.client().salesPersonUser();
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`, {
id: id,
url: `${url}ticket/${id}/summary`

View File

@ -165,7 +165,7 @@ module.exports = Self => {
const salesPerson = ticket.client().salesPersonUser();
if (salesPerson) {
const url = await Self.app.models.Application.getUrl();
const url = await Self.app.models.Url.getUrl();
const message = $t('Changed sale discount', {
ticketId: id,
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 account = await models.VnUser.findById(userId, 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', {
author: account.nickname,
employee: subordinated.nickname,

View File

@ -60,7 +60,7 @@ module.exports = Self => {
const absenceType = await models.AbsenceType.findById(absence.dayOffTypeFk, null, myOptions);
const account = await models.VnUser.findById(userId, 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', {
author: account.nickname,
employee: subordinated.nickname,