Return data on client (sync) and Promise on server (async) naturally, without wrapping in an extra Promise

This commit is contained in:
Harry Adel 2026-02-18 18:24:55 +02:00
parent 2b15a8ff09
commit f934aea2a5
21 changed files with 405 additions and 3760 deletions

View file

@ -20,7 +20,7 @@ Meteor.methods({
throw new Meteor.Error('not-authorized', 'You must be logged in.');
}
const swimlane = Swimlanes.findOne(swimlaneId);
const swimlane = await Swimlanes.findOneAsync(swimlaneId);
if (!swimlane) {
throw new Meteor.Error('swimlane-not-found', 'Swimlane not found');
}
@ -43,7 +43,7 @@ Meteor.methods({
throw new Meteor.Error('not-authorized', 'You must be logged in.');
}
const list = Lists.findOne(listId);
const list = await Lists.findOneAsync(listId);
if (!list) {
throw new Meteor.Error('list-not-found', 'List not found');
}
@ -66,7 +66,7 @@ Meteor.methods({
throw new Meteor.Error('not-authorized', 'You must be logged in.');
}
const card = Cards.findOne(cardId);
const card = await Cards.findOneAsync(cardId);
if (!card) {
throw new Meteor.Error('card-not-found', 'Card not found');
}
@ -89,7 +89,7 @@ Meteor.methods({
throw new Meteor.Error('not-authorized', 'You must be logged in.');
}
const swimlane = Swimlanes.findOne(swimlaneId);
const swimlane = await Swimlanes.findOneAsync(swimlaneId);
if (!swimlane) {
throw new Meteor.Error('swimlane-not-found', 'Swimlane not found');
}
@ -112,7 +112,7 @@ Meteor.methods({
throw new Meteor.Error('not-authorized', 'You must be logged in.');
}
const list = Lists.findOne(listId);
const list = await Lists.findOneAsync(listId);
if (!list) {
throw new Meteor.Error('list-not-found', 'List not found');
}
@ -135,7 +135,7 @@ Meteor.methods({
throw new Meteor.Error('not-authorized', 'You must be logged in.');
}
const card = Cards.findOne(cardId);
const card = await Cards.findOneAsync(cardId);
if (!card) {
throw new Meteor.Error('card-not-found', 'Card not found');
}
@ -158,7 +158,7 @@ Meteor.methods({
throw new Meteor.Error('not-authorized', 'You must be logged in.');
}
const swimlane = Swimlanes.findOne(swimlaneId);
const swimlane = await Swimlanes.findOneAsync(swimlaneId);
if (!swimlane) {
throw new Meteor.Error('swimlane-not-found', 'Swimlane not found');
}
@ -181,7 +181,7 @@ Meteor.methods({
throw new Meteor.Error('not-authorized', 'You must be logged in.');
}
const list = Lists.findOne(listId);
const list = await Lists.findOneAsync(listId);
if (!list) {
throw new Meteor.Error('list-not-found', 'List not found');
}
@ -204,7 +204,7 @@ Meteor.methods({
throw new Meteor.Error('not-authorized', 'You must be logged in.');
}
const card = Cards.findOne(cardId);
const card = await Cards.findOneAsync(cardId);
if (!card) {
throw new Meteor.Error('card-not-found', 'Card not found');
}
@ -227,7 +227,7 @@ Meteor.methods({
throw new Meteor.Error('not-authorized', 'You must be logged in.');
}
const swimlane = Swimlanes.findOne(swimlaneId);
const swimlane = await Swimlanes.findOneAsync(swimlaneId);
if (!swimlane) {
throw new Meteor.Error('swimlane-not-found', 'Swimlane not found');
}
@ -250,7 +250,7 @@ Meteor.methods({
throw new Meteor.Error('not-authorized', 'You must be logged in.');
}
const list = Lists.findOne(listId);
const list = await Lists.findOneAsync(listId);
if (!list) {
throw new Meteor.Error('list-not-found', 'List not found');
}
@ -273,7 +273,7 @@ Meteor.methods({
throw new Meteor.Error('not-authorized', 'You must be logged in.');
}
const card = Cards.findOne(cardId);
const card = await Cards.findOneAsync(cardId);
if (!card) {
throw new Meteor.Error('card-not-found', 'Card not found');
}
@ -305,7 +305,7 @@ Meteor.methods({
boardId: boardId,
}, {
sort: { createdAt: -1 }
}).fetch();
}).fetchAsync();
},
/**
@ -333,6 +333,6 @@ Meteor.methods({
entityType: entityType,
}, {
sort: { createdAt: -1 }
}).fetch();
}).fetchAsync();
},
});

View file

@ -22,7 +22,7 @@ publishComposite('boards', function() {
return await ReactiveCache.getBoards(
{
archived: false,
_id: { $in: Boards.userBoardIds(userId, false) },
_id: { $in: await Boards.userBoardIds(userId, false) },
},
{
sort: { sort: 1 /* boards default sorting */ },
@ -82,7 +82,7 @@ Meteor.publish('boardsReport', async function() {
const boards = await ReactiveCache.getBoards(
{
_id: { $in: Boards.userBoardIds(userId, null) },
_id: { $in: await Boards.userBoardIds(userId, null) },
},
{
fields: {
@ -142,7 +142,7 @@ Meteor.publish('archivedBoards', async function() {
const ret = await ReactiveCache.getBoards(
{
_id: { $in: Boards.userBoardIds(userId, true)},
_id: { $in: await Boards.userBoardIds(userId, true)},
archived: true,
members: {
$elemMatch: {

View file

@ -387,13 +387,13 @@ async function buildSelector(queryParams) {
if (archived !== null) {
if (archived) {
selector.boardId = {
$in: Boards.userBoardIds(userId, null, boardsSelector),
$in: await Boards.userBoardIds(userId, null, boardsSelector),
};
selector.$and.push({
$or: [
{
boardId: {
$in: Boards.userBoardIds(userId, archived, boardsSelector),
$in: await Boards.userBoardIds(userId, archived, boardsSelector),
},
},
{ swimlaneId: { $in: Swimlanes.userArchivedSwimlaneIds(userId) } },
@ -403,14 +403,14 @@ async function buildSelector(queryParams) {
});
} else {
selector.boardId = {
$in: Boards.userBoardIds(userId, false, boardsSelector),
$in: await Boards.userBoardIds(userId, false, boardsSelector),
};
selector.swimlaneId = { $nin: Swimlanes.archivedSwimlaneIds() };
selector.listId = { $nin: Lists.archivedListIds() };
selector.archived = false;
}
} else {
const userBoardIds = Boards.userBoardIds(userId, null, boardsSelector);
const userBoardIds = await Boards.userBoardIds(userId, null, boardsSelector);
if (process.env.DEBUG === 'true') {
console.log('buildSelector - userBoardIds:', userBoardIds);
}
@ -424,8 +424,8 @@ async function buildSelector(queryParams) {
if (queryParams.hasOperator(OPERATOR_BOARD)) {
const queryBoards = [];
queryParams.getPredicates(OPERATOR_BOARD).forEach(query => {
const boards = Boards.userSearch(userId, {
for (const query of queryParams.getPredicates(OPERATOR_BOARD)) {
const boards = await Boards.userSearch(userId, {
title: new RegExp(escapeForRegex(query), 'i'),
});
if (boards.length) {
@ -435,7 +435,7 @@ async function buildSelector(queryParams) {
} else {
errors.addNotFound(OPERATOR_BOARD, query);
}
});
}
selector.boardId.$in = queryBoards;
}
@ -550,17 +550,13 @@ async function buildSelector(queryParams) {
if (queryParams.hasOperator(OPERATOR_LABEL)) {
const queryLabels = [];
queryParams.getPredicates(OPERATOR_LABEL).forEach(label => {
let boards = Boards.userBoards(userId, null, {
for (const label of queryParams.getPredicates(OPERATOR_LABEL)) {
let boards = await Boards.userBoards(userId, null, {
labels: { $elemMatch: { color: label.toLowerCase() } },
});
if (boards.length) {
boards.forEach(board => {
// eslint-disable-next-line no-console
// console.log('board:', board);
// eslint-disable-next-line no-console
// console.log('board.labels:', board.labels);
board.labels
.filter(boardLabel => {
return boardLabel.color === label.toLowerCase();
@ -570,12 +566,8 @@ async function buildSelector(queryParams) {
});
});
} else {
// eslint-disable-next-line no-console
// console.log('label:', label);
const reLabel = new RegExp(escapeForRegex(label), 'i');
// eslint-disable-next-line no-console
// console.log('reLabel:', reLabel);
boards = Boards.userBoards(userId, null, {
boards = await Boards.userBoards(userId, null, {
labels: { $elemMatch: { name: reLabel } },
});
@ -596,7 +588,7 @@ async function buildSelector(queryParams) {
errors.addNotFound(OPERATOR_LABEL, label);
}
}
});
}
if (queryLabels.length) {
// eslint-disable-next-line no-console
// console.log('queryLabels:', queryLabels);

View file

@ -340,13 +340,14 @@ RulesHelper = {
sort: 0,
});
const itemsArray = action.checklistItems.split(',');
const checkList = await ReactiveCache.getChecklist(checkListId);
const existingItems = await ReactiveCache.getChecklistItems({ checklistId: checkListId });
const sortBase = existingItems.length;
for (let i = 0; i < itemsArray.length; i++) {
ChecklistItems.insert({
title: itemsArray[i],
checklistId: checkListId,
cardId: card._id,
sort: checkList.itemCount(),
sort: sortBase + i,
});
}
}