From 30933220aca2d32dfddd1ee4a2129aea66c58f64 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Mon, 24 Oct 2022 09:37:17 +0200 Subject: [PATCH] #4507 greuge.js/json now insert userFk @2h --- modules/client/back/models/greuge.js | 15 +++++++++++++++ modules/client/back/models/greuge.json | 4 ++++ modules/client/front/greuge/index/index.html | 2 ++ modules/client/front/greuge/index/locale/es.yml | 3 ++- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/modules/client/back/models/greuge.js b/modules/client/back/models/greuge.js index bd5f2865d..42820fd60 100644 --- a/modules/client/back/models/greuge.js +++ b/modules/client/back/models/greuge.js @@ -1,6 +1,21 @@ +const LoopBackContext = require('loopback-context'); + module.exports = function(Self) { require('../methods/greuge/sumAmount')(Self); + Self.observe('before save', function(ctx, next) { + const loopBackContext = LoopBackContext.getCurrentContext(); + + let userFk = loopBackContext.active.accessToken.userId; + + if (ctx.instance) + ctx.instance.userFk = userFk; + else + ctx.data.userFk = userFk; + + next(); + }); + Self.validatesLengthOf('description', { max: 45, message: 'Description should have maximum of 45 characters' diff --git a/modules/client/back/models/greuge.json b/modules/client/back/models/greuge.json index 918ff0ca5..e8790715a 100644 --- a/modules/client/back/models/greuge.json +++ b/modules/client/back/models/greuge.json @@ -34,6 +34,10 @@ "greugeTypeFk": { "type": "number", "required": true + }, + "userFk": { + "type": "number", + "required": true } }, diff --git a/modules/client/front/greuge/index/index.html b/modules/client/front/greuge/index/index.html index b48fe9466..cdc9c37d4 100644 --- a/modules/client/front/greuge/index/index.html +++ b/modules/client/front/greuge/index/index.html @@ -29,6 +29,7 @@ Date + Created by Comment Type Amount @@ -37,6 +38,7 @@ {{::greuge.shipped | date:'dd/MM/yyyy HH:mm' }} + {{::greuge.userFk}} {{::greuge.description}} diff --git a/modules/client/front/greuge/index/locale/es.yml b/modules/client/front/greuge/index/locale/es.yml index 513e6ff7b..d1f202862 100644 --- a/modules/client/front/greuge/index/locale/es.yml +++ b/modules/client/front/greuge/index/locale/es.yml @@ -1,4 +1,5 @@ Date: Fecha Comment: Comentario Amount: Importe -Type: Tipo \ No newline at end of file +Type: Tipo +Created by: Creado por \ No newline at end of file