Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const selector = {
_id: cartId
};
const update = {
$set: {
billing: payments
}
};
try {
Collections.Cart.update(selector, update);
} catch (e) {
Logger.error(e);
throw new Meteor.Error("server-error", "An error occurred saving the order");
}
// Calculate discounts
Hooks.Events.run("afterCartUpdateCalculateDiscount", cartId);
// Calculate taxes
Hooks.Events.run("afterCartUpdateCalculateTaxes", cartId);
return Collections.Cart.findOne(selector);
},
function checkUserMayLeave(meetingSeriesId) {
// Make sure the user is logged in before changing collections
if (!Meteor.userId()) {
throw new Meteor.Error('not-authorized');
}
// Ensure user can not update documents of other users
let userRoles = new UserRoles(Meteor.userId());
if (userRoles.isModeratorOf(meetingSeriesId)) {
throw new Meteor.Error('Cannot leave this meeting series', 'Moderators may only be removed by other moderators.');
}
if (! userRoles.isInvitedTo(meetingSeriesId)) {
throw new Meteor.Error('Cannot leave this meeting series', 'You are not invited to this meeting series.');
}
}
function processStockOffering(investors) {
let price = calculateInitialPrice(investors);
let directors;
let totalRelease;
do {
if (price < 1) {
throw new Meteor.Error('something went wrong: price < 1');
}
directors = calculateDirectors(investors, price);
totalRelease = _.reduce(directors, (sum, directorData) => {
return sum + directorData.stocks;
}, 0);
// 確保股數在最小限制之上,否則股價折半重新計算
if (totalRelease < minReleaseStock) {
price = Math.floor(price / 2);
}
}
while (totalRelease < minReleaseStock);
return { directors, price, totalRelease };
if (productHasAncestors) {
// Verify there are no deleted ancestors,
// Variants cannot be restored if their parent product / variant is deleted
const archivedCount = Revisions.find({
"documentId": { $in: product.ancestors },
"documentData.isDeleted": true,
"workflow.status": {
$nin: [
"revision/published"
]
}
}).count();
if (archivedCount > 0) {
Logger.debug(`Cannot create product ${product._id} as a product/variant higher in it's ancestors tree is marked as 'isDeleted'.`);
throw new Meteor.Error("unable-to-create-variant", "Unable to create product variant");
}
}
if (!productRevision) {
Logger.debug(`No revision found for product ${product._id}. Creating new revision`);
Revisions.insert({
documentId: product._id,
documentData: product
});
}
});
throw new Meteor.Error(403, '擁有的股票數量不足,訂單無法成立!');
}
const companyData = dbCompanies.findOne(companyId, {
fields: {
_id: 1,
companyName: 1,
listPrice: 1,
lastPrice: 1,
isSeal: 1
}
});
if (! companyData) {
throw new Meteor.Error(404, '不存在的公司股票,訂單無法成立!');
}
if (companyData.isSeal) {
throw new Meteor.Error(403, `「${companyData.companyName}」公司已被金融管理委員會查封關停了!`);
}
if (orderData.unitPrice < Math.max(Math.floor(companyData.listPrice * 0.85), 1)) {
throw new Meteor.Error(403, '每股單價不可偏離該股票參考價格的百分之十五!');
}
if (companyData.listPrice < dbVariables.get('lowPriceThreshold')) {
if (orderData.unitPrice > Math.ceil(companyData.listPrice * 1.3)) {
throw new Meteor.Error(403, '每股單價不可高於該股票參考價格的百分之三十!');
}
}
else if (orderData.unitPrice > Math.max(Math.ceil(companyData.listPrice * 1.15), 1)) {
throw new Meteor.Error(403, '每股單價不可偏離該股票參考價格的百分之十五!');
}
resourceManager.throwErrorIsResourceIsLock(['season', 'allCompanyOrders', `companyOrder${companyId}`, `user${userId}`]);
// 先鎖定資源,再重新讀取一次資料進行運算
resourceManager.request('createSellOrder', [`companyOrder${companyId}`, `user${userId}`], (release) => {
const directorData = dbDirectors.findOne({ companyId, userId }, {
collection[key] = (...args) => {
try {
return originalFcn.call(collection, ...args)
} catch (e) {
throw new Meteor.Error((e && e.error) || 500, (e && e.reason || e.toString()) || e || 'Unknown MongoDB Error')
}
}
}
function getMigrationShowStyleContext (chunk: MigrationChunk): IMigrationContextShowStyle {
if (chunk.sourceType !== MigrationStepType.SHOWSTYLE) throw new Meteor.Error(500, `wrong chunk.sourceType "${chunk.sourceType}", expected SHOWSTYLE`)
if (!chunk.sourceId) throw new Meteor.Error(500, `chunk.sourceId missing`)
let showStyleBase = ShowStyleBases.findOne(chunk.sourceId)
if (!showStyleBase) throw new Meteor.Error(404, `ShowStyleBase "${chunk.sourceId}" not found`)
return new MigrationContextShowStyle(showStyleBase)
}
"entry.startDiscussionThread"({entryID}) {
if (!this.userId) { throw new Meteor.Error('not-authorized'); }
const entry = Entries.findOne(entryID);
if (entry.mailingListID) {
throw new Meteor.Error("Entries.methods.startDiscussionThread.alreadyStarted", "Discussion thread has already been started.");
} else {
if (Meteor.isServer) {
Notifications.sendNewEntryEmail(entryID);
}
Entries.update(entryID, {$set: {
mailingListID: entryID,
updatedAt: new Date(),
}});
}
},
setUserStatus(statusType, statusText) {
const userId = Meteor.userId();
if (!userId) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'setUserStatus' });
}
if (statusType) {
Meteor.call('UserPresence:setDefaultStatus', statusType);
}
if (statusText || statusText === '') {
check(statusText, String);
if (!settings.get('Accounts_AllowUserStatusMessageChange')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', {
method: 'setUserStatus',
});
}
setStatusText(userId, statusText);
}
},
});
_assertRole(userId, roles) {
if (!userId) {
throw new Meteor.Error('unauthorized', 'You must be logged in.');
} else
if (!Roles.userIsInRole(userId, roles)) {
throw new Meteor.Error('unauthorized', `You must be one of the following roles: ${roles}`);
}
return true;
}