mirror of
https://github.com/Litlyx/litlyx
synced 2026-02-04 06:32:20 +01:00
Services rewrite
This commit is contained in:
@@ -13,6 +13,8 @@ export const EVENT_NAMES_EXPIRE_TIME = 60;
|
||||
|
||||
export const EVENT_METADATA_FIELDS_EXPIRE_TIME = 30;
|
||||
|
||||
type UseCacheV2Callback<T> = (noStore: () => void, updateExp: (value: number) => void) => Promise<T>
|
||||
|
||||
|
||||
export class Redis {
|
||||
|
||||
@@ -65,4 +67,17 @@ export class Redis {
|
||||
return result;
|
||||
}
|
||||
|
||||
static async useCacheV2<T extends any>(key: string, exp: number, callback: UseCacheV2Callback<T>) {
|
||||
const cached = await this.get<T>(key);
|
||||
if (cached) return cached;
|
||||
let expireValue = exp;
|
||||
let shouldStore = true;
|
||||
const noStore = () => shouldStore = false;
|
||||
const updateExp = (newExp: number) => expireValue = newExp;
|
||||
const result = await callback(noStore, updateExp);
|
||||
if (!shouldStore) return result;
|
||||
await this.set(key, result, expireValue);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -56,7 +56,7 @@ class StripeService {
|
||||
return checkout;
|
||||
}
|
||||
|
||||
async cretePayment(price: string, success_url: string, pid: string, customer?: string) {
|
||||
async createPayment(price: string, success_url: string, pid: string, customer?: string) {
|
||||
if (this.disabledMode) return;
|
||||
if (!this.stripe) throw Error('Stripe not initialized');
|
||||
|
||||
@@ -126,6 +126,22 @@ class StripeService {
|
||||
return customer;
|
||||
}
|
||||
|
||||
async setCustomerInfo(customer_id: string, address: { line1: string, line2: string, city: string, country: string, postal_code: string, state: string }) {
|
||||
if (this.disabledMode) return;
|
||||
if (!this.stripe) throw Error('Stripe not initialized');
|
||||
const customer = await this.stripe.customers.update(customer_id, {
|
||||
address: {
|
||||
line1: address.line1,
|
||||
line2: address.line2,
|
||||
city: address.city,
|
||||
country: address.country,
|
||||
postal_code: address.postal_code,
|
||||
state: address.state
|
||||
}
|
||||
})
|
||||
return customer.id;
|
||||
}
|
||||
|
||||
async deleteCustomer(customer_id: string) {
|
||||
if (this.disabledMode) return;
|
||||
if (!this.stripe) throw Error('Stripe not initialized');
|
||||
|
||||
@@ -46,7 +46,7 @@ export async function executeAdvancedTimelineAggregation<T = {}>(options: Advanc
|
||||
console.log(JSON.stringify(aggregation, null, 2));
|
||||
}
|
||||
|
||||
const timeline: { _id: string, count: number & T }[] = await options.model.aggregate(aggregation);
|
||||
const timeline: ({ _id: string, count: number } & T)[] = await options.model.aggregate(aggregation);
|
||||
|
||||
return timeline;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user