Compare commits
No commits in common. "development" and "1.4.4-alpha.2" have entirely different histories.
developmen
...
1.4.4-alph
|
@ -49,7 +49,6 @@
|
||||||
"exceljs": "^4.4.0",
|
"exceljs": "^4.4.0",
|
||||||
"fs-extra": "^11.2.0",
|
"fs-extra": "^11.2.0",
|
||||||
"googleapis": "^140.0.0",
|
"googleapis": "^140.0.0",
|
||||||
"gtts": "^0.2.1",
|
|
||||||
"handlebars": "^4.7.8",
|
"handlebars": "^4.7.8",
|
||||||
"mathjs": "^13.0.2",
|
"mathjs": "^13.0.2",
|
||||||
"midtrans-client": "^1.3.1",
|
"midtrans-client": "^1.3.1",
|
||||||
|
|
|
@ -73,14 +73,13 @@ export class LoginAdminQueueManager extends BaseCustomManager<UserEntity> {
|
||||||
message: `Akun anda sudah login di item "${hasLoginAsQueue?.item_name}"`,
|
message: `Akun anda sudah login di item "${hasLoginAsQueue?.item_name}"`,
|
||||||
error: 'Unauthorized',
|
error: 'Unauthorized',
|
||||||
});
|
});
|
||||||
|
} else if (itemLogin && itemLogin.user_id !== this.userLogin.id) {
|
||||||
|
throw new UnauthorizedException({
|
||||||
|
statusCode: HttpStatus.UNAUTHORIZED,
|
||||||
|
message: `"${userLoginItem.name}" masih login sebagai admin antrian `,
|
||||||
|
error: 'Unauthorized',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
// else if (itemLogin && itemLogin.user_id !== this.userLogin.id) {
|
|
||||||
// throw new UnauthorizedException({
|
|
||||||
// statusCode: HttpStatus.UNAUTHORIZED,
|
|
||||||
// message: `"${userLoginItem.name}" masih login sebagai admin antrian `,
|
|
||||||
// error: 'Unauthorized',
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
// * Disini untuk isi token
|
// * Disini untuk isi token
|
||||||
const tokenData = {
|
const tokenData = {
|
||||||
|
|
|
@ -19,7 +19,6 @@ 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);
|
||||||
|
@ -96,41 +95,4 @@ 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,17 +5,13 @@ 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(
|
constructor(private configService: ConfigService) {}
|
||||||
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');
|
||||||
|
@ -68,11 +64,4 @@ 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';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,4 @@
|
||||||
import {
|
import { Controller, Get, Param, Query } from '@nestjs/common';
|
||||||
Controller,
|
|
||||||
Get,
|
|
||||||
Param,
|
|
||||||
Query,
|
|
||||||
UnauthorizedException,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { FilterItemQueueDto } from './dto/filter-item-queue.dto';
|
import { FilterItemQueueDto } from './dto/filter-item-queue.dto';
|
||||||
import { Pagination } from 'src/core/response';
|
import { Pagination } from 'src/core/response';
|
||||||
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
|
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
|
||||||
|
@ -13,7 +7,6 @@ import { ItemQueueReadOrchestrator } from '../domain/usecases/item-queue-read.or
|
||||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||||
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
||||||
import { Public } from 'src/core/guards';
|
import { Public } from 'src/core/guards';
|
||||||
import { validate as isValidUUID } from 'uuid';
|
|
||||||
|
|
||||||
@ApiTags(`${MODULE_NAME.ITEM_QUEUE.split('-').join(' ')} - read`)
|
@ApiTags(`${MODULE_NAME.ITEM_QUEUE.split('-').join(' ')} - read`)
|
||||||
@Controller(`v1/${MODULE_NAME.ITEM_QUEUE}`)
|
@Controller(`v1/${MODULE_NAME.ITEM_QUEUE}`)
|
||||||
|
@ -51,7 +44,6 @@ export class ItemQueueReadController {
|
||||||
@Get('display/:id')
|
@Get('display/:id')
|
||||||
@Public(true)
|
@Public(true)
|
||||||
async detailPublic(@Param('id') id: string): Promise<ItemQueueEntity> {
|
async detailPublic(@Param('id') id: string): Promise<ItemQueueEntity> {
|
||||||
if (!isValidUUID(id)) throw new UnauthorizedException('id is required');
|
|
||||||
return await this.orchestrator.detail(id);
|
return await this.orchestrator.detail(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,10 +87,7 @@ export class QueueAdminOrchestrator {
|
||||||
// },
|
// },
|
||||||
// ]);
|
// ]);
|
||||||
|
|
||||||
if (
|
if (queueTicket.last_notification < currentTime - call_preparation) {
|
||||||
queueTicket.item.ticket.phone != null &&
|
|
||||||
queueTicket.last_notification < currentTime - call_preparation
|
|
||||||
) {
|
|
||||||
await notification.queueProcess(payload);
|
await notification.queueProcess(payload);
|
||||||
this.service.updateLastNotification(queueId, currentTime);
|
this.service.updateLastNotification(queueId, currentTime);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ export class QueueTimeFormula {
|
||||||
|
|
||||||
const times = itemQueue.items.map((item) => item.play_estimation ?? 0);
|
const times = itemQueue.items.map((item) => item.play_estimation ?? 0);
|
||||||
const average = times.length > 0 ? math.mean(times) * 60 * 1000 : 0; // change average minute to milliseconds
|
const average = times.length > 0 ? math.mean(times) * 60 * 1000 : 0; // change average minute to milliseconds
|
||||||
this.average = Math.floor(average);
|
this.average = average;
|
||||||
|
|
||||||
const calledQueue = await this.queueDataService.lastQueue(item_queue_id);
|
const calledQueue = await this.queueDataService.lastQueue(item_queue_id);
|
||||||
|
|
||||||
|
|
|
@ -61,10 +61,10 @@ export class GenerateQueueManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
const results: QueueModel[] = [];
|
const results: QueueModel[] = [];
|
||||||
const vipCustomer =
|
if (
|
||||||
transaction.customer_category?.has_vip_pass ||
|
transaction.customer_category?.has_vip_pass ||
|
||||||
transaction.customer_type === TransactionUserType.VIP;
|
transaction.customer_type === TransactionUserType.VIP
|
||||||
if (vipCustomer || transaction.creator_counter_no != null) {
|
) {
|
||||||
for (const ticket of insertTickets) {
|
for (const ticket of insertTickets) {
|
||||||
const ticket_id = ticket.id;
|
const ticket_id = ticket.id;
|
||||||
const items = {};
|
const items = {};
|
||||||
|
@ -86,8 +86,7 @@ export class GenerateQueueManager {
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const payload of Object.values(items)) {
|
for (const payload of Object.values(items)) {
|
||||||
const isVip = vipCustomer || transaction.creator_counter_no == null;
|
const result = await this.create(payload as any);
|
||||||
const result = await this.create(payload as any, isVip);
|
|
||||||
results.push(result);
|
results.push(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,7 +134,7 @@ export class GenerateQueueManager {
|
||||||
return Object.values<QueueItem>(result);
|
return Object.values<QueueItem>(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(data: RegisterQueueDto, isVip = false): Promise<QueueModel> {
|
async create(data: RegisterQueueDto): Promise<QueueModel> {
|
||||||
const queue = await this.queueService.getTicketItems(
|
const queue = await this.queueService.getTicketItems(
|
||||||
data.ticket_id,
|
data.ticket_id,
|
||||||
data.item_id,
|
data.item_id,
|
||||||
|
@ -143,7 +142,7 @@ export class GenerateQueueManager {
|
||||||
const queueRequest: any = {
|
const queueRequest: any = {
|
||||||
qty: data.qty,
|
qty: data.qty,
|
||||||
item_id: queue.id,
|
item_id: queue.id,
|
||||||
vip: isVip,
|
vip: true,
|
||||||
};
|
};
|
||||||
const registerQueueManager = new RegisterQueueManager(
|
const registerQueueManager = new RegisterQueueManager(
|
||||||
this.bucketService,
|
this.bucketService,
|
||||||
|
@ -153,9 +152,6 @@ export class GenerateQueueManager {
|
||||||
registerQueueManager.setService(this.queueService, TABLE_NAME.QUEUE);
|
registerQueueManager.setService(this.queueService, TABLE_NAME.QUEUE);
|
||||||
await registerQueueManager.execute();
|
await registerQueueManager.execute();
|
||||||
|
|
||||||
const result = await registerQueueManager.getResult();
|
return registerQueueManager.getResult();
|
||||||
result.time = null;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ export class RegisterQueueManager extends BaseCreateManager<QueueModel> {
|
||||||
const first = queues[0];
|
const first = queues[0];
|
||||||
const last = queues[queues.length - 1] ?? moment().valueOf();
|
const last = queues[queues.length - 1] ?? moment().valueOf();
|
||||||
const average = this.queueTimeFormula.average;
|
const average = this.queueTimeFormula.average;
|
||||||
return [Math.floor(first), Math.floor(last + average)];
|
return [first, last + average];
|
||||||
}
|
}
|
||||||
|
|
||||||
async beforeProcess(): Promise<void> {
|
async beforeProcess(): Promise<void> {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Body, Controller, Get, Param, Post, Query, Res } from '@nestjs/common';
|
import { Body, Controller, Get, Param, Post } from '@nestjs/common';
|
||||||
|
|
||||||
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
||||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||||
|
@ -15,9 +15,6 @@ import { mappingRevertTransaction } from 'src/modules/transaction/transaction/do
|
||||||
import { TransactionType } from 'src/modules/transaction/transaction/constants';
|
import { TransactionType } from 'src/modules/transaction/transaction/constants';
|
||||||
import { QueueModel } from '../../data/models/queue.model';
|
import { QueueModel } from '../../data/models/queue.model';
|
||||||
|
|
||||||
import * as Gtts from 'gtts';
|
|
||||||
import { Response } from 'express';
|
|
||||||
|
|
||||||
@ApiTags(`Queue`)
|
@ApiTags(`Queue`)
|
||||||
@Controller(`v1/${MODULE_NAME.QUEUE}`)
|
@Controller(`v1/${MODULE_NAME.QUEUE}`)
|
||||||
@Public(true)
|
@Public(true)
|
||||||
|
@ -108,15 +105,6 @@ export class QueueController {
|
||||||
return await this.orchestrator.queueOrderItems(id);
|
return await this.orchestrator.queueOrderItems(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('speech')
|
|
||||||
async speech(
|
|
||||||
@Query('text') text: string,
|
|
||||||
@Res() response: Response,
|
|
||||||
): Promise<void> {
|
|
||||||
const gtts = new Gtts(text, 'id');
|
|
||||||
gtts.stream().pipe(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get(':id/items/:item_id')
|
@Get(':id/items/:item_id')
|
||||||
async queueItemTickets(
|
async queueItemTickets(
|
||||||
@Param('id') id: string,
|
@Param('id') id: string,
|
||||||
|
|
|
@ -116,7 +116,7 @@ export function mappingRevertTransaction(data, type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.assign(data, {
|
Object.assign(data, {
|
||||||
id: data.booking_id ?? data._id ?? data.id,
|
id: data.booking_id ?? data._id,
|
||||||
creator_counter_no: Number(data.pos_number),
|
creator_counter_no: Number(data.pos_number),
|
||||||
creator_counter_name: data.pos_name,
|
creator_counter_name: data.pos_name,
|
||||||
settlement_date: new Date(data.created_at),
|
settlement_date: new Date(data.created_at),
|
||||||
|
|
|
@ -12,7 +12,6 @@ import {
|
||||||
} from './whatsapp.constant';
|
} from './whatsapp.constant';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { Logger } from '@nestjs/common';
|
import { Logger } from '@nestjs/common';
|
||||||
import { apm } from 'src/core/apm';
|
|
||||||
|
|
||||||
export class WhatsappService {
|
export class WhatsappService {
|
||||||
async sendMessage(data) {
|
async sendMessage(data) {
|
||||||
|
@ -26,14 +25,8 @@ export class WhatsappService {
|
||||||
data: data,
|
data: data,
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
const response = await axios(config);
|
||||||
const response = await axios(config);
|
return response.data;
|
||||||
return response.data;
|
|
||||||
} catch (error) {
|
|
||||||
Logger.error(error);
|
|
||||||
apm?.captureError(error);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async queueRegister(data: WhatsappQueue) {
|
async queueRegister(data: WhatsappQueue) {
|
||||||
|
@ -98,11 +91,8 @@ export class WhatsappService {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await this.sendMessage(payload);
|
await this.sendMessage(payload);
|
||||||
if (response)
|
Logger.log(`Notification register for ${data.code} send to ${data.phone}`);
|
||||||
Logger.log(
|
|
||||||
`Notification register for ${data.code} send to ${data.phone}`,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async queueProcess(data: WhatsappQueue) {
|
async queueProcess(data: WhatsappQueue) {
|
||||||
|
@ -162,8 +152,7 @@ export class WhatsappService {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await this.sendMessage(payload);
|
await this.sendMessage(payload);
|
||||||
if (response)
|
Logger.log(`Notification process for ${data.code} send to ${data.phone}`);
|
||||||
Logger.log(`Notification process for ${data.code} send to ${data.phone}`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue