fixes #4797 Seccion Worker/Notification #51

Merged
alexandre merged 23 commits from 4797-worker-notification-selector into dev 2023-05-15 09:42:17 +00:00
2 changed files with 18 additions and 160 deletions
Showing only changes of commit fd456ec559 - Show all commits

View File

@ -26,84 +26,10 @@ const notifications = ref([]);
async function fetch() {
try {
await axios
.get(`NotificationSubscriptions`, {
params: {
filter: {
include: [
{
relation: 'notification',
},
],
where: {
userFk: entityId.value,
},
},
},
})
.get(`NotificationSubscriptions/${entityId.value}/getList`)
.then(async (res) => {
if (res.data) {
res.data.forEach((subscription) => {
notifications.value.push({
id: subscription.id,
notificationFk: subscription.notificationFk,
name: subscription.notification.name,
description: subscription.notification.description,
active: true,
});
});
}
});
await axios
.get(`RoleMappings`, {
params: {
filter: {
fields: ['roleId'],
where: {
principalId: entityId.value,
},
},
},
})
.then(async (res) => {
if (res.data) {
await axios
.get(`NotificationAcls`, {
params: {
filter: {
include: [
{
relation: 'notification',
},
],
where: {
roleFk: {
inq: res.data.map((role) => {
return role.roleId;
}),
},
},
},
},
})
.then(async (res) => {
if (res.data) {
res.data.forEach((acl) => {
const activeNotif = notifications.value.find(
(notif) =>
notif.notificationFk === acl.notificationFk
);
if (!activeNotif) {
notifications.value.push({
id: null,
notificationFk: acl.notificationFk,
name: acl.notification.name,
description: acl.notification.description,
active: false,
});
}
});
}
});
notifications.value = res.data;
}
});
} catch (e) {
alexandre marked this conversation as resolved
Review

Aço es necesari? en la funcio de baix no ha fet falta?

Aço es necesari? en la funcio de baix no ha fet falta?
Review

Per algun motiu en vitest si les cridades que fa axios no estan manejades te llança un error Unhandled Rejection. En esta funció ho he posat en un try/catch perque no havia de fer res, en les altres funcions sí que està manejat gastant el .catch() de axios.

Per algun motiu en vitest si les cridades que fa axios no estan manejades te llança un error *Unhandled Rejection*. En esta funció ho he posat en un try/catch perque no havia de fer res, en les altres funcions sí que està manejat gastant el .catch() de axios.
@ -112,14 +38,19 @@ async function fetch() {
}
async function disableNotification(notification) {
await axios.delete(`NotificationSubscriptions/${notification.id}`).then(() => {
notification.id = null;
notification.active = false;
quasar.notify({
type: 'positive',
message: t('worker.notificationsManager.unsubscribed'),
await axios
.delete(`NotificationSubscriptions/${notification.id}`)
.catch(() => (notification.active = true))
.then((res) => {
if (res.data) {
notification.id = null;
notification.active = false;
quasar.notify({
type: 'positive',
message: t('worker.notificationsManager.unsubscribed'),
});
}
});
});
}
async function toggleNotification(notification) {

View File

@ -5,7 +5,6 @@ import WorkerNotificationsManager from 'src/pages/Worker/Card/WorkerNotification
describe('WorkerNotificationsManager', () => {
let vm;
const entityId = 1110;
const roleFk = 1;
beforeAll(() => {
vm = createWrapper(WorkerNotificationsManager, {
@ -26,81 +25,16 @@ describe('WorkerNotificationsManager', () => {
data: [
{
id: 1,
notification: {
name: 'Name 1',
description: 'Description 1',
},
name: 'Name 1',
description: 'Description 1',
notificationFk: 1,
},
],
})
.mockResolvedValueOnce({
data: [
{
roleId: roleFk,
},
],
})
.mockResolvedValueOnce({
data: [
{
notification: {
name: 'Name 1',
description: 'Description 1',
},
notificationFk: 1,
},
{
notification: {
name: 'Name 2',
description: 'Description 2',
},
notificationFk: 2,
active: true
},
],
});
await vm.fetch();
expect(axios.get).toHaveBeenCalledWith(`NotificationSubscriptions`, {
params: {
filter: {
include: [
{
relation: 'notification',
},
],
where: {
userFk: entityId,
},
},
},
});
expect(axios.get).toHaveBeenCalledWith(`RoleMappings`, {
params: {
filter: {
fields: ['roleId'],
where: {
principalId: entityId,
},
},
},
});
expect(axios.get).toHaveBeenCalledWith(`NotificationAcls`, {
params: {
filter: {
include: [
{
relation: 'notification',
},
],
where: {
roleFk: {
inq: [roleFk],
},
},
},
},
});
expect(axios.get).toHaveBeenCalledWith(`NotificationSubscriptions/${entityId}/getList`);
expect(vm.notifications).toEqual([
{
id: 1,
@ -109,13 +43,6 @@ describe('WorkerNotificationsManager', () => {
description: 'Description 1',
active: true,
},
{
id: null,
notificationFk: 2,
name: 'Name 2',
description: 'Description 2',
active: false,
},
]);
});
});