mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 14:20:31 +00:00
- feat: Optimize tenancy software architecture.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { Service, Container, Inject } from 'typedi';
|
||||
import cryptoRandomString from 'crypto-random-string';
|
||||
import { times } from 'lodash';
|
||||
import { Voucher } from "@/system/models";
|
||||
import { IVoucher } from '@/interfaces';
|
||||
import VoucherMailMessages from '@/services/Payment/VoucherMailMessages';
|
||||
@@ -26,6 +27,8 @@ export default class VoucherService {
|
||||
let voucherCode: string;
|
||||
let repeat: boolean = true;
|
||||
|
||||
console.log(Voucher);
|
||||
|
||||
while(repeat) {
|
||||
voucherCode = cryptoRandomString({ length: 10, type: 'numeric' });
|
||||
const foundVouchers = await Voucher.query().where('voucher_code', voucherCode);
|
||||
@@ -39,6 +42,29 @@ export default class VoucherService {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {number} loop
|
||||
* @param {number} voucherPeriod
|
||||
* @param {string} periodInterval
|
||||
* @param {number} planId
|
||||
*/
|
||||
async generateVouchers(
|
||||
loop = 1,
|
||||
voucherPeriod: numner,
|
||||
periodInterval: string = 'days',
|
||||
planId: number,
|
||||
) {
|
||||
const asyncOpers: Promise<any>[] = [];
|
||||
|
||||
times(loop, () => {
|
||||
const generateOper = this.generateVoucher(voucherPeriod, periodInterval, planId);
|
||||
asyncOpers.push(generateOper);
|
||||
});
|
||||
return Promise.all(asyncOpers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the given voucher id on the storage.
|
||||
* @param {number} voucherId
|
||||
|
||||
Reference in New Issue
Block a user