Compare commits
4 Commits
1.4.5-prod
...
production
Author | SHA1 | Date |
---|---|---|
|
0b482be669 | |
|
064112e731 | |
|
05473fce3d | |
|
d6a238a224 |
|
@ -19,6 +19,7 @@ export class CouchService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async onModuleInit() {
|
async onModuleInit() {
|
||||||
|
// return;
|
||||||
const nano = this.nanoInstance;
|
const nano = this.nanoInstance;
|
||||||
for (const database of DatabaseListen) {
|
for (const database of DatabaseListen) {
|
||||||
const db = nano.db.use(database);
|
const db = nano.db.use(database);
|
||||||
|
@ -95,4 +96,41 @@ export class CouchService {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getUnixTimestampLast7Days() {
|
||||||
|
const date = new Date();
|
||||||
|
date.setDate(date.getDate() - 4);
|
||||||
|
date.setHours(0, 0, 0, 0);
|
||||||
|
return date.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async clearTransactions() {
|
||||||
|
const nano = this.nanoInstance;
|
||||||
|
const transaction = nano.use('transaction');
|
||||||
|
|
||||||
|
const expiredDate = this.getUnixTimestampLast7Days();
|
||||||
|
|
||||||
|
const selectorPayment = {
|
||||||
|
created_at: {
|
||||||
|
$lt: expiredDate,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const transactions = await transaction.find({
|
||||||
|
selector: selectorPayment,
|
||||||
|
fields: ['_id', '_rev'],
|
||||||
|
limit: 100000,
|
||||||
|
});
|
||||||
|
|
||||||
|
const { docs } = transactions;
|
||||||
|
console.log(docs.length);
|
||||||
|
const deletedDocs = {
|
||||||
|
docs: docs.map((doc) => ({
|
||||||
|
_id: doc._id,
|
||||||
|
_rev: doc._rev,
|
||||||
|
_deleted: true,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
await transaction.bulk(deletedDocs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,17 @@ import { Public } from 'src/core/guards';
|
||||||
import * as Nano from 'nano';
|
import * as Nano from 'nano';
|
||||||
import { CreateUserPrivilegeDto } from 'src/modules/user-related/user-privilege/infrastructure/dto/create-user-privilege.dto';
|
import { CreateUserPrivilegeDto } from 'src/modules/user-related/user-privilege/infrastructure/dto/create-user-privilege.dto';
|
||||||
import { ConfigService } from '@nestjs/config';
|
import { ConfigService } from '@nestjs/config';
|
||||||
|
import { CouchService } from '../data/services/couch.service';
|
||||||
|
|
||||||
@ApiTags(`couch`)
|
@ApiTags(`couch`)
|
||||||
@Controller('v1/couch')
|
@Controller('v1/couch')
|
||||||
@Public()
|
@Public()
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CouchDataController {
|
export class CouchDataController {
|
||||||
constructor(private configService: ConfigService) {}
|
constructor(
|
||||||
|
private configService: ConfigService,
|
||||||
|
private couchService: CouchService,
|
||||||
|
) {}
|
||||||
|
|
||||||
get nanoInstance() {
|
get nanoInstance() {
|
||||||
const couchConfiguration = this.configService.get<string>('COUCHDB_CONFIG');
|
const couchConfiguration = this.configService.get<string>('COUCHDB_CONFIG');
|
||||||
|
@ -64,4 +68,11 @@ export class CouchDataController {
|
||||||
// return people.get();
|
// return people.get();
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Public(true)
|
||||||
|
@Get('clear-transactions')
|
||||||
|
async clearTransactions(): Promise<string> {
|
||||||
|
await this.couchService.clearTransactions();
|
||||||
|
return 'OK';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,7 +144,6 @@ export class GenerateQueueManager {
|
||||||
qty: data.qty,
|
qty: data.qty,
|
||||||
item_id: queue.id,
|
item_id: queue.id,
|
||||||
vip: isVip,
|
vip: isVip,
|
||||||
showTime: false,
|
|
||||||
};
|
};
|
||||||
const registerQueueManager = new RegisterQueueManager(
|
const registerQueueManager = new RegisterQueueManager(
|
||||||
this.bucketService,
|
this.bucketService,
|
||||||
|
@ -154,6 +153,9 @@ export class GenerateQueueManager {
|
||||||
registerQueueManager.setService(this.queueService, TABLE_NAME.QUEUE);
|
registerQueueManager.setService(this.queueService, TABLE_NAME.QUEUE);
|
||||||
await registerQueueManager.execute();
|
await registerQueueManager.execute();
|
||||||
|
|
||||||
return registerQueueManager.getResult();
|
const result = await registerQueueManager.getResult();
|
||||||
|
result.time = null;
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,6 @@ export class RegisterQueueManager extends BaseCreateManager<QueueModel> {
|
||||||
|
|
||||||
async beforeProcess(): Promise<void> {
|
async beforeProcess(): Promise<void> {
|
||||||
const vip = this.data.vip ?? false;
|
const vip = this.data.vip ?? false;
|
||||||
const showTime = this.data.showTime ?? true;
|
|
||||||
const item = await this.getItemMaster();
|
const item = await this.getItemMaster();
|
||||||
this.currentItemMaster = item;
|
this.currentItemMaster = item;
|
||||||
const [, end] = await this.queueTime(item.item_queue_id);
|
const [, end] = await this.queueTime(item.item_queue_id);
|
||||||
|
@ -57,7 +56,7 @@ export class RegisterQueueManager extends BaseCreateManager<QueueModel> {
|
||||||
|
|
||||||
Object.assign(this.data, {
|
Object.assign(this.data, {
|
||||||
status: STATUS.WAITING,
|
status: STATUS.WAITING,
|
||||||
time: showTime ? end : undefined,
|
time: end,
|
||||||
item_queue_id: item.item_queue_id,
|
item_queue_id: item.item_queue_id,
|
||||||
vip,
|
vip,
|
||||||
code,
|
code,
|
||||||
|
|
Loading…
Reference in New Issue