made openCanceledSlot api

This commit is contained in:
2026-01-30 14:49:43 +05:30
parent 3adbadc3ee
commit 07f0212b62
4 changed files with 126 additions and 2 deletions

View File

@@ -507,4 +507,19 @@ cancelSlotForActivity:
events:
- httpApi:
path: /scheduling/cancel-slot
method: post
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

View File

@@ -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
}),
};

View File

@@ -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<APIGatewayProxyResult> => {
// 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
}),
};
});

View File

@@ -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
}
})
}
}