本文整理汇总了TypeScript中utilities/mongodb-util.findById函数的典型用法代码示例。如果您正苦于以下问题:TypeScript findById函数的具体用法?TypeScript findById怎么用?TypeScript findById使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了findById函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: movePendingTransaction
return new Promise<any>(async (resolve, reject) => {
const pendingTransaction = movePendingTransaction(transaction);
try {
const totalPaid = transfer.totalPaid;
const pendingId = pendingTransaction._id.toHexString();
pendingTransaction._id = new ObjectID();
if (!pendingTransaction.productId || (transfer.tokenType !== TokenType.XEM)) {
const err = new Error('Product Id not found in transaction or XEM was not sent');
pendingTransaction.errMsg = err.message;
await saveWithId<XemTransaction>(DB_PROBLEM_XEM_CHARGES, pendingTransaction);
await deleteById<XemTransaction>(DB_PENDING_XEM_CHARGES, pendingId);
return reject(err);
}
pendingTransaction.totalPaid += totalPaid;
pendingTransaction.usdPaid += transfer.usdPaid;
if (pendingTransaction.totalPaid >= pendingTransaction.quotedAmount) {
const product: Product = await findById<Product>(DB_PRODUCTS, pendingTransaction.productId.toHexString());
pendingTransaction.transactionCompletedTimestamp = new Date().toISOString();
onChargeSuccess(
product.tokenAmount,
pendingTransaction.tokenRecipientAddress);
await saveWithId<XemTransaction>(DB_COMPLETED_XEM_CHARGES, pendingTransaction);
} else {
await saveWithId<XemTransaction>(DB_PARTIAL_XEM_CHARGES, pendingTransaction);
}
resolve(await deleteById<XemTransaction>(DB_PENDING_XEM_CHARGES, pendingId));
} catch (err) {
const pendingId = pendingTransaction._id.toHexString();
pendingTransaction._id = new ObjectID();
pendingTransaction.errMsg = err;
await saveWithId<XemTransaction>(DB_PROBLEM_XEM_CHARGES, pendingTransaction);
await deleteById<XemTransaction>(DB_PENDING_XEM_CHARGES, pendingId);
reject(err);
}
});
示例2: async
api.post('/initiate-coinbase-purchase', vInitateCoinbasePurchase, async (req: Request, res: Response) => {
try {
const product = await findById<Product>(DB_PRODUCTS, req.body[KEY_PRODUCT_ID]);
if (!product.isEnabled) { return res.status(409).json(new Error('Product temporarily locked.')); }
res.send(await createCoinbaseCharge(req.body[KEY_TOKEN_RECIPIENT_ADDRESS], req.body[KEY_PRODUCT_ID]));
} catch (err) {
res.status(409).json(err);
}
});
示例3: catch
return new Promise<Product>(async (resolve, reject) => {
try {
const product: Product = await findById<Product>(DB_PRODUCTS, productId);
if (product) {
resolve(product);
} else {
reject(stError.TRANS_PRODUCT_NOT_FOUND);
}
} catch (err) {
reject(stError.TRANS_PRODUCT_NOT_FOUND);
}
});
示例4: async
const processTransaction = async (charge: CoinbaseCharge, localCharge: CoinbaseCharge) => {
/**
* A length of 1 means the Status is NEW. We can skip these
*/
if (charge.timeline.length < 2) return;
for (const event of charge.timeline) {
switch (event.status) {
/**
* Handle the problems first
*/
case CoinbaseStatus.EXPIRED:
case CoinbaseStatus.UNRESOLVED: {
/**
* We are going to move this data into a new db collection, but first we
* need to carry over important data
*/
// Save problem to the problems collection
charge._id = new ObjectID();
saveWithId<CoinbaseCharge>(DB_PROBLEM_COINBASE_CHARGES, charge).then().catch();
// Remove the problem transaction from the pending transactions
// Find the existing pending charge in the database
deleteById<CoinbaseCharge>(DB_PENDING_COINBASE_CHARGES, localCharge._id).then().catch();
break;
}
case CoinbaseStatus.COMPLETED: {
/**
* Initiate token transfer process
* Save success transaction to success collection
* Delete pending transaction
*/
const product: Product = await findById<Product>(DB_PRODUCTS, charge.metadata.token_product_id);
if (product) {
onChargeSuccess(product.tokenAmount, charge.metadata.token_recipient_address).then().catch((err) => {
console.log(err);
});
saveWithId<CoinbaseCharge>(DB_COMPLETED_COINBASE_TRANSACTIONS, charge).then().catch();
}
deleteById<CoinbaseCharge>(DB_PENDING_COINBASE_CHARGES, localCharge._id).then().catch();
}
}
}
};
示例5: coinbaseTokenPurchaseDescription
return new Promise<string>(async (resolve, reject) => {
try {
const product: Product = await findById<Product>(DB_PRODUCTS, productId);
const newCharge: CoinbaseCharge = {
name: stEndUser.COINBASE_TOKEN_PURCHASE_NAME,
description: coinbaseTokenPurchaseDescription(product),
local_price: {
amount: `${product.priceUSD}`,
currency: 'USD'
},
pricing_type: 'fixed_price',
metadata: {
token_product_id: `${product._id}`,
token_recipient_address: `${tokenRecipientAddress}`
}
};
const config: AxiosRequestConfig = {
url: 'https://api.commerce.coinbase.com/charges',
method: 'post',
headers: {
'Content-Type': 'application/json',
'X-CC-Api-Key': `${process.env.COINBASE_API_KEY}`,
'X-CC-Version': '2018-03-22'
},
data: newCharge
};
const json: any = await axios(config);
const coinbaseCharge: CoinbaseCharge = json.data.data as CoinbaseCharge;
coinbaseCharge._id = new ObjectID();
await saveWithId<CoinbaseCharge>(DB_PENDING_COINBASE_CHARGES, coinbaseCharge);
resolve(coinbaseCharge.hosted_url);
} catch (err) {
console.log(err);
reject(err);
}
});
示例6: Address
return new Promise<any>(async (resolve, reject) => {
try {
const senderAddress = new Address(req.body.tokenRecipientAddress).plain();
const createdDate = new Date();
const hashId = await generateHashId(senderAddress, createdDate.toISOString());
const product = await findById<Product>(DB_PRODUCTS, req.body.productId);
const quotedAmount = await usdToXem(product.priceUSD);
const data: XemTransaction = {
_id: new ObjectID(),
tokenRecipientAddress: senderAddress,
tokenType: req.body.tokenType,
productId: product._id,
totalPaid: 0,
quotedAmount: precisionRound(quotedAmount * 1e6, 0),
usdPaid: 0,
message: MESSAGE_PREFIX + hashId,
createdAt: createdDate
};
await saveWithId<XemTransaction>(DB_PENDING_XEM_CHARGES, data);
resolve({tokenRecipientAddress: tokenHoldingAccountAddress(), message: data.message, usdValue: product.priceUSD, xemAmount: precisionRound(quotedAmount, 6)});
} catch (err) {
reject(err);
}
});