1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 05:09:43 +02:00

Project managers, board members, auto-update after reconnection, refactoring

This commit is contained in:
Maksim Eltyshev 2021-06-24 01:05:22 +05:00
parent 7956503a46
commit fe91b5241e
478 changed files with 21226 additions and 19495 deletions

View file

@ -1,25 +1,25 @@
module.exports = {
async fn(inputs, exits) {
async fn() {
const { currentUser } = this.req;
const notifications = await sails.helpers.getNotificationsForUser(currentUser.id);
const notifications = await sails.helpers.users.getNotifications(currentUser.id);
const actionIds = sails.helpers.mapRecords(notifications, 'actionId');
const actions = await sails.helpers.getActions(actionIds);
const actionIds = sails.helpers.utils.mapRecords(notifications, 'actionId');
const actions = await sails.helpers.actions.getMany(actionIds);
const cardIds = sails.helpers.mapRecords(notifications, 'cardId');
const cards = await sails.helpers.getCards(cardIds);
const userIds = sails.helpers.utils.mapRecords(actions, 'userId', true);
const users = await sails.helpers.users.getMany(userIds, true);
const userIds = sails.helpers.mapRecords(actions, 'userId', true);
const users = await sails.helpers.getUsers(userIds);
const cardIds = sails.helpers.utils.mapRecords(notifications, 'cardId');
const cards = await sails.helpers.cards.getMany(cardIds);
return exits.success({
return {
items: notifications,
included: {
users,
cards,
actions,
},
});
};
},
};

View file

@ -0,0 +1,48 @@
const Errors = {
NOTIFICATION_NOT_FOUND: {
notificationNotFound: 'Notification not found',
},
};
module.exports = {
inputs: {
id: {
type: 'string',
regex: /^[0-9]+$/,
required: true,
},
},
exits: {
notificationNotFound: {
responseType: 'notFound',
},
},
async fn(inputs) {
const { currentUser } = this.req;
const notification = await Notification.findOne({
id: inputs.id,
isRead: false,
userId: currentUser.id,
});
if (!notification) {
throw Errors.NOTIFICATION_NOT_FOUND;
}
const action = await Action.findOne(notification.actionId);
const user = await sails.helpers.users.getOne(action.userId, true);
const card = await Card.findOne(notification.cardId);
return {
item: notification,
included: {
users: [user],
cards: [card],
actions: [action],
},
};
},
};

View file

@ -10,20 +10,20 @@ module.exports = {
},
},
async fn(inputs, exits) {
async fn(inputs) {
const { currentUser } = this.req;
const values = _.pick(inputs, ['isRead']);
const notifications = await sails.helpers.updateNotificationsForUser(
const notifications = await sails.helpers.notifications.updateMany(
inputs.ids.split(','),
currentUser,
values,
currentUser,
this.req,
);
return exits.success({
return {
items: notifications,
});
};
},
};