Compare commits
18 Commits
1.6.21-alp
...
developmen
Author | SHA1 | Date |
---|---|---|
|
b96d24de1a | |
|
5d3f9d7bff | |
|
831593e743 | |
|
162bd0918f | |
|
13b5838393 | |
|
63bb55b04b | |
|
9d1c240b6b | |
|
83f3377465 | |
|
69c2ee06cf | |
|
42060384aa | |
|
62cfb1f1a8 | |
|
08a35dfdf4 | |
|
8df836ff3e | |
|
822cfe606a | |
|
de43f0f28b | |
|
09b0133bf4 | |
|
a77e6b0381 | |
|
a5da557dd9 |
|
@ -106,6 +106,7 @@ import { OtpVerificationModule } from './modules/configuration/otp-verification/
|
||||||
import { OtpVerificationModel } from './modules/configuration/otp-verification/data/models/otp-verification.model';
|
import { OtpVerificationModel } from './modules/configuration/otp-verification/data/models/otp-verification.model';
|
||||||
import { OtpVerifierModel } from './modules/configuration/otp-verification/data/models/otp-verifier.model';
|
import { OtpVerifierModel } from './modules/configuration/otp-verification/data/models/otp-verifier.model';
|
||||||
import { RescheduleVerificationModel } from './modules/booking-online/order/data/models/reschedule-verification.model';
|
import { RescheduleVerificationModel } from './modules/booking-online/order/data/models/reschedule-verification.model';
|
||||||
|
import { OtpCheckerGuard } from './core/guards/domain/otp-checker.guard';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
@ -246,6 +247,8 @@ import { RescheduleVerificationModel } from './modules/booking-online/order/data
|
||||||
providers: [
|
providers: [
|
||||||
AuthService,
|
AuthService,
|
||||||
PrivilegeService,
|
PrivilegeService,
|
||||||
|
OtpCheckerGuard,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* By default all request from client will protect by JWT
|
* By default all request from client will protect by JWT
|
||||||
* if there is some endpoint/function that does'nt require authentication
|
* if there is some endpoint/function that does'nt require authentication
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
import {
|
||||||
|
CanActivate,
|
||||||
|
ExecutionContext,
|
||||||
|
Injectable,
|
||||||
|
UnprocessableEntityException,
|
||||||
|
} from '@nestjs/common';
|
||||||
|
import { InjectDataSource } from '@nestjs/typeorm';
|
||||||
|
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||||
|
import { OtpVerificationModel } from 'src/modules/configuration/otp-verification/data/models/otp-verification.model';
|
||||||
|
import { OtpVerificationEntity } from 'src/modules/configuration/otp-verification/domain/entities/otp-verification.entity';
|
||||||
|
import { DataSource } from 'typeorm';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class OtpCheckerGuard implements CanActivate {
|
||||||
|
constructor(
|
||||||
|
@InjectDataSource(CONNECTION_NAME.DEFAULT)
|
||||||
|
protected readonly dataSource: DataSource,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
get otpRepository() {
|
||||||
|
return this.dataSource.getRepository(OtpVerificationModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
async canActivate(context: ExecutionContext): Promise<boolean> {
|
||||||
|
const request = context.switchToHttp().getRequest();
|
||||||
|
const verificationCode = request.headers['x-verification-code'];
|
||||||
|
console.log({ verificationCode });
|
||||||
|
|
||||||
|
if (verificationCode) {
|
||||||
|
const decoded = Buffer.from(verificationCode, 'base64').toString('ascii');
|
||||||
|
const [dataIdentity, otpCode] = decoded.split('|');
|
||||||
|
|
||||||
|
let otpData: OtpVerificationEntity;
|
||||||
|
|
||||||
|
otpData = await this.otpRepository.findOne({
|
||||||
|
where: {
|
||||||
|
otp_code: otpCode,
|
||||||
|
target_id: dataIdentity,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!otpData) {
|
||||||
|
otpData = await this.otpRepository.findOne({
|
||||||
|
where: {
|
||||||
|
otp_code: otpCode,
|
||||||
|
reference: dataIdentity,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.log({ dataIdentity, otpCode, otpData });
|
||||||
|
if (otpData && otpData?.verified_at) return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new UnprocessableEntityException('OTP not verified.');
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||||
|
|
||||||
|
export class AddUsageTypeToItem1750319148269 implements MigrationInterface {
|
||||||
|
name = 'AddUsageTypeToItem1750319148269';
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`CREATE TYPE "public"."item_queues_usage_type_enum" AS ENUM('one_time', 'multiple')`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "item_queues" ADD "usage_type" "public"."item_queues_usage_type_enum" NOT NULL DEFAULT 'one_time'`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`CREATE TYPE "public"."items_usage_type_enum" AS ENUM('one_time', 'multiple')`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "items" ADD "usage_type" "public"."items_usage_type_enum" NOT NULL DEFAULT 'one_time'`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`ALTER TABLE "items" DROP COLUMN "usage_type"`);
|
||||||
|
await queryRunner.query(`DROP TYPE "public"."items_usage_type_enum"`);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "item_queues" DROP COLUMN "usage_type"`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(`DROP TYPE "public"."item_queues_usage_type_enum"`);
|
||||||
|
}
|
||||||
|
}
|
|
@ -42,8 +42,11 @@ export class BookingItemManager extends IndexItemManager {
|
||||||
const { data, total } = result;
|
const { data, total } = result;
|
||||||
const hasRates = (this.filterParam.season_period_ids?.length ?? 0) > 0;
|
const hasRates = (this.filterParam.season_period_ids?.length ?? 0) > 0;
|
||||||
const items = data.map((item) => {
|
const items = data.map((item) => {
|
||||||
|
const currentRate = item.item_rates.find((rate) =>
|
||||||
|
this.filterParam.season_period_ids?.includes(rate.season_period_id),
|
||||||
|
);
|
||||||
const { item_rates, ...rest } = item;
|
const { item_rates, ...rest } = item;
|
||||||
const rate = item_rates?.[0]?.['price'] ?? rest.base_price;
|
const rate = currentRate?.['price'] ?? rest.base_price;
|
||||||
return {
|
return {
|
||||||
...rest,
|
...rest,
|
||||||
base_price: hasRates ? rate : rest.base_price,
|
base_price: hasRates ? rate : rest.base_price,
|
||||||
|
@ -57,11 +60,8 @@ export class BookingItemManager extends IndexItemManager {
|
||||||
): SelectQueryBuilder<ItemEntity> {
|
): SelectQueryBuilder<ItemEntity> {
|
||||||
const query = super.setQueryFilter(queryBuilder);
|
const query = super.setQueryFilter(queryBuilder);
|
||||||
|
|
||||||
if (this.filterParam.season_period_ids) {
|
query.andWhere(`${this.tableName}.status = 'active'`);
|
||||||
query.andWhere(`item_rates.season_period_id In (:...seasonIds)`, {
|
|
||||||
seasonIds: this.filterParam.season_period_ids,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ export class ItemController {
|
||||||
): Promise<PaginationResponse<ItemEntity>> {
|
): Promise<PaginationResponse<ItemEntity>> {
|
||||||
params.limit = 1000;
|
params.limit = 1000;
|
||||||
params.show_to_booking = true;
|
params.show_to_booking = true;
|
||||||
|
params.all_item = true;
|
||||||
this.indexManager.setFilterParam(params);
|
this.indexManager.setFilterParam(params);
|
||||||
this.indexManager.setService(this.serviceData, TABLE_NAME.ITEM);
|
this.indexManager.setService(this.serviceData, TABLE_NAME.ITEM);
|
||||||
await this.indexManager.execute();
|
await this.indexManager.execute();
|
||||||
|
|
|
@ -16,7 +16,7 @@ import {
|
||||||
OtpVerifierCreateDto,
|
OtpVerifierCreateDto,
|
||||||
OtpVerifyDto,
|
OtpVerifyDto,
|
||||||
} from './dto/otp-verification.dto';
|
} from './dto/otp-verification.dto';
|
||||||
import { OtpAuthGuard } from './guards/otp-auth-guard';
|
import { OtpAuthGuard } from './guards/otp-auth.guard';
|
||||||
import { OtpVerifierService } from '../data/services/otp-verifier.service';
|
import { OtpVerifierService } from '../data/services/otp-verifier.service';
|
||||||
|
|
||||||
@ApiTags(`${MODULE_NAME.OTP_VERIFICATIONS.split('-').join(' ')} - data`)
|
@ApiTags(`${MODULE_NAME.OTP_VERIFICATIONS.split('-').join(' ')} - data`)
|
||||||
|
|
|
@ -10,7 +10,7 @@ import {
|
||||||
} from './infrastructure/otp-verification-data.controller';
|
} from './infrastructure/otp-verification-data.controller';
|
||||||
import { OtpVerificationService } from './data/services/otp-verification.service';
|
import { OtpVerificationService } from './data/services/otp-verification.service';
|
||||||
import { OtpVerifierModel } from './data/models/otp-verifier.model';
|
import { OtpVerifierModel } from './data/models/otp-verifier.model';
|
||||||
import { OtpAuthGuard } from './infrastructure/guards/otp-auth-guard';
|
import { OtpAuthGuard } from './infrastructure/guards/otp-auth.guard';
|
||||||
|
|
||||||
import { JwtModule } from '@nestjs/jwt';
|
import { JwtModule } from '@nestjs/jwt';
|
||||||
import { JWT_EXPIRED } from 'src/core/sessions/constants';
|
import { JWT_EXPIRED } from 'src/core/sessions/constants';
|
||||||
|
|
|
@ -5,3 +5,8 @@ export enum ItemType {
|
||||||
FREE_GIFT = 'free gift',
|
FREE_GIFT = 'free gift',
|
||||||
OTHER = 'other',
|
OTHER = 'other',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum UsageType {
|
||||||
|
ONE_TIME = 'one_time',
|
||||||
|
MULTIPLE = 'multiple',
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
import { ItemQueueEntity } from '../../domain/entities/item-queue.entity';
|
import { ItemQueueEntity } from '../../domain/entities/item-queue.entity';
|
||||||
import { Column, Entity, OneToMany } from 'typeorm';
|
import { Column, Entity, OneToMany } from 'typeorm';
|
||||||
import { BaseStatusModel } from 'src/core/modules/data/model/base-status.model';
|
import { BaseStatusModel } from 'src/core/modules/data/model/base-status.model';
|
||||||
import { ItemType } from '../../constants';
|
import { ItemType, UsageType } from '../../constants';
|
||||||
import { ItemModel } from 'src/modules/item-related/item/data/models/item.model';
|
import { ItemModel } from 'src/modules/item-related/item/data/models/item.model';
|
||||||
|
|
||||||
@Entity(TABLE_NAME.ITEM_QUEUE)
|
@Entity(TABLE_NAME.ITEM_QUEUE)
|
||||||
|
@ -29,6 +29,13 @@ export class ItemQueueModel
|
||||||
})
|
})
|
||||||
item_type: ItemType;
|
item_type: ItemType;
|
||||||
|
|
||||||
|
@Column('enum', {
|
||||||
|
name: 'usage_type',
|
||||||
|
enum: UsageType,
|
||||||
|
default: UsageType.ONE_TIME,
|
||||||
|
})
|
||||||
|
usage_type: UsageType;
|
||||||
|
|
||||||
@OneToMany(() => ItemModel, (model) => model.item_queue, {
|
@OneToMany(() => ItemModel, (model) => model.item_queue, {
|
||||||
onUpdate: 'CASCADE',
|
onUpdate: 'CASCADE',
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { BaseStatusEntity } from 'src/core/modules/domain/entities/base-status.entity';
|
import { BaseStatusEntity } from 'src/core/modules/domain/entities/base-status.entity';
|
||||||
import { ItemType } from '../../constants';
|
import { ItemType, UsageType } from '../../constants';
|
||||||
import { ItemEntity } from 'src/modules/item-related/item/domain/entities/item.entity';
|
import { ItemEntity } from 'src/modules/item-related/item/domain/entities/item.entity';
|
||||||
|
|
||||||
export interface ItemQueueEntity extends BaseStatusEntity {
|
export interface ItemQueueEntity extends BaseStatusEntity {
|
||||||
|
@ -11,4 +11,5 @@ export interface ItemQueueEntity extends BaseStatusEntity {
|
||||||
items: ItemEntity[];
|
items: ItemEntity[];
|
||||||
use_notification?: boolean;
|
use_notification?: boolean;
|
||||||
requiring_notification?: boolean;
|
requiring_notification?: boolean;
|
||||||
|
usage_type?: UsageType;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ export class DetailItemQueueManager extends BaseDetailManager<ItemQueueEntity> {
|
||||||
`${this.tableName}.call_preparation`,
|
`${this.tableName}.call_preparation`,
|
||||||
`${this.tableName}.use_notification`,
|
`${this.tableName}.use_notification`,
|
||||||
`${this.tableName}.requiring_notification`,
|
`${this.tableName}.requiring_notification`,
|
||||||
|
`${this.tableName}.usage_type`,
|
||||||
|
|
||||||
`items.id`,
|
`items.id`,
|
||||||
`items.created_at`,
|
`items.created_at`,
|
||||||
|
|
|
@ -43,7 +43,7 @@ export class IndexItemQueueManager extends BaseIndexManager<ItemQueueEntity> {
|
||||||
`${this.tableName}.call_preparation`,
|
`${this.tableName}.call_preparation`,
|
||||||
`${this.tableName}.use_notification`,
|
`${this.tableName}.use_notification`,
|
||||||
`${this.tableName}.requiring_notification`,
|
`${this.tableName}.requiring_notification`,
|
||||||
|
`${this.tableName}.usage_type`,
|
||||||
`items.id`,
|
`items.id`,
|
||||||
`items.created_at`,
|
`items.created_at`,
|
||||||
`items.status`,
|
`items.status`,
|
||||||
|
|
|
@ -18,6 +18,7 @@ import { ItemRateModel } from 'src/modules/item-related/item-rate/data/models/it
|
||||||
import { GateModel } from 'src/modules/web-information/gate/data/models/gate.model';
|
import { GateModel } from 'src/modules/web-information/gate/data/models/gate.model';
|
||||||
import { ItemQueueModel } from 'src/modules/item-related/item-queue/data/models/item-queue.model';
|
import { ItemQueueModel } from 'src/modules/item-related/item-queue/data/models/item-queue.model';
|
||||||
import { TimeGroupModel } from 'src/modules/item-related/time-group/data/models/time-group.model';
|
import { TimeGroupModel } from 'src/modules/item-related/time-group/data/models/time-group.model';
|
||||||
|
import { UsageType } from 'src/modules/item-related/item-queue/constants';
|
||||||
|
|
||||||
@Entity(TABLE_NAME.ITEM)
|
@Entity(TABLE_NAME.ITEM)
|
||||||
export class ItemModel
|
export class ItemModel
|
||||||
|
@ -43,6 +44,13 @@ export class ItemModel
|
||||||
})
|
})
|
||||||
item_type: ItemType;
|
item_type: ItemType;
|
||||||
|
|
||||||
|
@Column('enum', {
|
||||||
|
name: 'usage_type',
|
||||||
|
enum: UsageType,
|
||||||
|
default: UsageType.ONE_TIME,
|
||||||
|
})
|
||||||
|
usage_type: UsageType;
|
||||||
|
|
||||||
@Column('bigint', { name: 'hpp', nullable: true })
|
@Column('bigint', { name: 'hpp', nullable: true })
|
||||||
hpp: number;
|
hpp: number;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { BaseStatusEntity } from 'src/core/modules/domain/entities/base-status.e
|
||||||
import { ItemType } from 'src/modules/item-related/item-category/constants';
|
import { ItemType } from 'src/modules/item-related/item-category/constants';
|
||||||
import { LimitType } from '../../constants';
|
import { LimitType } from '../../constants';
|
||||||
import { ItemRateEntity } from 'src/modules/item-related/item-rate/domain/entities/item-rate.entity';
|
import { ItemRateEntity } from 'src/modules/item-related/item-rate/domain/entities/item-rate.entity';
|
||||||
|
import { UsageType } from 'src/modules/item-related/item-queue/constants';
|
||||||
export interface ItemEntity extends BaseStatusEntity {
|
export interface ItemEntity extends BaseStatusEntity {
|
||||||
name: string;
|
name: string;
|
||||||
item_type: ItemType;
|
item_type: ItemType;
|
||||||
|
@ -20,6 +20,7 @@ export interface ItemEntity extends BaseStatusEntity {
|
||||||
show_to_booking: boolean;
|
show_to_booking: boolean;
|
||||||
breakdown_bundling?: boolean;
|
breakdown_bundling?: boolean;
|
||||||
booking_description?: string;
|
booking_description?: string;
|
||||||
|
usage_type?: UsageType;
|
||||||
|
|
||||||
item_rates?: ItemRateEntity[] | any[];
|
item_rates?: ItemRateEntity[] | any[];
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,7 @@ export class DetailItemManager extends BaseDetailManager<ItemEntity> {
|
||||||
`${this.tableName}.total_price`,
|
`${this.tableName}.total_price`,
|
||||||
`${this.tableName}.base_price`,
|
`${this.tableName}.base_price`,
|
||||||
`${this.tableName}.use_queue`,
|
`${this.tableName}.use_queue`,
|
||||||
|
`${this.tableName}.usage_type`,
|
||||||
`${this.tableName}.show_to_booking`,
|
`${this.tableName}.show_to_booking`,
|
||||||
`${this.tableName}.breakdown_bundling`,
|
`${this.tableName}.breakdown_bundling`,
|
||||||
`${this.tableName}.play_estimation`,
|
`${this.tableName}.play_estimation`,
|
||||||
|
|
|
@ -55,6 +55,7 @@ export class IndexItemManager extends BaseIndexManager<ItemEntity> {
|
||||||
`${this.tableName}.play_estimation`,
|
`${this.tableName}.play_estimation`,
|
||||||
`${this.tableName}.show_to_booking`,
|
`${this.tableName}.show_to_booking`,
|
||||||
`${this.tableName}.booking_description`,
|
`${this.tableName}.booking_description`,
|
||||||
|
`${this.tableName}.usage_type`,
|
||||||
|
|
||||||
`item_category.id`,
|
`item_category.id`,
|
||||||
`item_category.name`,
|
`item_category.name`,
|
||||||
|
|
|
@ -6,6 +6,7 @@ import {
|
||||||
Patch,
|
Patch,
|
||||||
Post,
|
Post,
|
||||||
Put,
|
Put,
|
||||||
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ItemDataOrchestrator } from '../domain/usecases/item-data.orchestrator';
|
import { ItemDataOrchestrator } from '../domain/usecases/item-data.orchestrator';
|
||||||
import { ItemDto } from './dto/item.dto';
|
import { ItemDto } from './dto/item.dto';
|
||||||
|
@ -16,6 +17,7 @@ import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||||
import { BatchIdsDto } from 'src/core/modules/infrastructure/dto/base-batch.dto';
|
import { BatchIdsDto } from 'src/core/modules/infrastructure/dto/base-batch.dto';
|
||||||
import { Public } from 'src/core/guards';
|
import { Public } from 'src/core/guards';
|
||||||
import { UpdateItemPriceDto } from './dto/update-item-price.dto';
|
import { UpdateItemPriceDto } from './dto/update-item-price.dto';
|
||||||
|
import { OtpCheckerGuard } from 'src/core/guards/domain/otp-checker.guard';
|
||||||
|
|
||||||
@ApiTags(`${MODULE_NAME.ITEM.split('-').join(' ')} - data`)
|
@ApiTags(`${MODULE_NAME.ITEM.split('-').join(' ')} - data`)
|
||||||
@Controller(`v1/${MODULE_NAME.ITEM}`)
|
@Controller(`v1/${MODULE_NAME.ITEM}`)
|
||||||
|
@ -41,19 +43,18 @@ export class ItemDataController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':id/active')
|
@Patch(':id/active')
|
||||||
// TODO => simpan OTP update yang disikim dari request ini
|
@UseGuards(OtpCheckerGuard)
|
||||||
async active(@Param('id') dataId: string): Promise<string> {
|
async active(@Param('id') dataId: string): Promise<string> {
|
||||||
return await this.orchestrator.active(dataId);
|
return await this.orchestrator.active(dataId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put('/batch-active')
|
@Put('/batch-active')
|
||||||
// TODO => simpan OTP update yang disikim dari request ini
|
|
||||||
async batchActive(@Body() body: BatchIdsDto): Promise<BatchResult> {
|
async batchActive(@Body() body: BatchIdsDto): Promise<BatchResult> {
|
||||||
return await this.orchestrator.batchActive(body.ids);
|
return await this.orchestrator.batchActive(body.ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':id/confirm')
|
@Patch(':id/confirm')
|
||||||
// TODO => simpan OTP update yang disikim dari request ini
|
@UseGuards(OtpCheckerGuard)
|
||||||
async confirm(@Param('id') dataId: string): Promise<string> {
|
async confirm(@Param('id') dataId: string): Promise<string> {
|
||||||
return await this.orchestrator.confirm(dataId);
|
return await this.orchestrator.confirm(dataId);
|
||||||
}
|
}
|
||||||
|
@ -74,7 +75,7 @@ export class ItemDataController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put(':id')
|
@Put(':id')
|
||||||
// TODO => simpan OTP update yang disikim dari request ini
|
@UseGuards(OtpCheckerGuard)
|
||||||
async update(
|
async update(
|
||||||
@Param('id') dataId: string,
|
@Param('id') dataId: string,
|
||||||
@Body() data: ItemDto,
|
@Body() data: ItemDto,
|
||||||
|
|
|
@ -6,6 +6,7 @@ import {
|
||||||
Patch,
|
Patch,
|
||||||
Post,
|
Post,
|
||||||
Put,
|
Put,
|
||||||
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { SeasonPeriodDataOrchestrator } from '../domain/usecases/season-period-data.orchestrator';
|
import { SeasonPeriodDataOrchestrator } from '../domain/usecases/season-period-data.orchestrator';
|
||||||
import { SeasonPeriodDto } from './dto/season-period.dto';
|
import { SeasonPeriodDto } from './dto/season-period.dto';
|
||||||
|
@ -18,6 +19,7 @@ import { Public } from 'src/core/guards';
|
||||||
import { UpdateSeasonPeriodDto } from './dto/update-season-period.dto';
|
import { UpdateSeasonPeriodDto } from './dto/update-season-period.dto';
|
||||||
import { UpdateSeasonPeriodItemDto } from './dto/update-season-period-item.dto';
|
import { UpdateSeasonPeriodItemDto } from './dto/update-season-period-item.dto';
|
||||||
import { UpdateSeasonPriceDto } from './dto/update-season-price.dto';
|
import { UpdateSeasonPriceDto } from './dto/update-season-price.dto';
|
||||||
|
import { OtpCheckerGuard } from 'src/core/guards/domain/otp-checker.guard';
|
||||||
|
|
||||||
@ApiTags(`${MODULE_NAME.SEASON_PERIOD.split('-').join(' ')} - data`)
|
@ApiTags(`${MODULE_NAME.SEASON_PERIOD.split('-').join(' ')} - data`)
|
||||||
@Controller(`v1/${MODULE_NAME.SEASON_PERIOD}`)
|
@Controller(`v1/${MODULE_NAME.SEASON_PERIOD}`)
|
||||||
|
@ -27,11 +29,13 @@ export class SeasonPeriodDataController {
|
||||||
constructor(private orchestrator: SeasonPeriodDataOrchestrator) {}
|
constructor(private orchestrator: SeasonPeriodDataOrchestrator) {}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
|
@UseGuards(OtpCheckerGuard)
|
||||||
async create(@Body() data: SeasonPeriodDto): Promise<SeasonPeriodEntity> {
|
async create(@Body() data: SeasonPeriodDto): Promise<SeasonPeriodEntity> {
|
||||||
return await this.orchestrator.create(data);
|
return await this.orchestrator.create(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('/update-price')
|
@Post('/update-price')
|
||||||
|
@UseGuards(OtpCheckerGuard)
|
||||||
async updatePrice(@Body() body: UpdateSeasonPriceDto): Promise<BatchResult> {
|
async updatePrice(@Body() body: UpdateSeasonPriceDto): Promise<BatchResult> {
|
||||||
return await this.orchestrator.updatePrice(body);
|
return await this.orchestrator.updatePrice(body);
|
||||||
}
|
}
|
||||||
|
@ -82,6 +86,7 @@ export class SeasonPeriodDataController {
|
||||||
// pemisahan update data dengan update items dikarenakan payload (based on tampilan) berbeda
|
// pemisahan update data dengan update items dikarenakan payload (based on tampilan) berbeda
|
||||||
// TODO => simpan OTP update yang disikim dari request ini
|
// TODO => simpan OTP update yang disikim dari request ini
|
||||||
@Put(':id/items')
|
@Put(':id/items')
|
||||||
|
@UseGuards(OtpCheckerGuard)
|
||||||
async updateItems(
|
async updateItems(
|
||||||
@Param('id') dataId: string,
|
@Param('id') dataId: string,
|
||||||
@Body() data: UpdateSeasonPeriodItemDto,
|
@Body() data: UpdateSeasonPeriodItemDto,
|
||||||
|
|
|
@ -31,6 +31,10 @@ export class DetailRefundManager extends BaseDetailManager<RefundEntity> {
|
||||||
'items.bundling_items',
|
'items.bundling_items',
|
||||||
'items.refunds item_refunds',
|
'items.refunds item_refunds',
|
||||||
'item_refunds.refund item_refunds_refund',
|
'item_refunds.refund item_refunds_refund',
|
||||||
|
|
||||||
|
'transaction.items transaction_items',
|
||||||
|
'transaction_items.item transaction_items_item',
|
||||||
|
'transaction_items_item.time_group transaction_items_item_time_group',
|
||||||
],
|
],
|
||||||
|
|
||||||
// relation yang hanya ingin dihitung (akan return number)
|
// relation yang hanya ingin dihitung (akan return number)
|
||||||
|
@ -65,6 +69,10 @@ export class DetailRefundManager extends BaseDetailManager<RefundEntity> {
|
||||||
'item_refunds',
|
'item_refunds',
|
||||||
'item_refunds_refund.id',
|
'item_refunds_refund.id',
|
||||||
'item_refunds_refund.status',
|
'item_refunds_refund.status',
|
||||||
|
|
||||||
|
'transaction_items',
|
||||||
|
'transaction_items_item',
|
||||||
|
'transaction_items_item_time_group',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,6 +77,22 @@ export class MidtransCallbackHandler
|
||||||
await whatsappService.bookingCreated(payload);
|
await whatsappService.bookingCreated(payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
transaction.status === STATUS.EXPIRED &&
|
||||||
|
transaction.type === TransactionType.ONLINE
|
||||||
|
) {
|
||||||
|
const whatsappService = new WhatsappService();
|
||||||
|
const formattedDate = moment(transaction.booking_date);
|
||||||
|
const payload = {
|
||||||
|
id: transaction.id,
|
||||||
|
phone: transaction.customer_phone,
|
||||||
|
code: transaction.invoice_code,
|
||||||
|
name: transaction.customer_name,
|
||||||
|
time: formattedDate.valueOf(),
|
||||||
|
};
|
||||||
|
await whatsappService.bookingExpired(payload);
|
||||||
|
}
|
||||||
|
|
||||||
this.eventBus.publish(
|
this.eventBus.publish(
|
||||||
new TransactionChangeStatusEvent({
|
new TransactionChangeStatusEvent({
|
||||||
id: data_id,
|
id: data_id,
|
||||||
|
|
|
@ -31,6 +31,9 @@ export class DetailTransactionManager extends BaseDetailManager<TransactionEntit
|
||||||
'items.refunds item_refunds',
|
'items.refunds item_refunds',
|
||||||
'item_refunds.refund item_refunds_refund',
|
'item_refunds.refund item_refunds_refund',
|
||||||
'refunds',
|
'refunds',
|
||||||
|
|
||||||
|
'items.item items_item',
|
||||||
|
'items_item.time_group items_item_time_group',
|
||||||
],
|
],
|
||||||
|
|
||||||
// relation yang hanya ingin dihitung (akan return number)
|
// relation yang hanya ingin dihitung (akan return number)
|
||||||
|
@ -92,6 +95,8 @@ export class DetailTransactionManager extends BaseDetailManager<TransactionEntit
|
||||||
'item_refunds_refund.status',
|
'item_refunds_refund.status',
|
||||||
|
|
||||||
'refunds',
|
'refunds',
|
||||||
|
'items_item',
|
||||||
|
'items_item_time_group',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,8 @@ export function mappingTransaction(data, refundId?: string) {
|
||||||
if (refundId)
|
if (refundId)
|
||||||
refund = itemData.refunds?.find((item) => item.refund.id == refundId);
|
refund = itemData.refunds?.find((item) => item.refund.id == refundId);
|
||||||
|
|
||||||
|
const timeGroup = itemData?.item?.time_group;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
item: {
|
item: {
|
||||||
id: itemData.item_id,
|
id: itemData.item_id,
|
||||||
|
@ -57,6 +59,7 @@ export function mappingTransaction(data, refundId?: string) {
|
||||||
},
|
},
|
||||||
breakdown_bundling: itemData.breakdown_bundling,
|
breakdown_bundling: itemData.breakdown_bundling,
|
||||||
bundling_items: itemData.bundling_items,
|
bundling_items: itemData.bundling_items,
|
||||||
|
time_group: timeGroup,
|
||||||
},
|
},
|
||||||
id: itemData.id,
|
id: itemData.id,
|
||||||
refund: refund,
|
refund: refund,
|
||||||
|
|
|
@ -20,7 +20,8 @@ import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||||
import { BatchIdsDto } from 'src/core/modules/infrastructure/dto/base-batch.dto';
|
import { BatchIdsDto } from 'src/core/modules/infrastructure/dto/base-batch.dto';
|
||||||
import { Public } from 'src/core/guards';
|
import { Public } from 'src/core/guards';
|
||||||
import { DownloadPdfDto } from './dto/donwload-pdf.dto';
|
import { DownloadPdfDto } from './dto/donwload-pdf.dto';
|
||||||
import { OtpAuthGuard } from 'src/modules/configuration/otp-verification/infrastructure/guards/otp-auth-guard';
|
import { OtpAuthGuard } from 'src/modules/configuration/otp-verification/infrastructure/guards/otp-auth.guard';
|
||||||
|
import { OtpCheckerGuard } from 'src/core/guards/domain/otp-checker.guard';
|
||||||
|
|
||||||
@ApiTags(`${MODULE_NAME.TRANSACTION.split('-').join(' ')} - data`)
|
@ApiTags(`${MODULE_NAME.TRANSACTION.split('-').join(' ')} - data`)
|
||||||
@Controller(`v1/${MODULE_NAME.TRANSACTION}`)
|
@Controller(`v1/${MODULE_NAME.TRANSACTION}`)
|
||||||
|
@ -53,6 +54,7 @@ export class TransactionDataController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':id/confirm-data')
|
@Patch(':id/confirm-data')
|
||||||
|
@UseGuards(OtpCheckerGuard)
|
||||||
async confirmData(@Param('id') dataId: string): Promise<string> {
|
async confirmData(@Param('id') dataId: string): Promise<string> {
|
||||||
return await this.orchestrator.confirmData(dataId);
|
return await this.orchestrator.confirmData(dataId);
|
||||||
}
|
}
|
||||||
|
@ -63,6 +65,7 @@ export class TransactionDataController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':id/confirm')
|
@Patch(':id/confirm')
|
||||||
|
@UseGuards(OtpCheckerGuard)
|
||||||
async confirm(@Param('id') dataId: string): Promise<string> {
|
async confirm(@Param('id') dataId: string): Promise<string> {
|
||||||
return await this.orchestrator.confirm(dataId);
|
return await this.orchestrator.confirm(dataId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import {
|
||||||
Patch,
|
Patch,
|
||||||
Post,
|
Post,
|
||||||
Put,
|
Put,
|
||||||
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { UserDataOrchestrator } from '../domain/usecases/user-data.orchestrator';
|
import { UserDataOrchestrator } from '../domain/usecases/user-data.orchestrator';
|
||||||
import { UserDto } from './dto/user.dto';
|
import { UserDto } from './dto/user.dto';
|
||||||
|
@ -17,6 +18,7 @@ import { BatchIdsDto } from 'src/core/modules/infrastructure/dto/base-batch.dto'
|
||||||
import { Public } from 'src/core/guards';
|
import { Public } from 'src/core/guards';
|
||||||
import { UpdateUserDto } from './dto/update-user.dto';
|
import { UpdateUserDto } from './dto/update-user.dto';
|
||||||
import { UpdatePasswordUserDto } from './dto/update-password-user.dto';
|
import { UpdatePasswordUserDto } from './dto/update-password-user.dto';
|
||||||
|
import { OtpCheckerGuard } from 'src/core/guards/domain/otp-checker.guard';
|
||||||
|
|
||||||
@ApiTags(`${MODULE_NAME.USER.split('-').join(' ')} - data`)
|
@ApiTags(`${MODULE_NAME.USER.split('-').join(' ')} - data`)
|
||||||
@Controller(`v1/${MODULE_NAME.USER}`)
|
@Controller(`v1/${MODULE_NAME.USER}`)
|
||||||
|
@ -36,25 +38,23 @@ export class UserDataController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':id/active')
|
@Patch(':id/active')
|
||||||
// TODO => simpan OTP update yang disikim dari request ini
|
@UseGuards(OtpCheckerGuard)
|
||||||
async active(@Param('id') dataId: string): Promise<string> {
|
async active(@Param('id') dataId: string): Promise<string> {
|
||||||
return await this.orchestrator.active(dataId);
|
return await this.orchestrator.active(dataId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put('/batch-active')
|
@Put('/batch-active')
|
||||||
// TODO => simpan OTP update yang disikim dari request ini
|
|
||||||
async batchActive(@Body() body: BatchIdsDto): Promise<BatchResult> {
|
async batchActive(@Body() body: BatchIdsDto): Promise<BatchResult> {
|
||||||
return await this.orchestrator.batchActive(body.ids);
|
return await this.orchestrator.batchActive(body.ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':id/confirm')
|
@Patch(':id/confirm')
|
||||||
// TODO => simpan OTP update yang disikim dari request ini
|
@UseGuards(OtpCheckerGuard)
|
||||||
async confirm(@Param('id') dataId: string): Promise<string> {
|
async confirm(@Param('id') dataId: string): Promise<string> {
|
||||||
return await this.orchestrator.confirm(dataId);
|
return await this.orchestrator.confirm(dataId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put('/batch-confirm')
|
@Put('/batch-confirm')
|
||||||
// TODO => simpan OTP update yang disikim dari request ini
|
|
||||||
async batchConfirm(@Body() body: BatchIdsDto): Promise<BatchResult> {
|
async batchConfirm(@Body() body: BatchIdsDto): Promise<BatchResult> {
|
||||||
return await this.orchestrator.batchConfirm(body.ids);
|
return await this.orchestrator.batchConfirm(body.ids);
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,6 +198,57 @@ export class WhatsappService {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async bookingExpired(data: WhatsappBookingCreate) {
|
||||||
|
const momentDate = moment(data.time);
|
||||||
|
const fallbackValue = momentDate.locale('id').format('dddd, DD MMMM YYYY');
|
||||||
|
// const dayOfWeek = momentDate.day();
|
||||||
|
// const dayOfMonth = momentDate.date();
|
||||||
|
// const year = momentDate.year();
|
||||||
|
// const month = momentDate.month() + 1;
|
||||||
|
// const hour = momentDate.hour();
|
||||||
|
// const minute = momentDate.minute();
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
messaging_product: 'whatsapp',
|
||||||
|
to: phoneNumberOnly(data.phone), // recipient's phone number
|
||||||
|
type: 'template',
|
||||||
|
template: {
|
||||||
|
name: 'booking_expired',
|
||||||
|
language: {
|
||||||
|
code: 'id', // language code
|
||||||
|
},
|
||||||
|
components: [
|
||||||
|
{
|
||||||
|
type: 'body',
|
||||||
|
parameters: [
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
parameter_name: 'customer',
|
||||||
|
text: data.name, // replace with name variable
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
parameter_name: 'code',
|
||||||
|
text: data.code, // replace with queue_code variable
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
parameter_name: 'booking_date',
|
||||||
|
text: fallbackValue,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await this.sendMessage(payload);
|
||||||
|
if (response)
|
||||||
|
Logger.log(
|
||||||
|
`Notification register Booking for ${data.code} send to ${data.phone}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async rescheduleCreated(data: WhatsappBookingCreate) {
|
async rescheduleCreated(data: WhatsappBookingCreate) {
|
||||||
const imageUrl = `${BOOKING_QR_URL}${data.id}`;
|
const imageUrl = `${BOOKING_QR_URL}${data.id}`;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue