diff --git a/db/versions/10890-redOrchid/00-firstScript.sql b/db/versions/10890-redOrchid/00-firstScript.sql new file mode 100644 index 000000000..17bf974a1 --- /dev/null +++ b/db/versions/10890-redOrchid/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) +VALUES( 'Ticket', 'myLastModified', '*', 'ALLOW', 'ROLE', 'production'); \ No newline at end of file diff --git a/modules/ticket/back/methods/ticket/myLastModified.js b/modules/ticket/back/methods/ticket/myLastModified.js new file mode 100644 index 000000000..a47ea570f --- /dev/null +++ b/modules/ticket/back/methods/ticket/myLastModified.js @@ -0,0 +1,25 @@ +module.exports = Self => { + Self.remoteMethodCtx('myLastModified', { + description: 'Get list of last tickets which user has modified', + accessType: 'READ', + returns: { + type: 'object', + root: true + }, + http: { + path: `/myLastModified`, + verb: 'GET' + } + }); + + Self.myLastModified = async ctx => { + const userId = ctx.req.accessToken.userId; + const query = + `SELECT ticketFk, MAX(created) created + FROM ticketTracking tt + WHERE tt.userFk = ? + GROUP BY ticketFk + LIMIT 5;`; + return await Self.rawSql(query, [userId]); + }; +}; diff --git a/modules/ticket/back/methods/ticket/specs/myLastModified.spec.js b/modules/ticket/back/methods/ticket/specs/myLastModified.spec.js new file mode 100644 index 000000000..6f245a032 --- /dev/null +++ b/modules/ticket/back/methods/ticket/specs/myLastModified.spec.js @@ -0,0 +1,10 @@ +const {models} = require('vn-loopback/server/server'); + +describe('myLastModified()', () => { + it('return list of last tickets which user has modified', async() => { + let ctx = {req: {accessToken: {userId: 100}}}; + let response = await models.Ticket.myLastModified(ctx); + + expect(response.length).toBeGreaterThan(0); + }); +}); diff --git a/modules/ticket/back/models/ticket-methods.js b/modules/ticket/back/models/ticket-methods.js index 8914e9c4f..d204a8102 100644 --- a/modules/ticket/back/models/ticket-methods.js +++ b/modules/ticket/back/models/ticket-methods.js @@ -45,4 +45,5 @@ module.exports = function(Self) { require('../methods/ticket/invoiceTickets')(Self); require('../methods/ticket/invoiceTicketsAndPdf')(Self); require('../methods/ticket/docuwareDownload')(Self); + require('../methods/ticket/myLastModified')(Self); };