refs #6067 feat(url): getByUser
This commit is contained in:
parent
6871ce4b15
commit
b3c7511e59
|
@ -0,0 +1,40 @@
|
||||||
|
module.exports = function(Self) {
|
||||||
|
Self.remoteMethod('getByUser', {
|
||||||
|
description: 'returns the starred modules for the current user',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [{
|
||||||
|
arg: 'userId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The user id',
|
||||||
|
required: true,
|
||||||
|
http: {source: 'path'}
|
||||||
|
}],
|
||||||
|
returns: {
|
||||||
|
type: 'object',
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/:userId/get-by-user`,
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.getByUser = async userId => {
|
||||||
|
const models = Self.app.models;
|
||||||
|
const appNames = ['hedera'];
|
||||||
|
const filter = {
|
||||||
|
fields: ['appName', 'url'],
|
||||||
|
where: {
|
||||||
|
appName: {inq: appNames},
|
||||||
|
environment: process.env.NODE_ENV ?? 'development',
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const isWorker = await models.Account.findById(userId, {fields: ['id']});
|
||||||
|
if (!isWorker)
|
||||||
|
return models.Url.find(filter);
|
||||||
|
|
||||||
|
appNames.push('salix');
|
||||||
|
return models.Url.find(filter);
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,19 @@
|
||||||
|
const {models} = require('vn-loopback/server/server');
|
||||||
|
|
||||||
|
describe('getByUser()', () => {
|
||||||
|
const worker = 1;
|
||||||
|
const notWorker = 2;
|
||||||
|
it(`should return only hedera url if not is worker`, async() => {
|
||||||
|
const urls = await models.Url.getByUser(notWorker);
|
||||||
|
|
||||||
|
expect(urls.length).toEqual(1);
|
||||||
|
expect(urls[0].appName).toEqual('hedera');
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should return more than hedera url`, async() => {
|
||||||
|
const urls = await models.Url.getByUser(worker);
|
||||||
|
|
||||||
|
expect(urls.length).toBeGreaterThan(1);
|
||||||
|
expect(urls.find(url => url.appName == 'salix').appName).toEqual('salix');
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,3 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
require('../methods/url/getByUser')(Self);
|
||||||
|
};
|
|
@ -21,12 +21,5 @@
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"required": true
|
"required": true
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
"acls": [{
|
|
||||||
"accessType": "READ",
|
|
||||||
"principalType": "ROLE",
|
|
||||||
"principalId": "$everyone",
|
|
||||||
"permission": "ALLOW"
|
|
||||||
}]
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,7 +222,6 @@ module.exports = function(Self) {
|
||||||
]}
|
]}
|
||||||
});
|
});
|
||||||
|
|
||||||
const isWorker = instance.isWorker || await Self.app.models.Account.findById(instance.id, null, ctx.options);
|
|
||||||
class Mailer {
|
class Mailer {
|
||||||
async send(verifyOptions, cb) {
|
async send(verifyOptions, cb) {
|
||||||
const params = {
|
const params = {
|
||||||
|
@ -236,11 +235,12 @@ module.exports = function(Self) {
|
||||||
cb(null, verifyOptions.to);
|
cb(null, verifyOptions.to);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.log('instance.id', instance.id);
|
||||||
const options = {
|
const options = {
|
||||||
type: 'email',
|
type: 'email',
|
||||||
to: newEmail,
|
to: newEmail,
|
||||||
from: {},
|
from: {},
|
||||||
redirect: `${liliumUrl.url}verifyEmail?isWorker=${!!isWorker}`,
|
redirect: `${liliumUrl.url}verifyEmail?userId=${instance.id}`,
|
||||||
template: false,
|
template: false,
|
||||||
mailer: new Mailer,
|
mailer: new Mailer,
|
||||||
host: url[1].split('/')[2],
|
host: url[1].split('/')[2],
|
||||||
|
|
|
@ -3,7 +3,5 @@ INSERT INTO `salix`.`url` (`appName`, `environment`, `url`)
|
||||||
('hedera', 'test', 'https://test-shop.verdnatura.es/'),
|
('hedera', 'test', 'https://test-shop.verdnatura.es/'),
|
||||||
('hedera', 'production', 'https://shop.verdnatura.es/');
|
('hedera', 'production', 'https://shop.verdnatura.es/');
|
||||||
|
|
||||||
DELETE FROM `salix`.`ACL`
|
INSERT INTO `salix`.`ACL` ( model, property, accessType, permission, principalType, principalId)
|
||||||
WHERE model = 'Url'
|
VALUES('Url', 'getByUser', 'READ', 'ALLOW', 'ROLE', '$everyone');
|
||||||
AND 'accessType' = 'READ'
|
|
||||||
AND principalId = 'employee';
|
|
||||||
|
|
|
@ -155,7 +155,6 @@ module.exports = Self => {
|
||||||
password: randomPassword.password,
|
password: randomPassword.password,
|
||||||
email: args.email,
|
email: args.email,
|
||||||
roleFk: workerConfig.roleFk,
|
roleFk: workerConfig.roleFk,
|
||||||
isWorker: true // to verifyEmail
|
|
||||||
},
|
},
|
||||||
myOptions
|
myOptions
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue