From 07f0212b62edd3a21f0a5528e3b84557d5af6942 Mon Sep 17 00:00:00 2001 From: Mayank Mishra Date: Fri, 30 Jan 2026 14:49:43 +0530 Subject: [PATCH] made openCanceledSlot api --- serverless/functions/host.yml | 17 +++- .../Activity_Hub/Scheduling/cancelSlot.ts | 2 +- .../Scheduling/openCanceledSlot.ts | 85 +++++++++++++++++++ .../services/activityScheduling.service.ts | 24 ++++++ 4 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 src/modules/host/handlers/Activity_Hub/Scheduling/openCanceledSlot.ts diff --git a/serverless/functions/host.yml b/serverless/functions/host.yml index 0be9b32..62e1482 100644 --- a/serverless/functions/host.yml +++ b/serverless/functions/host.yml @@ -507,4 +507,19 @@ cancelSlotForActivity: events: - httpApi: path: /scheduling/cancel-slot - method: post \ No newline at end of file + method: post + +openCanceledSlotForActivity: + handler: src/modules/host/handlers/Activity_Hub/Scheduling/openCanceledSlot.handler + memorySize: 512 + package: + patterns: + - 'src/modules/host/handlers/Activity_Hub/Scheduling/**' + - ${file(./serverless/patterns/base.yml):pattern1} + - ${file(./serverless/patterns/base.yml):pattern2} + - ${file(./serverless/patterns/base.yml):pattern3} + - ${file(./serverless/patterns/base.yml):pattern4} + events: + - httpApi: + path: /scheduling/open-canceled-slot + method: patch \ No newline at end of file diff --git a/src/modules/host/handlers/Activity_Hub/Scheduling/cancelSlot.ts b/src/modules/host/handlers/Activity_Hub/Scheduling/cancelSlot.ts index ff984eb..49c6e70 100644 --- a/src/modules/host/handlers/Activity_Hub/Scheduling/cancelSlot.ts +++ b/src/modules/host/handlers/Activity_Hub/Scheduling/cancelSlot.ts @@ -79,7 +79,7 @@ export const handler = safeHandler(async ( }, body: JSON.stringify({ success: true, - message: 'Scheduling details updated successfully', + message: 'Slot blocked successfully', data: result }), }; diff --git a/src/modules/host/handlers/Activity_Hub/Scheduling/openCanceledSlot.ts b/src/modules/host/handlers/Activity_Hub/Scheduling/openCanceledSlot.ts new file mode 100644 index 0000000..17a2760 --- /dev/null +++ b/src/modules/host/handlers/Activity_Hub/Scheduling/openCanceledSlot.ts @@ -0,0 +1,85 @@ +import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda'; +import { safeHandler } from '../../../../../common/utils/handlers/safeHandler'; +import { prismaClient } from '../../../../../common/database/prisma.lambda.service'; +import { SchedulingService } from '../../../services/activityScheduling.service'; +import { HostService } from '../../../services/host.service'; +import ApiError from '../../../../../common/utils/helper/ApiError'; +import { verifyHostToken } from '../../../../../common/middlewares/jwt/authForHost'; +import { scheduleActivity } from '../../../../../common/utils/validation/host/createSchedulingOfAct.validation'; +import { z } from 'zod'; + +const schedulingService = new SchedulingService(prismaClient); +const hostService = new HostService(prismaClient); + +export const handler = safeHandler(async ( + event: APIGatewayProxyEvent, + context?: Context +): Promise => { + // Extract token from headers + const token = event.headers['x-auth-token'] || event.headers['X-Auth-Token'] + if (!token) { + throw new ApiError(400, 'This is a protected route. Please provide a valid token.'); + } + + // Authenticate user using the shared authForHost function + const userInfo = await verifyHostToken(token); + const hostId = userInfo.id; + + if (Number.isNaN(hostId)) { + throw new ApiError(400, 'Host id must be a number'); + } + + const host = await hostService.getHostIdByUserXid(hostId); + if (!host) { + throw new ApiError(404, 'Host not found'); + } + + let body: { activityXid: number; venueXid: number; cancellationXid: number; slotXid: number; }; + + try { + body = event.body ? JSON.parse(event.body) : {}; + } catch { + throw new ApiError(400, 'Invalid JSON payload'); + } + if (!body.activityXid || !body.venueXid || !body.cancellationXid || !body.slotXid) { + throw new ApiError(400, 'Missing required fields'); + } + + const activity = await schedulingService.getActivityByXid(body.activityXid); + if (!activity) { + throw new ApiError(404, "Activity not found"); + } + + const venueExists = await schedulingService.getVenueFromVenueXid( + body.venueXid, + body.activityXid + ); + + if (!venueExists) { + throw new ApiError( + 404, + `Venue not found for this activity` + ) + } + + + await schedulingService.openCanceledSlot( + Number(body.cancellationXid), + Number(body.slotXid), + ); + + const result = await schedulingService.getVenueDurationByAct(Number(body.activityXid), Number(hostId)); + + return { + statusCode: 200, + headers: { + 'Content-Type': 'application/json', + 'Access-Control-Allow-Origin': '*', + }, + body: JSON.stringify({ + success: true, + message: 'Slot opened successfully', + data: result + }), + }; +}); \ No newline at end of file diff --git a/src/modules/host/services/activityScheduling.service.ts b/src/modules/host/services/activityScheduling.service.ts index 6f858b1..772d530 100644 --- a/src/modules/host/services/activityScheduling.service.ts +++ b/src/modules/host/services/activityScheduling.service.ts @@ -353,6 +353,16 @@ export class SchedulingService { activityDurationMins: true, activityTitle: true, activityRefNumber: true, + is_late_checking_allowed: true, + isInstantBooking: true, + frequenciesXid: true, + frequency: { + where: { isActive: true }, + select: { + id: true, + frequencyName: true, + } + }, ActivityVenues: { where: { isActive: true }, select: { @@ -529,4 +539,18 @@ export class SchedulingService { } }) } + + async openCanceledSlot( + cancellationXid: number, + slotXid?: number, + ) { + return await this.prisma.cancellations.update({ + where: { + id: cancellationXid, slotXid: slotXid + }, + data: { + isActive: false + } + }) + } } \ No newline at end of file