This commit is contained in:
parent
5b541aa804
commit
adeca2bb22
|
@ -1,25 +1,25 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('myLastModified', {
|
Self.remoteMethodCtx('myLastModified', {
|
||||||
description: 'Get list of last tickets which user has modified',
|
description: 'Get list of last tickets which user has modified',
|
||||||
accessType: 'READ',
|
accessType: 'READ',
|
||||||
returns: {
|
returns: {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
root: true
|
root: true
|
||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
path: `/getLastTicketsByWorker`,
|
path: `/myLastModified`,
|
||||||
verb: 'GET'
|
verb: 'GET'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.getLastTicketsByWorker = async ctx => {
|
Self.myLastModified = async ctx => {
|
||||||
const userId = ctx.req.accessToken.userId;
|
const userId = ctx.req.accessToken.userId;
|
||||||
const query =
|
const query =
|
||||||
`SELECT ticketFk, MAX(created) created
|
`SELECT ticketFk, MAX(created) created
|
||||||
FROM ticketTracking tt
|
FROM ticketTracking tt
|
||||||
WHERE tt.userFk = ?
|
WHERE tt.userFk = ?
|
||||||
GROUP BY ticketFk
|
GROUP BY ticketFk
|
||||||
LIMIT 5;`;
|
LIMIT 5;`;
|
||||||
return await Self.rawSql(query, [userId]);
|
return await Self.rawSql(query, [userId]);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
const {models} = require('vn-loopback/server/server');
|
const {models} = require('vn-loopback/server/server');
|
||||||
|
|
||||||
describe('getLastTicketsByWorker()', () => {
|
describe('myLastModified()', () => {
|
||||||
it('return list of last tickets which user has modified', async() => {
|
it('return list of last tickets which user has modified', async() => {
|
||||||
let ctx = {req: {accessToken: {userId: 100}}};
|
let ctx = {req: {accessToken: {userId: 100}}};
|
||||||
let response = await models.Ticket.getLastTicketsByWorker(ctx);
|
let response = await models.Ticket.myLastModified(ctx);
|
||||||
|
|
||||||
expect(response.length).toBeGreaterThan(0);
|
expect(response.length).toBeGreaterThan(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue