Compare commits
9 Commits
1.6.25-alp
...
developmen
Author | SHA1 | Date |
---|---|---|
|
99889f425a | |
|
db7bd81eac | |
|
fcf9e9459e | |
|
2c92d4b8b3 | |
|
58e062dd6c | |
|
e1d8975dda | |
|
e25ad6500f | |
|
7bb539db0c | |
|
92b54635d0 |
|
@ -52,10 +52,12 @@ export class ValidateRelationHelper<Entity> {
|
|||
`Failed! this data already connected to ${relation.relation}`;
|
||||
|
||||
if (relation.singleQuery) {
|
||||
const relationObject = data[relation.relation] ?? {};
|
||||
const isRelationExist = `${relation.singleQuery[0]}` in relationObject;
|
||||
const relationColumn =
|
||||
data[relation.relation]?.[`${relation.singleQuery[0]}`];
|
||||
if (
|
||||
// !!relationColumn &&
|
||||
isRelationExist &&
|
||||
this.mappingValidator(
|
||||
relationColumn,
|
||||
relation.singleQuery[1],
|
||||
|
@ -76,6 +78,10 @@ export class ValidateRelationHelper<Entity> {
|
|||
case '==':
|
||||
return column == value;
|
||||
|
||||
case 'in':
|
||||
const candidates = Array.isArray(value) ? value : [value];
|
||||
return candidates.includes(column);
|
||||
|
||||
default:
|
||||
return column == value;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,19 @@ export class MidtransService {
|
|||
return diffInHours > 24;
|
||||
}
|
||||
|
||||
isCreatedMoreThan24HoursAgo(unixTimestamp) {
|
||||
const date = moment.unix(unixTimestamp);
|
||||
const now = moment();
|
||||
const diffInHours = now.diff(date, 'hours');
|
||||
return diffInHours > 24;
|
||||
}
|
||||
|
||||
isBookingDateExpired(bookingDate) {
|
||||
const bookingDateMoment = moment(bookingDate);
|
||||
const today = moment().startOf('day');
|
||||
return bookingDateMoment.isBefore(today);
|
||||
}
|
||||
|
||||
get midtransInstance() {
|
||||
return new Snap({
|
||||
isProduction: false,
|
||||
|
@ -38,16 +51,18 @@ export class MidtransService {
|
|||
const responses = [];
|
||||
|
||||
for (const transaction of pendingIds) {
|
||||
const { id, invoice_date } = transaction;
|
||||
const { id, booking_date, created_at } = transaction;
|
||||
let status;
|
||||
try {
|
||||
status = await this.getStatus(id);
|
||||
} catch (error) {
|
||||
status = {
|
||||
order_id: id,
|
||||
transaction_status: this.isMoreThan24HoursAgo(invoice_date)
|
||||
? 'cancel'
|
||||
: 'pending',
|
||||
transaction_status:
|
||||
this.isCreatedMoreThan24HoursAgo(created_at) ||
|
||||
this.isBookingDateExpired(booking_date)
|
||||
? 'expired'
|
||||
: 'pending',
|
||||
};
|
||||
}
|
||||
responses.push(status);
|
||||
|
|
|
@ -39,7 +39,7 @@ export class CreateItemManager extends BaseCreateManager<ItemEntity> {
|
|||
? [
|
||||
{
|
||||
relation: relation,
|
||||
singleQuery: ['time_group_id', '!=', timeGroupId],
|
||||
singleQuery: ['time_group_id', 'in', [timeGroupId, null]],
|
||||
message: `Gagal Update! Time group item dan bundling item tidak sama`,
|
||||
},
|
||||
]
|
||||
|
@ -52,13 +52,12 @@ export class CreateItemManager extends BaseCreateManager<ItemEntity> {
|
|||
? [
|
||||
{
|
||||
column: 'name',
|
||||
query: `(status = '${STATUS.ACTIVE}' AND (${this.tableName}.time_group_id Is Null OR ${this.tableName}.time_group_id = '${timeGroupId}'))`,
|
||||
query: `((${this.tableName}.time_group_id Is Null OR ${this.tableName}.time_group_id = '${timeGroupId}'))`,
|
||||
},
|
||||
]
|
||||
: [
|
||||
{
|
||||
column: 'name',
|
||||
query: `(status = '${STATUS.ACTIVE}')`,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ export class UpdateItemManager extends BaseUpdateManager<ItemEntity> {
|
|||
? [
|
||||
{
|
||||
relation: relation,
|
||||
singleQuery: ['time_group_id', '!=', timeGroupId],
|
||||
singleQuery: ['time_group_id', 'in', [timeGroupId, null]],
|
||||
message: `Gagal Update! Time group item dan bundling item tidak sama`,
|
||||
},
|
||||
]
|
||||
|
@ -59,12 +59,18 @@ export class UpdateItemManager extends BaseUpdateManager<ItemEntity> {
|
|||
|
||||
get uniqueColumns(): columnUniques[] {
|
||||
const timeGroupId = this.data.time_group_id ?? this.data.time_group?.id;
|
||||
return [
|
||||
{
|
||||
column: 'name',
|
||||
query: `(status = '${STATUS.ACTIVE}' AND (${this.tableName}.time_group_id Is Null OR ${this.tableName}.time_group_id = '${timeGroupId}'))`,
|
||||
},
|
||||
];
|
||||
return timeGroupId != null
|
||||
? [
|
||||
{
|
||||
column: 'name',
|
||||
query: `((${this.tableName}.time_group_id Is Null OR ${this.tableName}.time_group_id = '${timeGroupId}'))`,
|
||||
},
|
||||
]
|
||||
: [
|
||||
{
|
||||
column: 'name',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
get entityTarget(): any {
|
||||
|
|
|
@ -6,6 +6,8 @@ import {
|
|||
Param,
|
||||
RelationParam,
|
||||
} from 'src/core/modules/domain/entities/base-filter.entity';
|
||||
import * as moment from 'moment';
|
||||
import { ORDER_TYPE } from 'src/core/strings/constants/base.constants';
|
||||
|
||||
// TODO:
|
||||
// Implementasikan filter by start_time, end_timen, dan max_usage_time
|
||||
|
@ -13,6 +15,10 @@ import {
|
|||
@Injectable()
|
||||
export class IndexPublicTimeGroupManager extends BaseIndexManager<TimeGroupEntity> {
|
||||
async prepareData(): Promise<void> {
|
||||
Object.assign(this.filterParam, {
|
||||
order_by: `${this.tableName}.start_time`,
|
||||
order_type: ORDER_TYPE.ASC,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -60,6 +66,15 @@ export class IndexPublicTimeGroupManager extends BaseIndexManager<TimeGroupEntit
|
|||
queryBuilder: SelectQueryBuilder<TimeGroupEntity>,
|
||||
): SelectQueryBuilder<TimeGroupEntity> {
|
||||
queryBuilder.andWhere(`items.id is not null`);
|
||||
|
||||
if (!this.filterParam.date) {
|
||||
const currentTime = moment().utcOffset('+07:00').format('HH:mm:ss');
|
||||
|
||||
queryBuilder.andWhere(`${this.tableName}.end_time >= :current_time`, {
|
||||
current_time: currentTime,
|
||||
});
|
||||
}
|
||||
|
||||
return queryBuilder;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,4 +30,12 @@ export class FilterTimeGroupDto
|
|||
@ApiProperty({ type: 'string', required: false })
|
||||
@ValidateIf((body) => body.max_usage_time_to)
|
||||
max_usage_time_to: string;
|
||||
|
||||
@ApiProperty({
|
||||
type: Date,
|
||||
required: false,
|
||||
example: '2024-01-01',
|
||||
})
|
||||
@ValidateIf((body) => body.date)
|
||||
date: Date;
|
||||
}
|
||||
|
|
|
@ -56,6 +56,7 @@ export class TicketDataService extends BaseDataService<QueueTicket> {
|
|||
await this.transaction.findOneOrFail({
|
||||
where: {
|
||||
id,
|
||||
booking_date: new Date(),
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ export class QueueOrchestrator {
|
|||
return order;
|
||||
} catch (error) {
|
||||
throw new UnauthorizedException({
|
||||
message: 'Invoice tidak ditemukan',
|
||||
message: 'Invoice tidak ditemukan untuk tanggal hari ini',
|
||||
error: 'INVOICE_NOT_FOUND',
|
||||
});
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ export class GenerateQueueManager {
|
|||
async generate(transaction: TransactionModel) {
|
||||
const date = transaction.booking_date ?? transaction.invoice_date;
|
||||
const queue_date = moment(date, 'YYYY-MM-DD').unix();
|
||||
const isToday = moment(date, 'YYYY-MM-DD').isSame(moment(), 'day');
|
||||
|
||||
const { id, customer_name, customer_phone, invoice_code } = transaction;
|
||||
|
||||
|
@ -40,10 +41,9 @@ export class GenerateQueueManager {
|
|||
|
||||
const items = this.generateItems(transaction.items);
|
||||
|
||||
const existTicket = await this.ticketService.ticketByUser(
|
||||
customer_name,
|
||||
customer_phone,
|
||||
);
|
||||
const existTicket = isToday
|
||||
? await this.ticketService.ticketByUser(customer_name, customer_phone)
|
||||
: null;
|
||||
|
||||
const insertTickets: QueueTicket[] = [];
|
||||
if (customer_name && customer_phone && existTicket) {
|
||||
|
|
|
@ -8,7 +8,7 @@ import {
|
|||
} from 'src/core/strings/constants/base.constants';
|
||||
import { Repository } from 'typeorm';
|
||||
import { BaseReadService } from 'src/core/modules/data/service/base-read.service';
|
||||
import { TransactionPaymentType } from '../../constants';
|
||||
import { TransactionPaymentType, TransactionType } from '../../constants';
|
||||
|
||||
@Injectable()
|
||||
export class TransactionReadService extends BaseReadService<TransactionEntity> {
|
||||
|
@ -24,8 +24,9 @@ export class TransactionReadService extends BaseReadService<TransactionEntity> {
|
|||
where: {
|
||||
status: STATUS.PENDING,
|
||||
payment_type: TransactionPaymentType.MIDTRANS,
|
||||
type: TransactionType.ONLINE,
|
||||
},
|
||||
select: ['id', 'invoice_date'],
|
||||
select: ['id', 'invoice_date', 'created_at', 'booking_date'],
|
||||
});
|
||||
|
||||
return transactions;
|
||||
|
|
|
@ -332,6 +332,8 @@ export class WhatsappService {
|
|||
const momentDate = moment(data.time);
|
||||
const fallbackValue = momentDate.locale('id').format('dddd, DD MMMM YYYY');
|
||||
|
||||
const currentDate = moment().locale('id').format('DD MMMM YYYY');
|
||||
|
||||
const formattedTotal = new Intl.NumberFormat('id-ID', {
|
||||
style: 'currency',
|
||||
currency: 'IDR',
|
||||
|
@ -364,6 +366,11 @@ export class WhatsappService {
|
|||
parameter_name: 'booking_date',
|
||||
text: fallbackValue,
|
||||
},
|
||||
{
|
||||
type: 'text',
|
||||
parameter_name: 'created_date',
|
||||
text: currentDate,
|
||||
},
|
||||
{
|
||||
type: 'text',
|
||||
parameter_name: 'booking_code',
|
||||
|
|
Loading…
Reference in New Issue