@xuda.io/account_module 1.2.1542 → 1.2.1544
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.mjs +6 -3
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -3050,17 +3050,20 @@ export const record_ai_usage = async function (uid, input_tokens, output_tokens,
|
|
|
3050
3050
|
|
|
3051
3051
|
export const record_ai_credit = async function (uid, credits = 0, source, details, credited_uid) {
|
|
3052
3052
|
try {
|
|
3053
|
-
var dup = await db_module.
|
|
3053
|
+
var dup = await db_module.find_couch_query('xuda_billing', {
|
|
3054
3054
|
selector: {
|
|
3055
3055
|
docType: 'ai_credit',
|
|
3056
3056
|
credited_uid,
|
|
3057
3057
|
details,
|
|
3058
3058
|
},
|
|
3059
|
-
fields: ['
|
|
3059
|
+
fields: ['_id'],
|
|
3060
3060
|
limit: 1,
|
|
3061
|
-
sort: [{ 'message.seq': 'desc' }],
|
|
3062
3061
|
});
|
|
3063
3062
|
|
|
3063
|
+
if (dup.docs.length) {
|
|
3064
|
+
throw new Error(`${details} already credited!`);
|
|
3065
|
+
}
|
|
3066
|
+
|
|
3064
3067
|
const t = Date.now();
|
|
3065
3068
|
let credit_doc = {
|
|
3066
3069
|
_id: await _common.xuda_get_uuid('ai_credit'),
|