Merge branch 'mayankSprint2' of http://git.wdipl.com/Mayank.Mishra/MinglarBackendNestJS into paritosh-main1
This commit is contained in:
@@ -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
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -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
|
||||
}),
|
||||
};
|
||||
});
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user