本文整理汇总了TypeScript中utilities/mongodb-util.saveWithId函数的典型用法代码示例。如果您正苦于以下问题:TypeScript saveWithId函数的具体用法?TypeScript saveWithId怎么用?TypeScript saveWithId使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了saveWithId函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: resolve
return new Promise<any>(async (resolve, reject) => {
try {
transaction.errMsg = 'Anonymous transaction';
await saveWithId<XemTransaction>(DB_PROBLEM_XEM_CHARGES, transaction);
resolve();
} catch (err) {
transaction.errMsg = 'Anonymous transaction + err: ' + err;
await saveWithId<XemTransaction>(DB_PROBLEM_XEM_CHARGES, transaction);
reject(err);
}
});
示例3: 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();
}
}
}
};
示例4: async
.map( async (transferTransaction: TransferTransaction) => {
try {
const rawMsg = (transferTransaction.message as PlainMessage).plain().replace(/ /g, '');
const hashId = rawMsg.substr(rawMsg.indexOf(':'), rawMsg.length);
/**
* Try finding a transaction in the database that may be a partial payment. Sometimes people will send
* multiple amounts of XEM to purchase a product
*/
let transaction: XemTransaction = await findOneThatContains<XemTransaction>(DB_PARTIAL_XEM_CHARGES, 'message', hashId, TRANSACTION_MESSAGE_LENGTH);
/**
* If it is not partial, we look up pending charges
*/
if (!transaction) {
transaction = await findOneThatContains<XemTransaction>(DB_PENDING_XEM_CHARGES, 'message', hashId, TRANSACTION_MESSAGE_LENGTH);
}
const transfer = await formatIncomingTransaction(transferTransaction);
/**
* Ignore transactions that are confirmed for the holding account - we only want to
* listen for customer transactions
*/
if (transfer.tokenRecipientAddress === tokenHoldingAccountAddress()
|| transfer.tokenRecipientAddress === nemConfig.multisigAddress) {
return;
}
/**
* If the transaction is not in the database someone sent us XEM without using
* our purchase process on the website
*/
if (!transaction) {
saveAnonymousTransaction(transfer);
} else {
/**
* We found the pending transaction in the database
*/
onTransactionConfirmed(transaction, transfer);
}
} catch (err) {
/**
* Save errors to the database so we can handle customer inquiries
*/
const amountPaid = transferTransaction.xem().amount;
const errorTrans: XemTransaction = {
_id: new ObjectID(),
tokenRecipientAddress: transferTransaction.signer.address.plain(),
tokenType: TokenType.NA,
totalPaid: amountPaid,
message: 'Contains mosaics: ' + transferTransaction.containsMosaics(),
createdAt: new Date(),
errMsg: err
};
await saveWithId<XemTransaction>(DB_PROBLEM_XEM_CHARGES, errorTrans);
}
})
示例5: ObjectID
const movePendingTransaction = (transaction: XemTransaction): XemTransaction => {
if (transaction.totalPaid > 0) {
const partialId = transaction._id.toHexString();
transaction._id = new ObjectID();
transaction.createdAt = new Date();
saveWithId<XemTransaction>(DB_PENDING_XEM_CHARGES, transaction);
deleteById<XemTransaction>(DB_PARTIAL_XEM_CHARGES, partialId);
}
return transaction;
};
示例6: async
api.put('/update-usd', async (req: Request, res: Response) => {
try {
const totals: Array<UsdTotal> = await findAll<UsdTotal>(DB_USD_TOTALS);
if (totals.length === 0) {
const total: UsdTotal = {
_id: new ObjectID(),
currentRaised: req.body.currentRaised,
nextMilestone: req.body.nextMilestone
};
await saveWithId<UsdTotal>(DB_USD_TOTALS, total);
} else {
totals[0].currentRaised = precisionRound(req.body.currentRaised, 2);
totals[0].nextMilestone = precisionRound(req.body.nextMilestone, 2);
const id = totals[0]._id.toHexString();
delete totals[0]._id;
await update<UsdTotal>(DB_USD_TOTALS, id, totals[0]);
}
return res.status(202).json({message: 'ok'});
} catch (err) {
res.status(409).json(err);
}
});
示例7: 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);
}
});
示例8: 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);
}
});