add whatsapp modules
This commit is contained in:
@@ -9,9 +9,11 @@ import type {
|
||||
ListResponse,
|
||||
SingleResponse,
|
||||
} from "@/common/types";
|
||||
import { generateRandomCode } from "@/common/utils";
|
||||
import { FlightClass } from "@/database/entities/flight-class.entity";
|
||||
import { FlightSchedule } from "@/database/entities/flight-schedule.entity";
|
||||
import { Hotel } from "@/database/entities/hotel.entity";
|
||||
import { PackageConsultSession } from "@/database/entities/package-consult-session.entity";
|
||||
import { PackageDetail } from "@/database/entities/package-detail.entity";
|
||||
import { PackageItineraryDay } from "@/database/entities/package-itinerary-day.entity";
|
||||
import { PackageItineraryImage } from "@/database/entities/package-itinerary-image.entity";
|
||||
@@ -35,6 +37,7 @@ import {
|
||||
packageRequestSchema,
|
||||
} from "@/modules/package/package.schemas";
|
||||
import type {
|
||||
PackageConsultResponse,
|
||||
PackageDetailResponse,
|
||||
PackageResponse,
|
||||
} from "@/modules/package/package.types";
|
||||
@@ -98,6 +101,47 @@ export class PackageController extends Controller {
|
||||
} satisfies SingleResponse<PackageResponse>);
|
||||
}
|
||||
|
||||
async consult(req: Request, res: Response) {
|
||||
const parseParamsResult = packageParamsSchema.safeParse(req.params);
|
||||
if (!parseParamsResult.success) {
|
||||
return this.handleZodError(parseParamsResult.error, res, "params");
|
||||
}
|
||||
const params = parseParamsResult.data;
|
||||
|
||||
const package_ = await orm.em.findOne(
|
||||
Package,
|
||||
{ id: params.id },
|
||||
{ populate: ["*"] },
|
||||
);
|
||||
if (!package_) {
|
||||
return res.status(404).json({
|
||||
data: null,
|
||||
errors: [
|
||||
{
|
||||
path: "id",
|
||||
location: "params",
|
||||
message: "Package not found.",
|
||||
},
|
||||
],
|
||||
} satisfies ErrorResponse);
|
||||
}
|
||||
|
||||
const consultSession = orm.em.create(PackageConsultSession, {
|
||||
id: ulid(),
|
||||
code: generateRandomCode(6, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"),
|
||||
package: package_,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
});
|
||||
|
||||
return res.status(200).json({
|
||||
data: {
|
||||
session_code: consultSession.code,
|
||||
},
|
||||
errors: null,
|
||||
} satisfies SingleResponse<PackageConsultResponse>);
|
||||
}
|
||||
|
||||
async list(req: Request, res: Response) {
|
||||
const parseQueryResult = paginationQuerySchema.safeParse(req.query);
|
||||
if (!parseQueryResult.success) {
|
||||
@@ -1325,6 +1369,11 @@ export class PackageController extends Controller {
|
||||
isAdminMiddleware(this.jwtService, [AdminPermission.createPackage]),
|
||||
this.create.bind(this),
|
||||
);
|
||||
router.post(
|
||||
"/:id/consult",
|
||||
createOrmContextMiddleware,
|
||||
this.consult.bind(this),
|
||||
);
|
||||
router.get("/", createOrmContextMiddleware, this.list.bind(this));
|
||||
router.get("/:id", createOrmContextMiddleware, this.view.bind(this));
|
||||
router.put(
|
||||
|
||||
@@ -33,6 +33,10 @@ export type PackageResponse = {
|
||||
updated_at: Date;
|
||||
};
|
||||
|
||||
export type PackageConsultResponse = {
|
||||
session_code: string;
|
||||
};
|
||||
|
||||
export type PackageItineraryWidgetResponse =
|
||||
| {
|
||||
type: "transport";
|
||||
|
||||
Reference in New Issue
Block a user